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

122 {
123 std::string rule_name = rule.name;
124 ComputationContext rule_context = rule.context;
125
126 auto insert_pos = std::ranges::upper_bound(m_rules, rule,
127 [](const Rule& a, const Rule& b) { return a.priority > b.priority; });
128 m_rules.insert(insert_pos, std::move(rule));
129
130 m_context_index[rule_context].push_back(rule_name);
131 }
size_t a
size_t b
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 a, b, 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: