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;
177 inline std::unordered_map<std::shared_ptr<Buffer>, std::vector<std::shared_ptr<BufferProcessor>>>
get_chain()
const {
return m_buffer_processors; }
192 void merge_chain(
const std::shared_ptr<BufferProcessingChain>& other);
202 void preprocess(
const std::shared_ptr<Buffer>& buffer);
212 void postprocess(
const std::shared_ptr<Buffer>& buffer);
223 void process_final(
const std::shared_ptr<Buffer>& buffer);
245 return m_token_filter_mask;
258 m_enforcement_strategy = strategy;
271 return m_enforcement_strategy;
285 void optimize_for_tokens(
const std::shared_ptr<Buffer>& buffer);
296 std::vector<TokenCompatibilityReport> analyze_token_compatibility()
const;
306 bool validate_all_processors(std::vector<std::string>* incompatibility_reasons =
nullptr)
const;
316 void enforce_chain_token_on_processors();
320 return m_pending_count.load(std::memory_order_relaxed) > 0;
333 template <
typename T>
334 std::shared_ptr<T>
get_processor(
const std::shared_ptr<Buffer>& buffer)
const
336 auto processors = get_processors(buffer);
338 for (
auto& processor : processors) {
339 if (
auto t_processor = std::dynamic_pointer_cast<T>(processor)) {
347 bool add_processor_direct(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer, std::string* rejection_reason =
nullptr);
348 void remove_processor_direct(
const std::shared_ptr<BufferProcessor>& processor,
const std::shared_ptr<Buffer>& buffer);
360 void process_non_owning(
const std::shared_ptr<Buffer>& buffer);
365 void cleanup_rejected_processors(
const std::shared_ptr<Buffer>& buffer);
370 void process_pending_processor_operations();
372 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);
381 std::unordered_map<std::shared_ptr<Buffer>, std::vector<std::shared_ptr<BufferProcessor>>>
m_buffer_processors;
391 std::unordered_map<std::shared_ptr<Buffer>, std::unordered_set<std::shared_ptr<BufferProcessor>>>
m_pending_removal;
399 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<BufferProcessor>>
m_preprocessors;
407 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<BufferProcessor>>
m_postprocessors;
436 static constexpr size_t MAX_PENDING_PROCESSORS = 32;
439 std::atomic<bool> active {
false };
442 bool is_addition {
true };
449 std::atomic<uint32_t> m_pending_count { 0 };