66template <ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
97 template <
typename ConcreteOpType>
100 static_assert(std::is_base_of_v<ComputeOperation<InputType, OutputType>, ConcreteOpType>,
101 "Operation must derive from ComputeOperation");
126 template <
typename ConcreteOpType,
typename... Args>
129 auto operation = std::make_shared<ConcreteOpType>(std::forward<Args>(args)...);
130 return add_operation(operation, name);
157 input_type current_data = input;
160 if (
auto best_rule = m_grammar->find_best_match(current_data, current_context)) {
161 if (
auto rule_result = m_grammar->execute_rule(best_rule->name, current_data, current_context)) {
163 current_data = std::any_cast<input_type>(*rule_result);
164 }
catch (
const std::bad_any_cast&) {
170 for (
const auto& [operation, name] : m_operations) {
172 auto result = operation->apply_operation(current_data);
173 current_data = result;
174 }
catch (
const std::exception& e) {
175 throw std::runtime_error(
"Pipeline operation failed: " + name +
" - " + e.what());
179 if constexpr (std::is_same_v<InputType, OutputType>) {
194 [[nodiscard]] std::shared_ptr<ComputationGrammar>
get_grammar()
const
208 m_grammar = std::move(grammar);
229 template <
typename ConcreteOpType>
230 std::shared_ptr<ConcreteOpType>
get_operation(
const std::string& name)
const
232 for (
const auto& [operation, op_name] : m_operations) {
233 if (op_name == name) {
234 return std::dynamic_pointer_cast<ConcreteOpType>(operation);
260 template <
typename ConcreteOpType>
262 const std::function<
void(std::shared_ptr<ConcreteOpType>)>& configurator)
264 for (
auto& [operation, op_name] : m_operations) {
265 if (op_name == name) {
266 if (
auto concrete_op = std::dynamic_pointer_cast<ConcreteOpType>(operation)) {
267 configurator(concrete_op);
281 return m_operations.size();
292 m_operations.clear();
304 std::vector<std::string> names;
305 names.reserve(m_operations.size());
306 std::ranges::transform(m_operations, std::back_inserter(names),
307 [](
const auto& op_pair) {
return op_pair.second; });
321 auto it = std::ranges::find_if(m_operations,
322 [&name](
const auto& op_pair) {
return op_pair.second == name; });
324 if (it != m_operations.end()) {
325 m_operations.erase(it);
333 std::vector<std::pair<std::shared_ptr<ComputeOperation<InputType, OutputType>>, std::string>>
m_operations;
343namespace PipelineFactory {
360 template <ComputeData DataType = std::vector<Kakshya::DataVariant>>
363 auto pipeline = std::make_shared<ComputationPipeline<DataType>>();
388 template <ComputeData DataType = std::vector<Kakshya::DataVariant>>
391 auto pipeline = std::make_shared<ComputationPipeline<DataType>>();
474 template <ComputeData InputType>
479 if (
auto best_rule = m_grammar->find_best_match(input_data, context)) {
480 if (
auto rule_result = m_grammar->execute_rule(best_rule->name, input_data, context)) {
482 input_data = std::any_cast<IO<InputType>>(*rule_result);
483 }
catch (
const std::bad_any_cast&) {
513 m_grammar = std::move(grammar);
526 m_grammar->add_rule(std::move(rule));
548 return m_grammar->create_rule(name);
Fluent interface for building rules with method chaining.
Core grammar system for rule-based computation in Maya Flux.
std::shared_ptr< ConcreteOpType > get_operation(const std::string &name) const
Get operation by name.
ComputationPipeline & create_operation(const std::string &name="", Args &&... args)
Create and add operation by type.
bool remove_operation(const std::string &name)
Remove operation by name.
std::shared_ptr< ComputationGrammar > get_grammar() const
Get the grammar instance.
void clear_operations()
Clear all operations.
size_t operation_count() const
Get number of operations in pipeline.
void set_grammar(std::shared_ptr< ComputationGrammar > grammar)
Set grammar instance.
output_type process(const input_type &input, const ExecutionContext &context={})
Execute the pipeline with grammar rule application.
std::vector< std::pair< std::shared_ptr< ComputeOperation< InputType, OutputType > >, std::string > > m_operations
Operations and their names in execution order.
std::shared_ptr< ComputationGrammar > m_grammar
Grammar instance for rule-based operation selection.
ComputationPipeline(std::shared_ptr< ComputationGrammar > grammar=nullptr)
Constructor with optional grammar.
std::vector< std::string > get_operation_names() const
Get all operation names in the pipeline.
bool configure_operation(const std::string &name, const std::function< void(std::shared_ptr< ConcreteOpType >)> &configurator)
Configure operation by name.
ComputationPipeline & add_operation(std::shared_ptr< ConcreteOpType > operation, const std::string &name="")
Add a concrete operation instance to the pipeline.
Pipeline that uses grammar rules for operation composition.
Local execution orchestrator for computational operations.
Base interface for all computational operations in the processing pipeline.
std::shared_ptr< ComputationGrammar > m_grammar
Grammar instance for rule-based operation selection.
auto execute_with_grammar(const InputType &input, const ExecutionContext &context={})
Execute operations with grammar rule pre-processing.
void add_grammar_rule(ComputationGrammar::Rule rule)
Add a grammar rule directly to the matrix.
std::shared_ptr< ComputationGrammar > get_grammar() const
Get the grammar instance.
GrammarAwareComputeMatrix(std::shared_ptr< ComputationGrammar > grammar=nullptr)
Constructor with optional grammar.
void set_grammar(std::shared_ptr< ComputationGrammar > grammar)
Set grammar instance.
ComputationGrammar::RuleBuilder create_grammar_rule(const std::string &name)
Create a rule builder for this matrix's grammar.
ComputeMatrix extension that integrates grammar-based operation selection.
std::shared_ptr< ComputationPipeline< DataType > > create_audio_pipeline()
Create an audio processing pipeline.
std::shared_ptr< ComputationPipeline< DataType > > create_analysis_pipeline()
Create an analysis pipeline.
Represents a computation rule with matching and execution logic.
Context information for operation execution.
Input/Output container for computation pipeline data flow with structure preservation.