载入中...
搜索中...
未找到
eve::emergence::RuleEngine类 参考

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]

eve::emergence::RuleEngine::RuleEngine ( )
default

Rule engine.

◆ ~RuleEngine()

eve::emergence::RuleEngine::~RuleEngine ( )
default

Rule engine.

◆ RuleEngine() [2/3]

eve::emergence::RuleEngine::RuleEngine ( const RuleEngine &  )
delete

◆ RuleEngine() [3/3]

eve::emergence::RuleEngine::RuleEngine ( RuleEngine &&  )
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()

int eve::emergence::RuleEngine::activationCount ( ) const
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()

int eve::emergence::RuleEngine::dirtyCount ( ) const
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.

参数
tickInjected 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. Cascaded fact.set wakes 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()

const FactStore & eve::emergence::RuleEngine::facts ( ) const
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()

std::uint64_t eve::emergence::RuleEngine::lastDrainEvaluations ( ) const
inlinenoexcept

Diagnostic: condition evaluations performed during the last drain.

在文件 RuleEngine.h 第 149 行定义.

◆ operator=() [1/2]

RuleEngine & eve::emergence::RuleEngine::operator= ( const RuleEngine &  )
delete

◆ operator=() [2/2]

RuleEngine & eve::emergence::RuleEngine::operator= ( RuleEngine &&  )
default

Operator =.

◆ replaceCatalogue()

eve::Result< int > eve::emergence::RuleEngine::replaceCatalogue ( std::vector< RuleDefinition >  rules)

Validate and atomically replace every rule definition.

参数
rulesOwning 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)

◆ 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()

int eve::emergence::RuleEngine::ruleCount ( ) const
inlinenoexcept

Committed rule count.

在文件 RuleEngine.h 第 75 行定义.

◆ setAttribute()

eve::Result< bool > eve::emergence::RuleEngine::setAttribute ( std::string  key,
eve::Value  value 
)

◆ setAuthority()

eve::Result< bool > eve::emergence::RuleEngine::setAuthority ( std::string  scope,
bool  granted 
)

◆ 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.

参数
nameNon-empty policy id matching a policy_call condition key.
resultOwning 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 
)

◆ setState()

eve::Result< bool > eve::emergence::RuleEngine::setState ( std::string  key,
eve::Value  value 
)

◆ setTag()

eve::Result< bool > eve::emergence::RuleEngine::setTag ( std::string  tag,
bool  present 
)

◆ setValue()

eve::Result< bool > eve::emergence::RuleEngine::setValue ( std::string  key,
eve::Value  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()

std::uint64_t eve::emergence::RuleEngine::wakeKeyEvents ( ) const
inlinenoexcept

Diagnostic: distinct keys that woke at least one rule since construction/clear.

在文件 RuleEngine.h 第 151 行定义.


该类的文档由以下文件生成: