载入中...
搜索中...
未找到
Settlement.cpp
浏览该文件的文档.
43 eve::DiagnosticCode::InvalidArgument, "settlement target must be a valid SubjectRef", "target"));
46 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "settlement kind must not be empty", "kind"));
59 eve::DiagnosticCode::InvalidArgument, "settlement correlation must use a canonical id", "correlation"));
87 if (!request.trigger.empty() || request.chain.emittedCount != 0 || !request.chain.triggerPath.empty())
269bool SettlementResult::hasStage(std::string_view name) const noexcept { return stage(name) != nullptr; }
284 const auto it = std::find_if(stages.begin(), stages.end(), [&](const auto& value) { return value.name == name; });
330 eve::DiagnosticCode::InvariantViolation, "settlement mutation is empty or already rolled back", "apply"));
343 eve::DiagnosticCode::Failed, std::string("settlement apply commit threw: ") + exception.what(), "apply"));
370 recordMutationViolation("settlement magnitude cannot change after apply preparation", "magnitude");
372 eve::DiagnosticCode::Conflict, "settlement magnitude is frozen after apply preparation", "magnitude"));
385 recordMutationViolation("settlement absorbed amount cannot change after apply preparation", "absorbed");
387 eve::DiagnosticCode::Conflict, "settlement absorbed amount is frozen after apply preparation", "absorbed"));
396 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "absorbed amount overflowed", "absorbed"));
403 recordMutationViolation("settlement resisted amount cannot change after apply preparation", "resisted");
405 eve::DiagnosticCode::Conflict, "settlement resisted amount is frozen after apply preparation", "resisted"));
414 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "resisted amount overflowed", "resisted"));
421 recordMutationViolation("settlement clamped amount cannot change after apply preparation", "clamped");
423 eve::DiagnosticCode::Conflict, "settlement clamped amount is frozen after apply preparation", "clamped"));
432 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "clamped amount overflowed", "clamped"));
513 eve::DiagnosticCode::InvariantViolation, "settlement policy returned an invalid mutation", "apply"));
561 if (request.chain.depth != 0 || request.chain.emittedCount != 0 || !request.chain.triggerPath.empty())
569void SettlementContext::recordMutationViolation(std::string message, std::string path) noexcept {
582eve::Result<void> ISettlementPolicy::decide(SettlementContext&) { return eve::Result<void>::success(); }
590 auto install = [&](StageKind kind, const char* name, StageFunction function, bool terminal = false) {
592 stages_.push_back(StageEntry{kind, name, priority, nextRegistration_++, true, terminal, std::move(function)});
646 install(StageKind::Event, "event", [](SettlementContext& context) { return context.prepareEvent(); }, true);
649eve::Result<void> SettlementPipeline::addStage(StageKind kind, std::string name, int priority, StageFunction function) {
652 eve::DiagnosticCode::InvalidArgument, "settlement stage name must not be empty", "stage.name"));
655 eve::DiagnosticCode::InvalidArgument, "settlement stage function must not be empty", "stage.function"));
657 std::find_if(stages_.begin(), stages_.end(), [&](const auto& stage) { return stage.name == name; });
660 eve::DiagnosticCode::AlreadyExists, "settlement stage name is already registered", "stage.name"));
663 eve::DiagnosticCode::InvariantViolation, "settlement stage registration sequence exhausted", "stage"));
669eve::Result<void> SettlementPipeline::prepare(SettlementContext& context, SettlementResult& result) const {
739 eve::DiagnosticCode::InvariantViolation, "settlement pipeline did not prepare an apply mutation",
744eve::Result<SettlementResult> SettlementPipeline::settle(const SettlementRequest& request, ISettlementPolicy& policy,
794 eve::DiagnosticCode::Failed, "settlement result event append threw an unknown exception", "event"));
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={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.h:84
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
const std::vector< Diagnostic > & diagnostics() const noexcept
All diagnostics in stable insertion order.
Definition Status.h:124
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:67
Deterministic in-memory stream of topic-neutral event envelopes.
Definition GameEvent.h:261
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:584
virtual eve::Result< void > decide(SettlementContext &context)
Resolve deterministic hit, immunity, block or other supplied decisions.
Definition Settlement.cpp:582
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:350
bool isValid() const noexcept
Return whether both transaction callbacks are available.
Definition Settlement.cpp:322
PreparedApply()=default
Construct an empty invalid mutation.
eve::Result< void > commit()
Publish the staged candidate; failure must leave state unchanged.
Definition Settlement.cpp:326
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:383
void setStageDetail(std::string key, Value value)
Attach one serializable explanation field to the current stage.
Definition Settlement.cpp:475
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:437
eve::Result< void > setClampMax(std::optional< double > value)
Set or clear the maximum amount used by the generic clamp stage.
Definition Settlement.cpp:458
eve::Result< void > emitDerived(SettlementRequest request)
Append one owning derived request during the Trigger phase.
Definition Settlement.cpp:556
eve::Result< void > prepareEvent()
Build the canonical GameEvent without appending it.
Definition Settlement.cpp:519
eve::Result< void > addClamped(double value)
Add an amount removed by the final clamp stage; late writes are rejected.
Definition Settlement.cpp:419
void synchronizeResult() noexcept
Copy the current frame counters into SettlementResult.
Definition Settlement.cpp:535
eve::Result< void > addResisted(double value)
Add an amount removed by target mitigation; late writes are rejected.
Definition Settlement.cpp:401
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:485
eve::Result< void > setMagnitude(double value)
Set the current amount; late writes after Apply are rejected.
Definition Settlement.cpp:368
eve::Result< void > prepareApply()
Prepare the adapter mutation without publishing domain state.
Definition Settlement.cpp:500
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:649
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:744
SettlementPipeline()
Construct a pipeline with the canonical stages installed.
Definition Settlement.cpp:589
Definition Settlement.cpp:10
const char * settlementDispositionName(SettlementDisposition disposition) noexcept
Return the stable lowercase spelling of a settlement disposition.
Definition Settlement.cpp:256
@ SourceModifiers
@ TargetMitigation
@ Decision
@ Validate
@ Trigger
@ ArmorShield
const char * stageKindName(StageKind kind) noexcept
Return the stable lowercase spelling of a stage kind.
Definition Settlement.cpp:241
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:40
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:45
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:187
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:283
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:271
std::size_t ruleMatchCount() const noexcept
Count declarative rules whose filter and condition matched.
Definition Settlement.cpp:277
std::vector< SettlementStageResult > stages
Definition Settlement.h:172
std::optional< game_event::GameEvent > event
Definition Settlement.h:173
SettlementDisposition disposition
Definition Settlement.h:170
bool hasStage(std::string_view name) const noexcept
Return whether a named stage explanation exists.
Definition Settlement.cpp:269
Explanation emitted for one executed stage.
Definition Settlement.h:145