载入中...
搜索中...
未找到
ConditionCodec.cpp
浏览该文件的文档.
18bool exactFields(const eve::Value::Object& object, std::initializer_list<std::string_view> allowed) {
27eve::Result<std::string> requiredString(const eve::Value::Object& object, std::string_view name) {
32 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "condition field must be a non-empty string",
41 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "condition operator must be a string",
44 {"eq", CompareOperator::Equal}, {"ne", CompareOperator::NotEqual}, {"lt", CompareOperator::Less},
45 {"le", CompareOperator::LessEqual}, {"gt", CompareOperator::Greater}, {"ge", CompareOperator::GreaterEqual},
50 return eve::Result<CompareOperator>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
70 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "unknown condition determinism level",
91 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "condition children must be an array",
103eve::Result<Condition> decodeLegacyLeaf(std::string_view kind, const eve::Value::Object& object) {
104 if (kind == "has_tag" || kind == "has_attribute" || kind == "has_resource" || kind == "authority_check") {
106 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
113 if (kind == "has_attribute") return eve::Result<Condition>::success(attributeExists(std::move(name)));
114 if (kind == "has_resource") return eve::Result<Condition>::success(resourceExists(std::move(name)));
119 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
126 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
132 eve::DiagnosticCode::InvalidArgument, "unknown condition kind", "kind", {}, "decision.condition_codec"));
138 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
144 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
150 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
157 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
167 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
174 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
185 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
195 return eve::Result<Condition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
209 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "scriptDeclaration must be an object",
251 Condition::policyCall(std::move(key).takeValue(), std::move(arguments), std::move(declaration)));
261 eve::DiagnosticCode::InvalidArgument, "condition is invalid", {}, {}, "decision.condition_codec"));
Canonical Compare key prefixes and PolicyCall names for thin conditions.
Stable, structured diagnostics shared by engine modules.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Type kind() const noexcept
Compatibility spelling for the former dialogue data tree.
Definition Value.h:96
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
static Condition compare(std::string key, CompareOperator op, Value expected={})
Compare a context value against an expected scalar value.
Definition Condition.cpp:157
static Condition any(std::vector< Condition > children)
Construct a disjunction of child conditions.
Definition Condition.cpp:145
static Condition all(std::vector< Condition > children)
Construct a conjunction of child conditions.
Definition Condition.cpp:139
static Condition not_(Condition child)
Construct a logical negation of one child condition.
Definition Condition.cpp:151
static Condition policyCall(std::string name, Value arguments=Value::Object{}, std::optional< ScriptConditionDeclaration > scriptDeclaration=std::nullopt)
Call a named read-only policy and use its ConditionResult.
Definition Condition.cpp:165
Shared Value codec for thin condition::Condition trees.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Definition BuildingSnapshot.cpp:96
Definition Condition.cpp:7
Condition stateEquals(std::string name, Value expected)
Compare that a state key equals an expected value.
Definition ConditionKeys.h:123
Condition attributeExists(std::string name)
Compare that an attribute key exists (attr:<name> Exists).
Definition ConditionKeys.h:106
const char * conditionKindName(ConditionKind kind) noexcept
Return the stable lowercase spelling of a condition node kind. @ownership Borrowed process-static tex...
Definition Condition.cpp:107
Condition tagPresent(std::string tag)
Compare that a tag key is present (tag:<name> == true).
Definition ConditionKeys.h:98
@ PolicyCall
DeterminismLevel
Determinism contract declared by a script-backed condition policy.
Definition Condition.h:47
@ ToleranceBounded
Results may vary within a documented numeric tolerance.
@ TickDeterministic
Deterministic when evaluated at the injected simulation tick.
@ BitExact
Same inputs produce the same bits without an external clock.
@ ExplicitlyNondeterministic
Result is intentionally not suitable for replay or lockstep.
Condition resourceExists(std::string name)
Compare that a resource key exists (resource:<name> Exists).
Definition ConditionKeys.h:114
eve::Result< Condition > decodeCondition(const eve::Value &value)
Decode one condition tree from an owning Value.
Definition ConditionCodec.cpp:298
@ Exists
Passes when the keyed value is present; expected is ignored.
@ GreaterEqual
@ LessEqual
Condition authorityAllow(std::string scope)
PolicyCall for read-only authority (authority.allow).
Definition ConditionKeys.h:131
const char * compareOperatorName(CompareOperator op) noexcept
Return the stable lowercase spelling of a comparison operator. @ownership Borrowed process-static tex...
Definition Condition.cpp:118
eve::Result< eve::Value > encodeCondition(const Condition &condition)
Encode one validated condition tree as an owning Value.
Definition ConditionCodec.cpp:258
std::string requiredString(Object::Ptr object, const std::string &field)
Strict source string fields; invalid manifest shapes throw a diagnostic exception.
@ InvalidArgument