载入中...
搜索中...
未找到
Settlement.cpp
浏览该文件的文档.
44 eve::DiagnosticCode::InvalidArgument, "settlement target must be a valid SubjectRef", "target"));
47 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement kind must not be empty", "kind"));
60 eve::DiagnosticCode::InvalidArgument, "settlement correlation must use a canonical id", "correlation"));
88 if (!request.trigger.empty() || request.chain.emittedCount != 0 || !request.chain.triggerPath.empty())
276bool SettlementResult::hasStage(std::string_view name) const noexcept { return stage(name) != nullptr; }
291 const auto it = std::find_if(stages.begin(), stages.end(), [&](const auto& value) { return value.name == name; });
337 eve::DiagnosticCode::InvariantViolation, "settlement mutation is empty or already rolled back", "apply"));
350 eve::DiagnosticCode::Failed, std::string("settlement apply commit threw: ") + exception.what(), "apply"));
377 recordMutationViolation("settlement magnitude cannot change after apply preparation", "magnitude");
379 eve::DiagnosticCode::Conflict, "settlement magnitude is frozen after apply preparation", "magnitude"));
392 recordMutationViolation("settlement absorbed amount cannot change after apply preparation", "absorbed");
394 eve::DiagnosticCode::Conflict, "settlement absorbed amount is frozen after apply preparation", "absorbed"));
403 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "absorbed amount overflowed", "absorbed"));
410 recordMutationViolation("settlement resisted amount cannot change after apply preparation", "resisted");
412 eve::DiagnosticCode::Conflict, "settlement resisted amount is frozen after apply preparation", "resisted"));
421 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "resisted amount overflowed", "resisted"));
428 recordMutationViolation("settlement clamped amount cannot change after apply preparation", "clamped");
430 eve::DiagnosticCode::Conflict, "settlement clamped amount is frozen after apply preparation", "clamped"));
439 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "clamped amount overflowed", "clamped"));
520 eve::DiagnosticCode::InvariantViolation, "settlement policy returned an invalid mutation", "apply"));
568 if (request.chain.depth != 0 || request.chain.emittedCount != 0 || !request.chain.triggerPath.empty())
576void SettlementContext::recordMutationViolation(std::string message, std::string path) noexcept {
589eve::Result<void> ISettlementPolicy::decide(SettlementContext&) { return eve::Result<void>::success(); }
597 auto install = [&](StageKind kind, const char* name, StageFunction function, bool terminal = false) {
599 stages_.push_back(StageEntry{kind, name, priority, nextRegistration_++, true, terminal, std::move(function)});
653 install(StageKind::Event, "event", [](SettlementContext& context) { return context.prepareEvent(); }, true);
656eve::Result<void> SettlementPipeline::addStage(StageKind kind, std::string name, int priority, StageFunction function) {
659 eve::DiagnosticCode::InvalidArgument, "settlement stage name must not be empty", "stage.name"));
662 eve::DiagnosticCode::InvalidArgument, "settlement stage function must not be empty", "stage.function"));
664 std::find_if(stages_.begin(), stages_.end(), [&](const auto& stage) { return stage.name == name; });
667 eve::DiagnosticCode::AlreadyExists, "settlement stage name is already registered", "stage.name"));
670 eve::DiagnosticCode::InvariantViolation, "settlement stage registration sequence exhausted", "stage"));
676eve::Result<void> SettlementPipeline::prepare(SettlementContext& context, SettlementResult& result) const {
678 if (context.request().trace != SettlementTraceLevel::Off) result.stages.reserve(stages_.size());
752 eve::DiagnosticCode::InvariantViolation, "settlement pipeline did not prepare an apply mutation",
757eve::Result<SettlementResult> SettlementPipeline::settle(const SettlementRequest& request, ISettlementPolicy& policy,
807 eve::DiagnosticCode::Failed, "settlement result event append threw an unknown exception", "event"));
#define EV_PROFILE_MODULE(module, name)
Profile the enclosing scope, tagged with a module for grouping.
Definition Profile.h:158
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
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 std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:37
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
const std::vector< Diagnostic > & diagnostics() const noexcept
All diagnostics in stable insertion order.
Definition Status.h:128
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.cpp:28
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:187
Deterministic in-memory stream of topic-neutral event envelopes.
Definition GameEvent.h:262
Domain-owned policy hooks used by the common settlement pipeline.
Definition Settlement.h:497
virtual eve::Result< std::vector< SettlementRequest > > prepareTrigger(const SettlementContext &context, const SettlementResult &result)
Produce owning derived requests without mutating domain state.
Definition Settlement.cpp:591
virtual eve::Result< void > decide(SettlementContext &context)
Resolve deterministic hit, immunity, block or other supplied decisions.
Definition Settlement.cpp:589
virtual eve::Result< PreparedApply > prepareApply(const SettlementContext &context)=0
Build an atomic candidate mutation without publishing it.
Prepared domain mutation used to make settlement application atomic.
Definition Settlement.h:281
std::function< eve::Result< void >()> CommitFunction
Definition Settlement.h:283
PreparedApply & operator=(const PreparedApply &)=delete
void rollback() noexcept
Restore or discard the staged candidate; safe to call repeatedly.
Definition Settlement.cpp:357
bool isValid() const noexcept
Return whether both transaction callbacks are available.
Definition Settlement.cpp:329
PreparedApply()=default
Construct an empty invalid mutation.
eve::Result< void > commit()
Publish the staged candidate; failure must leave state unchanged.
Definition Settlement.cpp:333
std::function< void()> RollbackFunction
Definition Settlement.h:284
Mutable calculation frame visible to policy and custom stage code.
Definition Settlement.h:338
SettlementDisposition disposition() const noexcept
Return the current semantic outcome.
Definition Settlement.h:391
eve::Result< void > addAbsorbed(double value)
Add an amount absorbed by a barrier or shield; late writes are rejected.
Definition Settlement.cpp:390
void setStageDetail(std::string key, Value value)
Attach one serializable explanation field to the current stage.
Definition Settlement.cpp:482
const SettlementRequest & request() const noexcept
Return the immutable request currently being settled.
Definition Settlement.h:341
eve::Result< void > setDisposition(SettlementDisposition disposition)
Set an explicit semantic outcome during calculation.
Definition Settlement.cpp:444
eve::Result< void > setClampMax(std::optional< double > value)
Set or clear the maximum amount used by the generic clamp stage.
Definition Settlement.cpp:465
eve::Result< void > emitDerived(SettlementRequest request)
Append one owning derived request during the Trigger phase.
Definition Settlement.cpp:563
eve::Result< void > prepareEvent()
Build the canonical GameEvent without appending it.
Definition Settlement.cpp:526
eve::Result< void > addClamped(double value)
Add an amount removed by the final clamp stage; late writes are rejected.
Definition Settlement.cpp:426
void synchronizeResult() noexcept
Copy the current frame counters into SettlementResult.
Definition Settlement.cpp:542
eve::Result< void > addResisted(double value)
Add an amount removed by target mitigation; late writes are rejected.
Definition Settlement.cpp:408
ISettlementPolicy & policy() const noexcept
Return the policy participating in this synchronous call.
Definition Settlement.h:344
eve::Result< void > applyClamp()
Apply the adapter-configured max bound and record any clamp loss.
Definition Settlement.cpp:492
eve::Result< void > setMagnitude(double value)
Set the current amount; late writes after Apply are rejected.
Definition Settlement.cpp:375
eve::Result< void > prepareApply()
Prepare the adapter mutation without publishing domain state.
Definition Settlement.cpp:507
std::function< eve::Result< void >(SettlementContext &)> StageFunction
Definition Settlement.h:544
eve::Result< void > addStage(StageKind kind, std::string name, int priority, StageFunction function)
Add one named custom stage; duplicate names are rejected.
Definition Settlement.cpp:656
eve::Result< SettlementResult > settle(const SettlementRequest &request, ISettlementPolicy &policy, game_event::GameEventLog *events=nullptr) const
Execute one settlement transaction against a domain policy.
Definition Settlement.cpp:757
SettlementPipeline()
Construct a pipeline with the canonical stages installed.
Definition Settlement.cpp:596
Definition Settlement.cpp:11
const char * settlementDispositionName(SettlementDisposition disposition) noexcept
Return the stable lowercase spelling of a settlement disposition.
Definition Settlement.cpp:263
@ SourceModifiers
@ TargetMitigation
@ Decision
@ Validate
@ Trigger
@ ArmorShield
const char * stageKindName(StageKind kind) noexcept
Return the stable lowercase spelling of a stage kind.
Definition Settlement.cpp:248
SettlementTraceLevel
Amount of stage explanation retained by one settlement request.
Definition Settlement.h:60
eve::Result< void > validateSettlementRequest(const SettlementRequest &request)
Validate the canonical semantic invariants of a settlement request.
Definition Settlement.cpp:41
SettlementDisposition
Semantic outcome of a completed settlement, distinct from its numeric amount.
Definition Settlement.h:49
@ PartiallyApplied
@ InvalidTarget
std::vector< DiagnosticDetail > DiagnosticDetails
Owning collection of diagnostic details with stable insertion order.
Definition Diagnostic.h:88
@ InvalidArgument
@ CallbackFailure
@ AlreadyExists
@ InvariantViolation
@ Failed
@ Conflict
@ NoOp
@ Applied
detail::StrongUint64< detail::SchemaVersionTag > SchemaVersion
Persistent data-format version; not a runtime replacement generation.
Definition SchemaVersion.h:13
constexpr std::string_view statusCodeName(StatusCode code) noexcept
Return the stable protocol spelling of a status code.
Definition Status.h:46
Definition Container.h:602
Domain-neutral, deterministic settlement pipeline.
EventSequence sequence
Sequence assigned by the owning stream; it is never global identity.
Definition GameEvent.h:188
std::uint32_t emittedCount
Definition Settlement.h:84
std::vector< std::string > triggerPath
Definition Settlement.h:85
Domain-neutral input to one settlement operation.
Definition Settlement.h:107
std::string trigger
Stable re-entry key for a derived request; empty only for a root request.
Definition Settlement.h:119
Complete observable outcome of one successful settlement.
Definition Settlement.h:163
const SettlementStageResult * stage(std::string_view name) const noexcept
Return the first stage explanation with this name, or null.
Definition Settlement.cpp:290
std::vector< SettlementRequest > derived
Owning derived requests emitted by the policy in deterministic order.
Definition Settlement.h:175
std::size_t ruleEvaluationCount() const noexcept
Count declarative rules evaluated in this retained trace.
Definition Settlement.cpp:278
std::size_t ruleMatchCount() const noexcept
Count declarative rules whose filter and condition matched.
Definition Settlement.cpp:284
std::vector< SettlementStageResult > stages
Definition Settlement.h:172
SettlementDisposition disposition
Definition Settlement.h:170
bool hasStage(std::string_view name) const noexcept
Return whether a named stage explanation exists.
Definition Settlement.cpp:276
Explanation emitted for one executed stage.
Definition Settlement.h:145