MayaFlux 0.1.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 165 of file ComputeGrammar.hpp.

168 {
169 auto it = std::ranges::find_if(m_rules,
170 [&rule_name](const Rule& rule) { return rule.name == rule_name; });
171
172 if (it != m_rules.end() && it->matcher(input, context)) {
173 return it->executor(input, context);
174 }
175 return std::nullopt;
176 }
std::vector< Rule > m_rules
All rules sorted by priority (highest first)

References MayaFlux::Yantra::ComputationGrammar::Rule::name.