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

◆ add_rule()

void MayaFlux::Yantra::ComputationGrammar::add_rule ( Rule  rule)
inline

Add a rule to the grammar.

Parameters
ruleRule to add to the grammar system

Rules are automatically sorted by priority (highest first) and indexed by context for efficient lookup. The rule's name must be unique within the grammar.

Note
Rules with higher priority values are evaluated first during matching

Definition at line 116 of file ComputeGrammar.hpp.

117 {
118 std::string rule_name = rule.name;
119 ComputationContext rule_context = rule.context;
120
121 auto insert_pos = std::ranges::upper_bound(m_rules, rule,
122 [](const Rule& a, const Rule& b) { return a.priority > b.priority; });
123 m_rules.insert(insert_pos, std::move(rule));
124
125 m_context_index[rule_context].push_back(rule_name);
126 }
std::unordered_map< ComputationContext, std::vector< std::string > > m_context_index
Index of rule names by context for fast lookup.
std::vector< Rule > m_rules
All rules sorted by priority (highest first)
ComputationContext
Defines the computational contexts in which rules can be applied.

References MayaFlux::Yantra::ComputationGrammar::Rule::context, MayaFlux::Yantra::ComputationGrammar::Rule::name, and MayaFlux::Yantra::ComputationGrammar::Rule::priority.

Referenced by MayaFlux::Yantra::ComputationGrammar::RuleBuilder::build().

+ Here is the caller graph for this function: