载入中...
搜索中...
未找到
FactStore.cpp
浏览该文件的文档.
29bool exactFields(const eve::Value::Object& object, std::initializer_list<std::string_view> allowed) {
63 eve::DiagnosticCode::InvalidArgument, "unknown condition reason code", "reason", {}, "emergence.fact"));
70 eve::DiagnosticCode::InvalidArgument, "policy result must be an object", {}, {}, "emergence.fact"));
73 eve::DiagnosticCode::InvalidArgument, "policy result contains an unknown field", {}, {}, "emergence.fact"));
78 eve::DiagnosticCode::InvalidArgument, "policy passed must be a boolean", "passed", {}, "emergence.fact"));
81 eve::DiagnosticCode::InvalidArgument, "policy reason must be a string", "reason", {}, "emergence.fact"));
116 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, message, "key", {}, "emergence.fact"));
141 return eve::Result<std::pair<FactDomain, std::string>>::success(std::make_pair(domain, std::string(name)));
248std::optional<decision::ConditionResult> FactStore::policy(std::string_view name, const eve::Value&) const {
288 eve::DiagnosticCode::InvalidArgument, "fact snapshot must be an object", {}, {}, "emergence.fact"));
289 if (!exactFields(*object, {"schema", "version", "values", "tags", "attributes", "resources", "states",
292 eve::DiagnosticCode::InvalidArgument, "fact snapshot contains an unknown field", {}, {}, "emergence.fact"));
297 eve::DiagnosticCode::InvalidArgument, "unexpected fact snapshot schema", "schema", {}, "emergence.fact"));
300 eve::DiagnosticCode::UnknownVersion, "unsupported fact snapshot version", "version", {}, "emergence.fact"));
309 eve::DiagnosticCode::InvalidArgument, "fact field must be an object", fieldName, {}, "emergence.fact"));
Stable, structured diagnostics shared by engine modules.
Authoritative, rule-visible world facts implementing EvaluationContext.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:67
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
Explain one condition evaluation in a UI- and log-friendly form.
Definition Condition.h:129
ConditionReasonCode reasonCode() const noexcept
Stable machine-readable reason code.
Definition Condition.h:139
static ConditionResult failed(ConditionReasonCode reason, Value evidence={}, Value details=Value::Object{})
Construct a rejected result with a stable reason and explanation.
Definition Condition.cpp:137
static ConditionResult success(Value evidence={}, Value details=Value::Object{})
Construct a passed result with optional evidence and details.
Definition Condition.cpp:133
const Value & evidence() const noexcept
Observed value or child evidence owned by this result.
Definition Condition.h:141
Mutable fact bag that doubles as a read-only Condition evaluation context.
Definition FactStore.h:60
std::string snapshotJson() const
Export deterministic compact JSON for runtime snapshots.
Definition FactStore.cpp:253
FactChange setPolicy(std::string name, decision::ConditionResult result)
Register or replace a read-only policy result.
Definition FactStore.cpp:196
eve::Result< void > restoreJson(std::string_view json)
Transactionally restore facts from a snapshot produced by snapshotJson().
Definition FactStore.cpp:282
FactChange setValue(std::string key, eve::Value value)
Set a compare/value fact.
Definition FactStore.cpp:166
FactChange setTag(std::string tag, bool present)
Set tag membership; present=true means the tag exists.
Definition FactStore.cpp:171
std::optional< eve::Value > attribute(std::string_view key) const override
Query an attribute value; nullopt means the attribute is absent.
Definition FactStore.cpp:228
std::optional< bool > authority(std::string_view scope) const override
Query authority without changing grants, leases, or state.
Definition FactStore.cpp:243
FactChange setState(std::string key, eve::Value value)
Set a state value.
Definition FactStore.cpp:186
FactChange setAttribute(std::string key, eve::Value value)
Set an attribute value.
Definition FactStore.cpp:176
std::optional< bool > hasTag(std::string_view tag) const override
Query tag membership; nullopt means the tag source is unavailable.
Definition FactStore.cpp:223
std::optional< decision::ConditionResult > policy(std::string_view name, const eve::Value &arguments) const override
Evaluate a named read-only policy with owned arguments.
Definition FactStore.cpp:248
std::optional< eve::Value > resource(std::string_view key) const override
Query a resource amount or resource marker.
Definition FactStore.cpp:233
FactChange setAuthority(std::string scope, bool granted)
Set authority for a scope.
Definition FactStore.cpp:191
std::optional< eve::Value > state(std::string_view key) const override
Query a state value for StateEquals nodes.
Definition FactStore.cpp:238
FactChange setResource(std::string key, eve::Value value)
Set a resource value.
Definition FactStore.cpp:181
std::optional< eve::Value > value(std::string_view key) const override
Query a named scalar or structured value for Compare nodes.
Definition FactStore.cpp:218
const char * conditionReasonCodeName(ConditionReasonCode code) noexcept
Return the stable lowercase spelling of a condition reason code. @ownership Borrowed process-static t...
Definition Condition.cpp:82
ConditionReasonCode
Stable machine-readable explanation code for a condition outcome.
Definition Condition.h:74
Definition ConditionCodec.cpp:10
@ Unchanged
@ Changed
@ Authority
@ Resource
@ Attribute
eve::Result< std::pair< FactDomain, std::string > > parseFactKey(std::string_view key)
Parse a canonical watch key into domain and leaf name.
Definition FactStore.cpp:113
std::string makeFactKey(FactDomain domain, std::string_view name)
Build the canonical watch key for one fact domain.
Definition FactStore.cpp:106
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
@ InvalidArgument
@ UnknownVersion
@ Applied