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

◆ execute_rule()

std::optional< std::any > MayaFlux::Yantra::ComputationGrammar::execute_rule ( const std::string &  rule_name,
const std::any &  input,
const ExecutionContext context 
) const
inline

Execute a specific rule by name.

Parameters
rule_nameName of the rule to execute
inputInput data for the rule's executor
contextExecution context containing parameters and metadata
Returns
Result of rule execution, or nullopt if rule not found or doesn't match

Finds the named rule and executes it if its matcher function returns true for the given input and context. This allows for explicit rule invocation when the specific rule to apply is known.

Note
The rule's matcher is still evaluated even when invoked by name, ensuring that rules maintain their matching contracts

Definition at line 173 of file ComputeGrammar.hpp.

176 {
177 auto it = std::ranges::find_if(m_rules,
178 [&rule_name](const Rule& rule) { return rule.name == rule_name; });
179
180 if (it != m_rules.end() && it->matcher(input, context)) {
181 return it->executor(input, context);
182 }
183 return std::nullopt;
184 }
Core::GlobalInputConfig input
Definition Config.cpp:38
std::vector< Rule > m_rules
All rules sorted by priority (highest first)

References input, and MayaFlux::Yantra::ComputationGrammar::Rule::name.