载入中...
搜索中...
未找到
RuntimeRegistry.h
浏览该文件的文档.
96 [[nodiscard]] constexpr bool isValid() const noexcept { return handle.isValid() && ownerEpoch != 0; }
99 friend constexpr bool operator==(const RuntimeHandleRef&, const RuntimeHandleRef&) noexcept = default;
137 explicit RuntimeSlotStore(OwnedInstanceDestroy destroy) noexcept : destroy_(destroy), ownerEpoch_(nextEpoch()) {}
242 [[nodiscard]] std::optional<std::uint32_t> findSlot(std::uint32_t index, std::uint32_t generation,
244 [[nodiscard]] static bool coordinatesValid(std::uint32_t index, std::uint32_t generation) noexcept;
246 [[nodiscard]] static std::optional<std::uint32_t> nextGeneration(std::uint32_t current) noexcept;
320 [[nodiscard]] Borrowed<T> borrow() const noexcept { return Borrowed<T>(get(), reference_.ownerEpoch); }
365 RuntimeObjectRegistry() : store_(std::make_unique<detail::RuntimeSlotStore>(&detail::ownedInstanceDestroy<T>)) {}
393 return eve::Result<Ref>::success(Ref{Handle(coordinates.index, coordinates.generation), store_->ownerEpoch()});
442 return eve::Result<RuntimePin<T, Tag>>::success(RuntimePin<T, Tag>(store_.get(), ref, object.value()));
Move-only, checked operation results for the common layer.
Strong generation-qualified handles for non-ECS runtime registries.
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
Process-local slot identity tagged by the registry that owns it.
Definition RuntimeHandle.h:116
static constexpr RuntimeHandle invalid() noexcept
Returns the canonical invalid handle.
Definition RuntimeHandle.h:143
Non-owning C++ observation with no implicit lifetime extension.
Definition RuntimeRegistry.h:42
constexpr T * operator->() const noexcept
Pointer-like access to the borrowed object.
Definition RuntimeRegistry.h:71
constexpr std::uint64_t ownerEpoch() const noexcept
Returns the epoch of the owner that produced this observation.
Definition RuntimeRegistry.h:69
constexpr bool isBound() const noexcept
Returns whether the observation currently names an object.
Definition RuntimeRegistry.h:67
constexpr T * get() const noexcept
Returns the observed pointer, or nullptr when unbound.
Definition RuntimeRegistry.h:65
constexpr Borrowed(T &value, std::uint64_t ownerEpoch=0) noexcept
Constructs a Borrowed.
Definition RuntimeRegistry.h:51
constexpr T & operator*() const noexcept
Dereferences the borrowed object; the caller owns validity proof.
Definition RuntimeRegistry.h:73
Slot/generation registry whose objects are exclusively unique-owned.
Definition RuntimeRegistry.h:359
eve::Result< void > erase(Ref ref)
Destroys the object identified by a live handle.
Definition RuntimeRegistry.h:426
bool isStale(Ref ref) const noexcept
Reports whether a non-invalid handle can no longer resolve.
Definition RuntimeRegistry.h:446
std::uint64_t ownerEpoch() const noexcept
Returns the non-reusable lifetime epoch of this registry.
Definition RuntimeRegistry.h:484
void clear()
Invalidates all slots and releases every unique-owned object.
Definition RuntimeRegistry.h:481
void forEachLive(F &&visit)
Visit every live object with its slot index, in slot order.
Definition RuntimeRegistry.h:465
Borrowed< T > resolve(Ref ref) noexcept
Resolves a live object as a non-owning observation.
Definition RuntimeRegistry.h:407
Borrowed< const T > resolve(Ref ref) const noexcept
Const overload of resolve(); see the non-const form for its contract.
Definition RuntimeRegistry.h:414
eve::Result< RuntimePin< T, Tag > > pin(Ref ref)
Keeps one entry alive until the returned pin is released.
Definition RuntimeRegistry.h:439
RuntimeObjectRegistry(const RuntimeObjectRegistry &)=delete
eve::Result< Ref > emplace(Owned< T > object)
Transfers one unique-owned object into a fresh registry slot.
Definition RuntimeRegistry.h:381
void forEachLive(F &&visit) const
Read-only overload: the callback receives const T&.
Definition RuntimeRegistry.h:473
RuntimeObjectRegistry()
Creates an empty registry with a unique owner-lifetime epoch.
Definition RuntimeRegistry.h:365
RuntimeObjectRegistry(RuntimeObjectRegistry &&) noexcept=default
Constructs a RuntimeObjectRegistry.
RuntimeObjectRegistry & operator=(const RuntimeObjectRegistry &)=delete
RuntimeHandle< Tag > Handle
Definition RuntimeRegistry.h:361
RAII keep-alive for one RuntimeObjectRegistry entry.
Definition RuntimeRegistry.h:276
Borrowed< T > borrow() const noexcept
Borrows the pinned object together with its owner epoch.
Definition RuntimeRegistry.h:320
~RuntimePin()
Releases the keep-alive; an erased object is destroyed here.
Definition RuntimeRegistry.h:308
RuntimePin & operator=(RuntimePin &&other) noexcept
Move-assigns, releasing any keep-alive this pin already held.
Definition RuntimeRegistry.h:294
T * get() const noexcept
Borrows the pinned object; valid until the pin is released.
Definition RuntimeRegistry.h:317
T * operator->() const noexcept
Pointer-like access to the pinned object.
Definition RuntimeRegistry.h:323
RuntimePin(RuntimePin &&other) noexcept
Moves the keep-alive to a new pin; the source becomes unbound.
Definition RuntimeRegistry.h:286
RuntimePin(const RuntimePin &)=delete
RuntimePin & operator=(const RuntimePin &)=delete
bool isBound() const noexcept
Whether this pin still keeps an object alive.
Definition RuntimeRegistry.h:311
const Ref & reference() const noexcept
The reference this pin was created from.
Definition RuntimeRegistry.h:314
Tag-free slot store behind every RuntimeObjectRegistry<T, Tag>.
Definition RuntimeRegistry.h:134
RuntimeSlotStore & operator=(RuntimeSlotStore &&)=delete
Result< void > erase(std::uint32_t index, std::uint32_t generation, std::uint64_t ownerEpoch)
Destroys the object in a live slot, then advances or retires it.
Definition RuntimeRegistry.cpp:150
void forEachLive(F &&visit)
Visits every live slot with its index, in slot order.
Definition RuntimeRegistry.h:207
void * resolve(std::uint32_t index, std::uint32_t generation, std::uint64_t ownerEpoch) const noexcept
Borrows the live object for these coordinates, or null when stale.
Definition RuntimeRegistry.cpp:108
RuntimeSlotStore(RuntimeSlotStore &&)=delete
bool isStale(std::uint32_t index, std::uint32_t generation, std::uint64_t ownerEpoch) const noexcept
Whether a non-invalid handle can no longer resolve.
Definition RuntimeRegistry.cpp:190
RuntimeSlotStore & operator=(const RuntimeSlotStore &)=delete
Result< void * > pin(std::uint32_t index, std::uint32_t generation, std::uint64_t ownerEpoch)
Keeps one live slot's object alive across erase() and clear().
Definition RuntimeRegistry.cpp:116
Result< RuntimeSlotCoordinates > emplace(void *object)
Stores one object in a fresh or recycled slot.
Definition RuntimeRegistry.cpp:74
void forEachLive(F &&visit) const
Read-only overload: the callback receives const void*.
Definition RuntimeRegistry.h:219
std::uint64_t ownerEpoch() const noexcept
Returns the non-reusable lifetime epoch of this store.
Definition RuntimeRegistry.h:229
void unpin(std::uint32_t index, std::uint64_t ownerEpoch) noexcept
Releases one pin, destroying the object when it was the last one on an erased slot.
Definition RuntimeRegistry.cpp:132
void clear()
Destroys every live object and invalidates every prior handle.
Definition RuntimeRegistry.cpp:199
RuntimeSlotStore(OwnedInstanceDestroy destroy) noexcept
Constructs an empty store that owns no slot.
Definition RuntimeRegistry.h:137
RuntimeSlotStore(const RuntimeSlotStore &)=delete
void(*)(void *) noexcept OwnedInstanceDestroy
Destroys one owned C++ wrapper without knowing its type.
Definition RuntimeRegistry.h:105
void ownedInstanceDestroy(void *pointer) noexcept
Type-erased cleanup used when the VM never took the object.
Definition RuntimeRegistry.h:110
Definition BindingContracts.h:5
std::unique_ptr< T > Owned
C++ owning storage used by an object factory.
Definition RuntimeRegistry.h:33
@ InvalidArgument
Definition Container.h:602
Handle plus owner-lifetime epoch for a non-ECS registry object.
Definition RuntimeRegistry.h:91
friend constexpr bool operator==(const RuntimeHandleRef &, const RuntimeHandleRef &) noexcept=default
constexpr bool isValid() const noexcept
Returns whether both the handle and its registry epoch are set.
Definition RuntimeRegistry.h:96
constexpr std::uint64_t packed() const noexcept
Returns the packed slot/generation projection.
Definition RuntimeRegistry.h:98
Slot coordinates without the domain tag.
Definition RuntimeRegistry.h:115
std::uint32_t generation
Definition RuntimeRegistry.h:117
std::uint32_t index
Definition RuntimeRegistry.h:116