MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
DataProcessingChain.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "DataProcessor.hpp"
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @class DataProcessingChain
9 * @brief Manages collection of data processors or flexible, composable pipelines.
10 *
11 * DataProcessingChain orchestrates collections of DataProcessor objects, enabling the construction
12 * of modular, extensible, and container-specific processing pipelines. Unlike traditional analog
13 * "signal chains," this class is designed for digital-first workflows, supporting dynamic, data-driven
14 * processing scenarios unconstrained by fixed or linear analog metaphors.
15 *
16 * Key features:
17 * - **Container-specific chains:** Each SignalSourceContainer can have its own unique sequence of processors,
18 * supporting heterogeneous and context-aware processing across the system.
19 * - **Dynamic composition:** Processors can be added, removed, or reordered at runtime, enabling adaptive
20 * workflows and on-the-fly reconfiguration.
21 * - **Type-based and tag-based filtering:** Processors can be grouped and selectively applied based on type
22 * or user-defined tags, supporting advanced routing, conditional processing, and logical grouping.
23 * - **Custom filtering:** Arbitrary filter functions allow for runtime selection of processors based on
24 * data characteristics, state, or external criteria.
25 * - **Composable with digital-first nodes, routines, and buffer systems:** Designed to integrate seamlessly
26 * with the broader Maya Flux ecosystem, enabling robust, data-driven orchestration of complex workflows.
27 *
28 * This abstraction enables advanced scenarios such as:
29 * - Multi-stage, container-specific data transformation pipelines
30 * - Selective or conditional processing based on data type, tag, or runtime state
31 * - Integration of analysis, transformation, and feature extraction in a unified pipeline
32 * - Dynamic adaptation to changing data, user interaction, or system state
33 *
34 * DataProcessingChain is foundational for building scalable, maintainable, and future-proof
35 * data processing architectures in digital-first, data-driven applications.
36 */
37class MAYAFLUX_API DataProcessingChain {
38public:
40
41 /**
42 * @brief Adds a processor to the chain for a specific container.
43 * @param processor The data processor to add
44 * @param container The signal container the processor will operate on
45 * @param tag Optional tag for categorizing processors (enables logical grouping and selective execution)
46 *
47 * Processors are appended to the end of the container's processing sequence by default.
48 */
49 void add_processor(std::shared_ptr<DataProcessor> processor, std::shared_ptr<SignalSourceContainer> container, const std::string& tag = "");
50
51 /**
52 * @brief Adds a processor at a specific position in the chain.
53 * @param processor The data processor to add
54 * @param container The signal container the processor will operate on
55 * @param position The position in the processing sequence (0-based index)
56 *
57 * Enables precise control over processing order for advanced workflows.
58 */
59 void add_processor_at(std::shared_ptr<DataProcessor> processor,
60 std::shared_ptr<SignalSourceContainer> container,
61 size_t position);
62
63 /**
64 * @brief Removes a processor from a container's chain.
65 * @param processor The data processor to remove
66 * @param container The signal container to remove the processor from
67 *
68 * Supports dynamic reconfiguration and resource management.
69 */
70 void remove_processor(std::shared_ptr<DataProcessor> processor, std::shared_ptr<SignalSourceContainer> container);
71
72 /**
73 * @brief Processes a container with all its associated processors, in sequence.
74 * @param container The signal container to process
75 *
76 * Applies each processor in the container's chain, enabling multi-stage transformation,
77 * analysis, or feature extraction.
78 */
79 void process(std::shared_ptr<SignalSourceContainer> container);
80
81 /**
82 * @brief Processes a container with processors of a specific type.
83 * @tparam ProcessorType The type of processors to apply
84 * @param container The signal container to process
85 *
86 * Enables selective processing based on processor type, supporting specialized
87 * data transformations or analysis paths.
88 */
89 template <typename ProcessorType>
90 inline void process_typed(std::shared_ptr<SignalSourceContainer> container)
91 {
92 auto it = m_container_processors.find(container);
93 if (it != m_container_processors.end()) {
94 for (auto& processor : it->second) {
95 if (auto typed_proc = std::dynamic_pointer_cast<ProcessorType>(processor)) {
96 typed_proc->process(container);
97 }
98 }
99 }
100 }
101
102 /**
103 * @brief Processes a container with processors that match a filter function.
104 * @param container The signal container to process
105 * @param filter Function that determines which processors to apply
106 *
107 * Enables dynamic, runtime filtering of processors based on arbitrary criteria,
108 * such as processor state, metadata, or external conditions.
109 */
110 void process_filtered(std::shared_ptr<SignalSourceContainer> container,
111 std::function<bool(std::shared_ptr<DataProcessor>)> filter);
112
113 /**
114 * @brief Processes a container with processors that have a specific tag.
115 * @param container The signal container to process
116 * @param tag The tag to filter processors by
117 *
118 * Allows for logical grouping and selective application of processors, supporting
119 * scenarios like feature extraction, effect routing, or conditional processing.
120 */
121 void process_tagged(std::shared_ptr<SignalSourceContainer> container, const std::string& tag);
122
123private:
124 /**
125 * @brief Maps containers to their associated processors in sequence order.
126 *
127 * Enables each container to maintain its own independent, ordered processing pipeline.
128 */
129 std::unordered_map<std::shared_ptr<SignalSourceContainer>,
130 std::vector<std::shared_ptr<DataProcessor>>>
132
133 /**
134 * @brief Maps processors to their associated tags for categorization and filtering.
135 */
136 std::unordered_map<std::shared_ptr<DataProcessor>, std::string> m_processor_tags;
137};
138
139}
void process_typed(std::shared_ptr< SignalSourceContainer > container)
Processes a container with processors of a specific type.
std::unordered_map< std::shared_ptr< DataProcessor >, std::string > m_processor_tags
Maps processors to their associated tags for categorization and filtering.
std::unordered_map< std::shared_ptr< SignalSourceContainer >, std::vector< std::shared_ptr< DataProcessor > > > m_container_processors
Maps containers to their associated processors in sequence order.
Manages collection of data processors or flexible, composable pipelines.
void add_processor(const std::shared_ptr< Buffers::BufferProcessor > &processor, const std::shared_ptr< Buffers::Buffer > &buffer, Buffers::ProcessingToken token)
Adds a processor to a specific buffer.
Definition Graph.cpp:86