Indexed, deferred rule evaluator for tens of thousands of conditions. 更多...
#include <RuleEngine.h>
Public 成员函数 | |
| RuleEngine ()=default | |
| Rule engine. | |
| ~RuleEngine ()=default | |
| Rule engine. | |
| RuleEngine (const RuleEngine &)=delete | |
| RuleEngine & | operator= (const RuleEngine &)=delete |
| RuleEngine (RuleEngine &&)=default | |
| Rule engine. | |
| RuleEngine & | operator= (RuleEngine &&)=default |
| Operator =. | |
| eve::Result< int > | replaceCatalogue (std::vector< RuleDefinition > rules) |
| Validate and atomically replace every rule definition. | |
| eve::Result< int > | replaceCatalogueJson (std::string_view json) |
| Replace the catalogue from a versioned JSON document. | |
| void | clear () |
| Remove every rule, fact, and queued activation. | |
| int | ruleCount () const noexcept |
| Committed rule count. | |
| bool | contains (std::string_view ruleId) const |
| Whether a stable rule id exists. | |
| const RuleDefinition * | find (std::string_view ruleId) const |
| Borrow one committed definition. @ownership Borrowed from this engine; callers must not delete it. @lifetime Invalidated by clear() or a successful catalogue replacement. @nullable Null when the id is absent. @thread Owning simulation thread only. | |
| const FactStore & | facts () const noexcept |
| Borrow the authoritative fact store for read-only inspection. @ownership Borrowed; this engine remains the owner. @lifetime Valid until the engine is destroyed. @thread Owning simulation thread only. | |
| eve::Result< bool > | setValue (std::string key, eve::Value value) |
| Set a value fact and wake watchers when it changes. | |
| eve::Result< bool > | setTag (std::string tag, bool present) |
| Set a tag fact and wake watchers when it changes. | |
| eve::Result< bool > | setAttribute (std::string key, eve::Value value) |
| Set an attribute fact and wake watchers when it changes. | |
| eve::Result< bool > | setResource (std::string key, eve::Value value) |
| Set a resource fact and wake watchers when it changes. | |
| eve::Result< bool > | setState (std::string key, eve::Value value) |
| Set a state fact and wake watchers when it changes. | |
| eve::Result< bool > | setAuthority (std::string scope, bool granted) |
| Set an authority fact and wake watchers when it changes. | |
| eve::Result< bool > | setPolicy (std::string name, decision::ConditionResult result) |
Cache a policy evaluation result and wake policy:<name> watchers when it changes. | |
| eve::Result< int > | drain (std::uint64_t tick) |
| Evaluate dirty rules and resolve activations for one simulation tick. | |
| int | activationCount () const noexcept |
| Activations retained from the most recent drain batches since clearActivations. | |
| const Activation * | activationAt (int index) const |
| Borrow one retained activation. @ownership Borrowed from this engine; callers must not delete it. @lifetime Invalidated by clear, clearActivations, or catalogue replacement. @nullable Null when index is out of range. @thread Owning simulation thread only. | |
| void | clearActivations () |
| Drop retained activations without touching facts or rules. | |
| eve::Result< void > | resetRule (std::string_view ruleId) |
| Re-enable a once-fired rule and clear its edge latch. | |
| int | dirtyCount () const noexcept |
| Diagnostic: rules marked dirty since the last successful drain start. | |
| std::uint64_t | lastDrainEvaluations () const noexcept |
| Diagnostic: condition evaluations performed during the last drain. | |
| std::uint64_t | wakeKeyEvents () const noexcept |
| Diagnostic: distinct keys that woke at least one rule since construction/clear. | |
| std::string | snapshotJson () const |
| Export runtime state (facts + rule latches) as deterministic JSON. | |
| eve::Result< void > | restoreJson (std::string_view json) |
| Transactionally restore runtime state; catalogue must already match rule ids. | |
详细描述
Indexed, deferred rule evaluator for tens of thousands of conditions.
Fact mutations only wake rules that watch the changed key. Activations are queued and resolved by drain, never inline during mutation. Built-in fact.set plus economy credit/debit actions execute during drain; other kinds go to IEmergenceActionHandler listeners and remain visible in the activation log for scripts.
@ownership Caller-owned when constructed directly; module-owned when created through Emergence::newEngine(). @thread Owning simulation thread only. @reentrancy drain must not be called reentrantly on the same engine.
在文件 RuleEngine.h 第 43 行定义.
构造及析构函数说明
◆ RuleEngine() [1/3]
|
default |
Rule engine.
◆ ~RuleEngine()
|
default |
Rule engine.
◆ RuleEngine() [2/3]
|
delete |
◆ RuleEngine() [3/3]
|
default |
Rule engine.
成员函数说明
◆ activationAt()
| const Activation * eve::emergence::RuleEngine::activationAt | ( | int | index | ) | const |
Borrow one retained activation. @ownership Borrowed from this engine; callers must not delete it. @lifetime Invalidated by clear, clearActivations, or catalogue replacement. @nullable Null when index is out of range. @thread Owning simulation thread only.
在文件 RuleEngine.cpp 第 521 行定义.
引用了 index.
◆ activationCount()
|
inlinenoexcept |
Activations retained from the most recent drain batches since clearActivations.
在文件 RuleEngine.h 第 128 行定义.
◆ clear()
| void eve::emergence::RuleEngine::clear | ( | ) |
Remove every rule, fact, and queued activation.
在文件 RuleEngine.cpp 第 242 行定义.
◆ clearActivations()
| void eve::emergence::RuleEngine::clearActivations | ( | ) |
Drop retained activations without touching facts or rules.
在文件 RuleEngine.cpp 第 526 行定义.
◆ contains()
| bool eve::emergence::RuleEngine::contains | ( | std::string_view | ruleId | ) | const |
Whether a stable rule id exists.
在文件 RuleEngine.cpp 第 255 行定义.
◆ dirtyCount()
|
inlinenoexcept |
Diagnostic: rules marked dirty since the last successful drain start.
在文件 RuleEngine.h 第 147 行定义.
◆ drain()
| eve::Result< int > eve::emergence::RuleEngine::drain | ( | std::uint64_t | tick | ) |
Evaluate dirty rules and resolve activations for one simulation tick.
- 参数
-
tick Injected simulation tick used for cooldown and activation metadata.
- 返回
- Number of activations produced this call (also retained until clearActivations).
- 备注
- Nested drain on the same engine returns PreconditionViolation.
-
Within each dirty pass, activations run in
(priority DESC, ruleId ASC)order. Cascadedfact.setwakes are evaluated in later passes of the same drain. Rising/once/cooldown latches commit only after that activation's actions succeed.
在文件 RuleEngine.cpp 第 432 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), index, eve::InvariantViolation, left, eve::NoOp, pending, eve::PreconditionViolation, right, eve::Status::success(), eve::Result< T >::success() , 以及 tick.
◆ facts()
|
inlinenoexcept |
Borrow the authoritative fact store for read-only inspection. @ownership Borrowed; this engine remains the owner. @lifetime Valid until the engine is destroyed. @thread Owning simulation thread only.
- 备注
- Mutations must go through the mediated
set*APIs so watchers wake.
在文件 RuleEngine.h 第 94 行定义.
◆ find()
| const RuleDefinition * eve::emergence::RuleEngine::find | ( | std::string_view | ruleId | ) | const |
Borrow one committed definition. @ownership Borrowed from this engine; callers must not delete it. @lifetime Invalidated by clear() or a successful catalogue replacement. @nullable Null when the id is absent. @thread Owning simulation thread only.
在文件 RuleEngine.cpp 第 257 行定义.
◆ lastDrainEvaluations()
|
inlinenoexcept |
Diagnostic: condition evaluations performed during the last drain.
在文件 RuleEngine.h 第 149 行定义.
◆ operator=() [1/2]
|
delete |
◆ operator=() [2/2]
|
default |
Operator =.
◆ replaceCatalogue()
| eve::Result< int > eve::emergence::RuleEngine::replaceCatalogue | ( | std::vector< RuleDefinition > | rules | ) |
Validate and atomically replace every rule definition.
- 参数
-
rules Owning definitions; watch keys are derived when omitted.
- 返回
- Committed rule count, or structured failure preserving the prior catalogue.
在文件 RuleEngine.cpp 第 95 行定义.
引用了 eve::AlreadyExists, eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), ids, index, eve::PreconditionViolation, eve::Status::success(), eve::Result< T >::success() , 以及 value.
◆ replaceCatalogueJson()
| eve::Result< int > eve::emergence::RuleEngine::replaceCatalogueJson | ( | std::string_view | json | ) |
Replace the catalogue from a versioned JSON document.
- 参数
-
json UTF-8 eve.emergence.rulesversion 1 document.
- 返回
- Committed rule count, or structured failure preserving the prior catalogue.
在文件 RuleEngine.cpp 第 125 行定义.
引用了 action, actions, eve::emergence::RuleDefinition::actions, condition, eve::emergence::RuleDefinition::condition, eve::emergence::RuleDefinition::cooldownTicks, eve::emergence::decodeCondition(), eve::Diagnostic::error(), eve::Result< T >::failure(), eve::emergence::RuleDefinition::fireMode, eve::Value::fromJson(), id, eve::emergence::RuleDefinition::id, eve::InvalidArgument, kind, eve::emergence::RuleDefinition::once, priority, eve::emergence::RuleDefinition::priority, root, eve::UnknownVersion , 以及 eve::emergence::RuleDefinition::watchKeys.
◆ resetRule()
| eve::Result< void > eve::emergence::RuleEngine::resetRule | ( | std::string_view | ruleId | ) |
Re-enable a once-fired rule and clear its edge latch.
- 返回
- Applied when the rule exists, NotFound otherwise.
在文件 RuleEngine.cpp 第 528 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::NotFound, eve::Status::success() , 以及 eve::Result< T >::success().
◆ restoreJson()
| eve::Result< void > eve::emergence::RuleEngine::restoreJson | ( | std::string_view | json | ) |
Transactionally restore runtime state; catalogue must already match rule ids.
- 返回
- Success, or structured failure leaving the engine unchanged.
在文件 RuleEngine.cpp 第 562 行定义.
引用了 eve::AlreadyExists, eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::Value::fromJson(), id, eve::InvalidArgument, eve::NotFound, eve::emergence::FactStore::restoreJson(), root, eve::Status::success(), eve::Result< T >::success() , 以及 eve::UnknownVersion.
◆ ruleCount()
|
inlinenoexcept |
Committed rule count.
在文件 RuleEngine.h 第 75 行定义.
◆ setAttribute()
| eve::Result< bool > eve::emergence::RuleEngine::setAttribute | ( | std::string | key, |
| eve::Value | value | ||
| ) |
Set an attribute fact and wake watchers when it changes.
在文件 RuleEngine.cpp 第 288 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, key, eve::emergence::makeFactKey(), eve::NoOp, eve::Status::success(), eve::Result< T >::success() , 以及 value.
◆ setAuthority()
| eve::Result< bool > eve::emergence::RuleEngine::setAuthority | ( | std::string | scope, |
| bool | granted | ||
| ) |
Set an authority fact and wake watchers when it changes.
在文件 RuleEngine.cpp 第 315 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, eve::emergence::makeFactKey(), eve::NoOp, scope, eve::Status::success() , 以及 eve::Result< T >::success().
◆ setPolicy()
| eve::Result< bool > eve::emergence::RuleEngine::setPolicy | ( | std::string | name, |
| decision::ConditionResult | result | ||
| ) |
Cache a policy evaluation result and wake policy:<name> watchers when it changes.
- 参数
-
name Non-empty policy id matching a policy_callcondition key.result Owning ConditionResult snapshot.
在文件 RuleEngine.cpp 第 325 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, eve::emergence::makeFactKey(), name, eve::NoOp, eve::Status::success() , 以及 eve::Result< T >::success().
◆ setResource()
| eve::Result< bool > eve::emergence::RuleEngine::setResource | ( | std::string | key, |
| eve::Value | value | ||
| ) |
Set a resource fact and wake watchers when it changes.
在文件 RuleEngine.cpp 第 297 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, key, eve::emergence::makeFactKey(), eve::NoOp, eve::Status::success(), eve::Result< T >::success() , 以及 value.
◆ setState()
| eve::Result< bool > eve::emergence::RuleEngine::setState | ( | std::string | key, |
| eve::Value | value | ||
| ) |
Set a state fact and wake watchers when it changes.
在文件 RuleEngine.cpp 第 306 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, key, eve::emergence::makeFactKey(), eve::NoOp, eve::Status::success(), eve::Result< T >::success() , 以及 value.
◆ setTag()
| eve::Result< bool > eve::emergence::RuleEngine::setTag | ( | std::string | tag, |
| bool | present | ||
| ) |
Set a tag fact and wake watchers when it changes.
在文件 RuleEngine.cpp 第 279 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, eve::emergence::makeFactKey(), eve::NoOp, eve::Status::success(), eve::Result< T >::success() , 以及 tag.
◆ setValue()
| eve::Result< bool > eve::emergence::RuleEngine::setValue | ( | std::string | key, |
| eve::Value | value | ||
| ) |
Set a value fact and wake watchers when it changes.
在文件 RuleEngine.cpp 第 270 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, key, eve::emergence::makeFactKey(), eve::NoOp, eve::Status::success(), eve::Result< T >::success() , 以及 value.
◆ snapshotJson()
| std::string eve::emergence::RuleEngine::snapshotJson | ( | ) | const |
Export runtime state (facts + rule latches) as deterministic JSON.
在文件 RuleEngine.cpp 第 541 行定义.
引用了 eve::Value::fromJson(), root , 以及 eve::Value::toJson().
◆ wakeKeyEvents()
|
inlinenoexcept |
Diagnostic: distinct keys that woke at least one rule since construction/clear.
在文件 RuleEngine.h 第 151 行定义.
该类的文档由以下文件生成:
- src/modules/emergence/RuleEngine.h
- src/modules/emergence/RuleEngine.cpp