MayaFlux 0.4.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 170 of file ComputeGrammar.hpp.

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

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