MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ add_operation_rule()

template<typename ConcreteOpType , typename... OpArgs>
void MayaFlux::Yantra::ComputationGrammar::add_operation_rule ( const std::string &  rule_name,
ComputationContext  context,
UniversalMatcher::MatcherFunc  matcher,
const std::unordered_map< std::string, std::any > &  op_parameters = {},
int  priority = 50,
OpArgs &&...  op_args 
)
inline

Helper to add concrete operation rules with automatic executor generation.

Template Parameters
ConcreteOpTypeThe concrete operation type to instantiate
OpArgsConstructor argument types for the operation
Parameters
rule_nameUnique name for this rule
contextComputation context for the rule
matcherMatcher function to determine when rule applies
op_parametersParameters to configure the operation instance
priorityExecution priority (default: 50)
op_argsConstructor arguments for the operation

Creates a rule that automatically instantiates and configures a concrete operation type when matched. This is the preferred way to integrate existing operations into the grammar system, as it handles type safety and parameter application automatically.

The generated executor:

  1. Creates an instance of ConcreteOpType with the provided constructor arguments
  2. Applies the op_parameters using set_parameter()
  3. Applies additional parameters from the execution context
  4. Executes the operation on the input data

Example:

grammar.add_operation_rule<SpectralTransformer<>>(
"pitch_shift_rule",
UniversalMatcher::create_type_matcher<std::vector<Kakshya::DataVariant>>(),
{{"operation", std::string("pitch_shift")}, {"pitch_ratio", 1.5}},
80 // priority
);
Concrete transformer for frequency-domain operations.
@ SPECTRAL
Frequency-domain operations.

Definition at line 256 of file ComputeGrammar.hpp.

259 {},
260 int priority = 50,
261 OpArgs&&... op_args)
262 {
263 Rule rule;
264 rule.name = rule_name;
265 rule.context = context;
266 rule.priority = priority;
267 rule.matcher = std::move(matcher);
268 rule.target_operation_type = std::type_index(typeid(ConcreteOpType));
269
270 // Capture op_args by perfect forwarding into a tuple
271 auto captured_args = std::make_tuple(std::forward<OpArgs>(op_args)...);
272
273 rule.executor = [op_parameters, captured_args = std::move(captured_args)](const std::any& input, const ExecutionContext& ctx) -> std::any {
274 auto operation = std::apply([&op_parameters](auto&&... args) {
275 return create_configured_operation<ConcreteOpType>(op_parameters, std::forward<decltype(args)>(args)...);
276 },
277 captured_args);
278
279 apply_context_parameters(operation, ctx);
280
281 auto typed_input = std::any_cast<IO<std::vector<Kakshya::DataVariant>>>(input);
282 return operation->apply_operation(typed_input);
283 };
284
285 add_rule(std::move(rule));
286 }
void add_rule(Rule rule)
Add a rule to the grammar.
void apply_context_parameters(std::shared_ptr< OperationType > operation, const ExecutionContext &ctx)
Applies context parameters to an operation.