载入中...
搜索中...
未找到
DefinitionRuntime.h
浏览该文件的文档.
99 eve::DiagnosticCode::InvalidArgument, "runtime instance identity must not be nil", "instanceId", {},
105 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "runtime definition reference is invalid",
180 std::function<eve::Result<void*>(const void*, const InstanceIdentity&, const DefinitionHandle&)>;
188 RuntimeInstanceCore(InstanceIdentity identity, void* state, CloneFunction clone, AssignFunction assign,
229 [[nodiscard]] eve::Result<ReloadOutcome> reload(const DefinitionHandle& next, ReloadPolicy policy,
239 [[nodiscard]] eve::Result<void> restoreExact(const InstanceIdentity& identity, void* state, bool active);
293 static_assert(std::is_copy_constructible_v<State>, "RuntimeInstance state must be copy constructible");
297 std::function<eve::Result<State>(const State&, const InstanceIdentity&, const DefinitionHandle&)>;
302 : core_(std::move(identity), new State(std::move(state)), &cloneRuntimeState<State>, &assignRuntimeState<State>,
325 auto identity = InstanceIdentity::create(instanceId, std::move(definition), definitionGeneration);
336 [[nodiscard]] const State& state() const noexcept { return *static_cast<const State*>(core_.state()); }
362 [[nodiscard]] eve::Result<ReloadOutcome> reload(const DefinitionHandle& next, ReloadPolicy policy,
390 [[nodiscard]] eve::Result<void> restoreExact(const InstanceIdentity& identity, State state, bool active) {
Runtime replacement generation for stale-handle rejection.
Strong asset, definition, object and generic resource references.
Move-only, checked operation results for the common layer.
const LogicalId & id() const noexcept
Return the stable logical definition identity.
Definition ResourceRef.h:97
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
bool isValid() const noexcept
Returns whether this value contains a valid namespace and name.
Definition Identity.h:433
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Type-erased bookkeeping shared by every RuntimeInstance<State>.
Definition DefinitionRuntime.h:166
std::function< eve::Result< void * >(const void *, const InstanceIdentity &, const DefinitionHandle &)> RebuildFunction
Type-erased rebuild policy callback.
Definition DefinitionRuntime.h:180
void(*)(void *destination, const void *source) AssignFunction
Assigns one payload from another payload of the same state type.
Definition DefinitionRuntime.h:171
eve::Result< ReloadOutcome > reload(const DefinitionHandle &next, ReloadPolicy policy, const void *defaults, const RebuildFunction &rebuild)
Apply a definition replacement with an atomic payload policy.
Definition DefinitionRuntime.cpp:125
void setActive(bool active) noexcept
Set active state; this does not reload or rebuild the instance.
Definition DefinitionRuntime.h:211
eve::Result< void > checkDefinition(const DefinitionHandle &handle) const
Verify that a caller's definition handle is the exact current incarnation.
Definition DefinitionRuntime.cpp:114
void * state() noexcept
Borrow the payload; null only after a move.
Definition DefinitionRuntime.h:205
eve::Result< void > restoreExact(const InstanceIdentity &identity, void *state, bool active)
Swap in an already validated payload of this exact instance.
Definition DefinitionRuntime.cpp:192
const void * state() const noexcept
Borrow the payload; null only after a move.
Definition DefinitionRuntime.h:207
void(*)(void *) noexcept DestroyFunction
Destroys one payload; must not throw.
Definition DefinitionRuntime.h:173
const InstanceIdentity & identity() const noexcept
Borrow the complete immutable identity.
Definition DefinitionRuntime.h:203
bool isActive() const noexcept
Whether the instance participates in active simulation.
Definition DefinitionRuntime.h:209
void *(*)(const void *) CloneFunction
Deep-copies one payload for the copy constructor and copy assignment.
Definition DefinitionRuntime.h:169
Owns one strongly typed runtime state and its definition identity.
Definition DefinitionRuntime.h:292
eve::Result< ReloadOutcome > reload(const DefinitionHandle &next, ReloadPolicy policy, const State &defaults, RebuildFunction rebuild={})
Apply a definition replacement with an atomic typed-state policy.
Definition DefinitionRuntime.h:362
bool isActive() const noexcept
Whether the instance participates in active simulation.
Definition DefinitionRuntime.h:340
std::function< eve::Result< State >(const State &, const InstanceIdentity &, const DefinitionHandle &)> RebuildFunction
Definition DefinitionRuntime.h:297
const State & state() const noexcept
Borrow the current typed state.
Definition DefinitionRuntime.h:336
State & state() noexcept
Mutate typed state on the owning domain thread.
Definition DefinitionRuntime.h:338
eve::Result< void > restoreExact(const InstanceIdentity &identity, State state, bool active)
Restore an already validated snapshot of this exact instance.
Definition DefinitionRuntime.h:390
const InstanceIdentity & identity() const noexcept
Borrow the complete immutable identity.
Definition DefinitionRuntime.h:334
static eve::Result< RuntimeInstance > create(eve::PersistentId instanceId, eve::DefinitionRef definition, eve::Generation definitionGeneration, State state, bool active=true)
Construct a runtime instance after validating its identity.
Definition DefinitionRuntime.h:321
void setActive(bool active) noexcept
Set active state; this does not reload or rebuild the instance.
Definition DefinitionRuntime.h:342
eve::Result< void > checkDefinition(const DefinitionHandle &handle) const
Verify that a caller's definition handle is the exact current incarnation.
Definition DefinitionRuntime.h:348
RuntimeInstance(RuntimeInstance &&) noexcept=default
Move a typed runtime instance.
RuntimeInstance(const RuntimeInstance &)=default
Copy a typed runtime instance.
RuntimeInstance & operator=(const RuntimeInstance &)=default
Copy-assign a typed runtime instance.
constexpr bool isNil() const noexcept
Returns whether this value is the all-zero nil ID.
Definition Identity.h:176
constexpr bool isZero() const noexcept
Returns whether this value is zero.
Definition StrongUint64.h:28
Definition DefinitionRuntime.cpp:6
void destroyRuntimeState(void *state) noexcept
Payload destruction for one state type.
Definition DefinitionRuntime.h:268
@ RejectWhileActive
Reject the reload while the instance is active; inactive instances keep values.
@ ReapplyDefaults
Replace the typed state with defaults produced from the new definition.
@ RebuildInstance
Let the consumer atomically construct a new state from the new definition.
@ KeepInstanceValues
Replace the definition generation and preserve all instance values.
void * cloneRuntimeState(const void *state)
Payload operations for one state type; used by RuntimeInstance<State>.
Definition DefinitionRuntime.h:253
ReloadDisposition
Observable result of a successful or no-op definition reload.
Definition DefinitionRuntime.h:132
@ DefaultsReapplied
void assignRuntimeState(void *destination, const void *source)
Payload assignment for one state type.
Definition DefinitionRuntime.h:261
const char * reloadPolicyName(ReloadPolicy policy) noexcept
Stable spelling for a runtime definition reload policy.
Definition DefinitionRuntime.h:51
@ InvalidArgument
Definition Container.h:602
A generation-qualified reference to one definition incarnation.
Definition DefinitionRuntime.h:69
bool isValid() const noexcept
Whether both the logical reference and generation are valid.
Definition DefinitionRuntime.h:74
friend bool operator==(const DefinitionHandle &, const DefinitionHandle &) noexcept=default
eve::DefinitionRef reference
Definition DefinitionRuntime.h:70
eve::Generation generation
Definition DefinitionRuntime.h:71
Canonical identity carried by every typed runtime instance.
Definition DefinitionRuntime.h:87
eve::DefinitionRef definition
Definition DefinitionRuntime.h:89
eve::PersistentId instanceId
Definition DefinitionRuntime.h:88
bool isValid() const noexcept
Whether this identity has all required non-zero fields.
Definition DefinitionRuntime.h:123
DefinitionHandle definitionHandle() const noexcept
Convert the logical reference and generation into a checked handle.
Definition DefinitionRuntime.h:118
friend bool operator==(const InstanceIdentity &, const InstanceIdentity &) noexcept=default
Operator ==.
static eve::Result< InstanceIdentity > create(eve::PersistentId instanceId, eve::DefinitionRef definition, eve::Generation definitionGeneration)
Construct and validate one complete instance identity.
Definition DefinitionRuntime.h:93
eve::Generation definitionGeneration
Definition DefinitionRuntime.h:90
Identity transition emitted by a typed runtime reload operation.
Definition DefinitionRuntime.h:140
eve::Generation newGeneration
Definition DefinitionRuntime.h:144
eve::Generation oldGeneration
Definition DefinitionRuntime.h:143
bool changed() const noexcept
Whether the reload changed the definition generation.
Definition DefinitionRuntime.h:149
eve::PersistentId instanceId
Definition DefinitionRuntime.h:141
ReloadDisposition disposition
Definition DefinitionRuntime.h:146
eve::DefinitionRef definition
Definition DefinitionRuntime.h:142