65 bool add_processor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer, std::string* rejection_reason =
nullptr);
79 void remove_processor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer);
96 void process(
const std::shared_ptr<Buffer>& buffer);
107 void process_complete(
const std::shared_ptr<Buffer>& buffer);
122 void add_preprocessor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer);
134 void add_postprocessor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer);
146 void add_final_processor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer);
156 bool has_processors(
const std::shared_ptr<Buffer>& buffer)
const;
167 const std::vector<std::shared_ptr<BufferProcessor>>& get_processors(
const std::shared_ptr<Buffer>& buffer)
const;
173 [[nodiscard]] std::shared_ptr<BufferProcessor>
174 get_preprocessor(
const std::shared_ptr<Buffer>& buffer)
const;
180 [[nodiscard]] std::shared_ptr<BufferProcessor>
181 get_postprocessor(
const std::shared_ptr<Buffer>& buffer)
const;
187 [[nodiscard]] std::shared_ptr<BufferProcessor>
188 get_final_processor(
const std::shared_ptr<Buffer>& buffer)
const;
198 inline std::unordered_map<std::shared_ptr<Buffer>, std::vector<std::shared_ptr<BufferProcessor>>>
get_chain()
const {
return m_buffer_processors; }
213 void merge_chain(
const std::shared_ptr<BufferProcessingChain>& other);
223 void preprocess(
const std::shared_ptr<Buffer>& buffer);
233 void postprocess(
const std::shared_ptr<Buffer>& buffer);
244 void process_final(
const std::shared_ptr<Buffer>& buffer);
266 return m_token_filter_mask;
279 m_enforcement_strategy = strategy;
292 return m_enforcement_strategy;
306 void optimize_for_tokens(
const std::shared_ptr<Buffer>& buffer);
317 std::vector<TokenCompatibilityReport> analyze_token_compatibility()
const;
327 bool validate_all_processors(std::vector<std::string>* incompatibility_reasons =
nullptr)
const;
337 void enforce_chain_token_on_processors();
341 return m_pending_count.load(std::memory_order_relaxed) > 0;
354 template <
typename T>
355 std::shared_ptr<T>
get_processor(
const std::shared_ptr<Buffer>& buffer)
const
357 auto processors = get_processors(buffer);
359 for (
auto& processor : processors) {
360 if (
auto t_processor = std::dynamic_pointer_cast<T>(processor)) {
368 bool add_processor_direct(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer, std::string* rejection_reason =
nullptr);
369 void remove_processor_direct(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer);
381 void process_non_owning(
const std::shared_ptr<Buffer>& buffer);
386 void cleanup_rejected_processors(
const std::shared_ptr<Buffer>& buffer);
391 void process_pending_processor_operations();
393 bool queue_pending_processor_op(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer,
bool is_addition, std::string* rejection_reason =
nullptr);
402 std::unordered_map<std::shared_ptr<Buffer>, std::vector<std::shared_ptr<BufferProcessor>>>
m_buffer_processors;
412 std::unordered_map<std::shared_ptr<Buffer>, std::unordered_set<std::shared_ptr<BufferProcessor>>>
m_pending_removal;
420 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<BufferProcessor>>
m_preprocessors;
428 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<BufferProcessor>>
m_postprocessors;
457 static constexpr size_t MAX_PENDING_PROCESSORS = 32;
460 std::atomic<bool> active {
false };
463 bool is_addition {
true };
470 std::atomic<uint32_t> m_pending_count { 0 };