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);
88 void remove_processor_anywhere(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>&
buffer);
105 void process(
const std::shared_ptr<Buffer>&
buffer);
116 void process_complete(
const std::shared_ptr<Buffer>&
buffer);
131 void add_preprocessor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>&
buffer);
143 void add_postprocessor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>&
buffer);
155 void add_final_processor(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>&
buffer);
165 bool has_processors(
const std::shared_ptr<Buffer>&
buffer)
const;
176 const std::vector<std::shared_ptr<BufferProcessor>>& get_processors(
const std::shared_ptr<Buffer>&
buffer)
const;
182 [[nodiscard]] std::shared_ptr<BufferProcessor>
183 get_preprocessor(
const std::shared_ptr<Buffer>&
buffer)
const;
189 [[nodiscard]] std::shared_ptr<BufferProcessor>
190 get_postprocessor(
const std::shared_ptr<Buffer>&
buffer)
const;
196 [[nodiscard]] std::shared_ptr<BufferProcessor>
197 get_final_processor(
const std::shared_ptr<Buffer>&
buffer)
const;
207 inline std::unordered_map<std::shared_ptr<Buffer>, std::vector<std::shared_ptr<BufferProcessor>>>
get_chain()
const {
return m_buffer_processors; }
222 void merge_chain(
const std::shared_ptr<BufferProcessingChain>& other);
232 void preprocess(
const std::shared_ptr<Buffer>&
buffer);
242 void postprocess(
const std::shared_ptr<Buffer>&
buffer);
253 void process_final(
const std::shared_ptr<Buffer>&
buffer);
275 return m_token_filter_mask;
288 m_enforcement_strategy = strategy;
301 return m_enforcement_strategy;
315 void optimize_for_tokens(
const std::shared_ptr<Buffer>&
buffer);
326 std::vector<TokenCompatibilityReport> analyze_token_compatibility()
const;
336 bool validate_all_processors(std::vector<std::string>* incompatibility_reasons =
nullptr)
const;
346 void enforce_chain_token_on_processors();
350 return m_pending_count.load(std::memory_order_relaxed) > 0;
363 template <
typename T>
366 auto processors = get_processors(
buffer);
368 for (
auto& processor : processors) {
369 if (
auto t_processor = std::dynamic_pointer_cast<T>(processor)) {
377 bool add_processor_direct(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>&
buffer, std::string* rejection_reason =
nullptr);
378 void remove_processor_direct(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>&
buffer);
379 void remove_processor_anywhere_direct(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>&
buffer);
382 void remove_processor_internal(
383 const std::shared_ptr<BufferProcessor>& processor,
384 const std::shared_ptr<Buffer>&
buffer,
385 bool search_all_slots);
396 void process_non_owning(
const std::shared_ptr<Buffer>&
buffer);
401 void cleanup_rejected_processors(
const std::shared_ptr<Buffer>&
buffer);
406 void process_pending_processor_operations();
408 bool queue_pending_processor_op(
409 const std::shared_ptr<BufferProcessor>& processor,
410 const std::shared_ptr<Buffer>&
buffer,
412 bool search_all_slots =
false,
413 std::string* rejection_reason =
nullptr);
422 std::unordered_map<std::shared_ptr<Buffer>, std::vector<std::shared_ptr<BufferProcessor>>>
m_buffer_processors;
432 std::unordered_map<std::shared_ptr<Buffer>, std::unordered_set<std::shared_ptr<BufferProcessor>>>
m_pending_removal;
440 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<BufferProcessor>>
m_preprocessors;
448 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<BufferProcessor>>
m_postprocessors;
477 static constexpr size_t MAX_PENDING_PROCESSORS = 32;
480 std::atomic<bool> active {
false };
483 bool is_addition {
true };
484 bool search_all_slots {
false };
491 std::atomic<uint32_t> m_pending_count { 0 };