载入中...
搜索中...
未找到
VersionedRegistry.h
浏览该文件的文档.
45[[nodiscard]] EVENGINE_API eve::Result<void> validateRegistryNextSequence(EventSequence nextEventSequence);
48[[nodiscard]] EVENGINE_API eve::Result<Generation> nextRegistryGeneration(Generation current, bool present);
51[[nodiscard]] EVENGINE_API eve::Result<EventSequence> nextRegistryEventSequence(EventSequence current);
62 [[nodiscard]] eve::Result<void> accept(EventSequence sequence, Generation generation, bool remove, bool tombstone);
132template <class Key, class Value, class EventData = std::monostate, class Compare = std::less<Key>>
136 static_assert(std::is_copy_constructible_v<Value>, "VersionedRegistry values must be copyable");
137 static_assert(std::is_copy_constructible_v<EventData>, "VersionedRegistry event data must be copyable");
219 [[nodiscard]] Result<Handle> insert(Key key, Value value, EventData data = {}, std::string label = {}) {
221 return mutate(RegistryOperation::Insert, std::move(key), std::optional<Value>(std::move(value)),
240 [[nodiscard]] Result<Handle> replace(Key key, Value value, EventData data = {}, std::string label = {}) {
242 return mutate(RegistryOperation::Replace, std::move(key), std::optional<Value>(std::move(value)),
262 return mutate(RegistryOperation::Remove, std::move(key), std::nullopt, std::move(data), std::move(label));
305 return Result<Handle>::failure(Diagnostic::error(DiagnosticCode::NotFound, "registry key is not live"));
461 [[nodiscard("retain Subscription or explicitly dispose it")]] Subscription subscribe(ChangeCallback callback) {
470 [[nodiscard]] Result<Handle> mutate(RegistryOperation operation, Key key, std::optional<Value> value,
484 return Result<Handle>::failure(Diagnostic::error(DiagnosticCode::NotFound, "registry key is not live"));
486 return Result<Handle>::failure(Diagnostic::error(DiagnosticCode::NotFound, "registry key is not live"));
493 detail::nextRegistryGeneration(current ? current->generation : Generation{}, current != nullptr);
Vocabulary aliases for nullable and checked borrowed references.
Stream-local event ordering value.
Runtime replacement generation for stale-handle rejection.
Persistent data-contract version identity.
static Diagnostic warning(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct a warning diagnostic.
Definition Diagnostic.h:134
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
Move-only RAII token that owns one observer registration.
Definition Subscription.h:27
A registry whose live values are qualified by a monotonically increasing runtime generation.
Definition VersionedRegistry.h:134
const Key * keyAt(std::size_t index) const noexcept
Returns the key for a live enumeration index, or nullptr.
Definition VersionedRegistry.h:385
ResultRef< const Value > resolve(const Key &key) const
Resolves a live key to a borrowed value.
Definition VersionedRegistry.h:277
std::size_t size() const noexcept
Number of live values, excluding tombstones.
Definition VersionedRegistry.h:341
bool isTombstone(const Key &key) const noexcept
Returns whether a key is retained as a removal tombstone.
Definition VersionedRegistry.h:328
VersionedRegistry & operator=(VersionedRegistry &&)=delete
bool isStale(const Handle &handle) const noexcept
Returns true when a handle cannot resolve to its exact live incarnation.
Definition VersionedRegistry.h:334
Result< Handle > replace(Key key, Value value, EventData data={}, std::string label={})
Replaces an existing live value and invalidates its old handle.
Definition VersionedRegistry.h:240
VersionedRegistry(const VersionedRegistry &)=delete
void clearEvents() noexcept
Clears retained events without changing entries or sequence monotonicity.
Definition VersionedRegistry.h:410
Result< Handle > handle(const Key &key) const
Returns the current live handle for a key.
Definition VersionedRegistry.h:302
Result< void > restoreState(State candidate)
Transactionally replaces all registry state from an owning image.
Definition VersionedRegistry.h:423
const Value * at(std::size_t index) const noexcept
Returns a live value by deterministic key order.
Definition VersionedRegistry.h:368
Subscription subscribe(ChangeCallback callback)
Subscribes to successful insert, replace and remove events.
Definition VersionedRegistry.h:461
Result< Generation > generationOf(const Key &key) const
Returns the latest generation for a live key or tombstone.
Definition VersionedRegistry.h:313
bool contains(const Key &key) const noexcept
Returns whether a key currently has a live value.
Definition VersionedRegistry.h:322
VersionedRegistry & operator=(const VersionedRegistry &)=delete
~VersionedRegistry()=default
VersionedRegistry(VersionedRegistry &&)=delete
Result< Handle > insert(Key key, Value value, EventData data={}, std::string label={})
Inserts a new live value, or revives a tombstoned key.
Definition VersionedRegistry.h:219
Result< Handle > remove(Key key, EventData data={}, std::string label={})
Removes a live value while retaining its generation tombstone.
Definition VersionedRegistry.h:260
std::function< void(const Event &)> ChangeCallback
Definition VersionedRegistry.h:194
std::size_t tombstoneCount() const noexcept
Number of retained tombstone slots.
Definition VersionedRegistry.h:349
const Event * eventAt(std::size_t index) const noexcept
Returns a retained event by insertion sequence order, or nullptr.
Definition VersionedRegistry.h:402
State snapshotState() const
Takes an owning copy of live entries, tombstones and event history.
Definition VersionedRegistry.h:413
VersionedRegistry(GenerationProjector generationProjector={})
Constructs an empty registry.
Definition VersionedRegistry.h:202
std::size_t eventCount() const noexcept
Number of retained mutation events.
Definition VersionedRegistry.h:407
ResultRef< const Value > resolve(const Handle &handle) const
Resolves a generation-qualified handle.
Definition VersionedRegistry.h:290
std::function< void(Value &, Generation)> GenerationProjector
Callback used to keep a legacy value field as a read-only projection of generation.
Definition VersionedRegistry.h:193
Incremental validator for the retained event log of a registry image.
Definition VersionedRegistry.h:59
eve::Result< void > accept(EventSequence sequence, Generation generation, bool remove, bool tombstone)
Accept one event header; the first failure describes the whole log.
Definition VersionedRegistry.cpp:32
eve::Result< void > finish(EventSequence nextEventSequence) const
Validate the boundary between the retained log and the next sequence.
Definition VersionedRegistry.cpp:43
constexpr bool isZero() const noexcept
Returns whether this value is zero.
Definition StrongUint64.h:28
eve::Result< EventSequence > nextRegistryEventSequence(EventSequence current)
Next event sequence, or a Failed diagnostic when it is exhausted.
Definition VersionedRegistry.cpp:24
eve::Result< void > validateRegistryNextSequence(EventSequence nextEventSequence)
Validates the next-event-sequence floor of a restored registry image.
Definition VersionedRegistry.cpp:10
eve::Result< Generation > nextRegistryGeneration(Generation current, bool present)
Next generation of one slot; present false means the slot is new.
Definition VersionedRegistry.cpp:15
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
@ NotFound
@ CallbackFailure
@ AlreadyExists
@ InvariantViolation
@ Failed
@ ParseError
@ StaleHandle
std::ostream & operator<<(std::ostream &stream, Severity severity)
Writes a severity for diagnostics and test output.
Definition Diagnostic.h:39
detail::StrongUint64< detail::GenerationTag > Generation
Registry/object replacement generation used to reject stale handles.
Definition Generation.h:13
@ Applied
RegistryOperation
Canonical mutation kind emitted by a VersionedRegistry.
Definition VersionedRegistry.h:75
@ Replace
@ Remove
@ Insert
const char * registryOperationName(RegistryOperation operation) noexcept
Stable lowercase name for a registry mutation kind.
Definition VersionedRegistry.h:90
detail::StrongUint64< detail::EventSequenceTag > EventSequence
Stream-local event ordering value; it is not a global event identity.
Definition EventSequence.h:13
Definition Container.h:602
One stored key slot; absent value means the slot is a tombstone.
Definition VersionedRegistry.h:164
One canonical mutation event retained by the registry.
Definition VersionedRegistry.h:150
RegistryOperation operation
Definition VersionedRegistry.h:152
bool isTombstone() const noexcept
Whether this event advanced a key to a removed tombstone.
Definition VersionedRegistry.h:160
Generation-qualified identity of one live incarnation or tombstone.
Definition VersionedRegistry.h:141
bool isValid() const noexcept
Returns false for the zero-generation sentinel.
Definition VersionedRegistry.h:146
Owning state image used for transactional snapshot/restore.
Definition VersionedRegistry.h:175
EventSequence nextEventSequence
Definition VersionedRegistry.h:178
std::map< Key, Entry, Compare > entries
Definition VersionedRegistry.h:176
void swap(State &other) noexcept
Atomically exchanges complete registry state without allocation.
Definition VersionedRegistry.h:181