载入中...
搜索中...
未找到
RuntimeBorrow.h
浏览该文件的文档.
1#pragma once
2
13
14#include <cstdint>
15
16namespace eve::script {
17
26template <class T>
27class Borrowed {
28public:
30 constexpr Borrowed() noexcept = default;
32 explicit constexpr Borrowed(T* value, std::uint64_t ownerEpoch = 0) noexcept
33 : value_(value), ownerEpoch_(ownerEpoch) {}
35 explicit constexpr Borrowed(T& value, std::uint64_t ownerEpoch = 0) noexcept
36 : value_(&value), ownerEpoch_(ownerEpoch) {}
37
48 [[nodiscard]] constexpr T* get() const noexcept { return value_; }
50 [[nodiscard]] constexpr bool isBound() const noexcept { return value_ != nullptr; }
52 [[nodiscard]] constexpr std::uint64_t ownerEpoch() const noexcept { return ownerEpoch_; }
54 constexpr T* operator->() const noexcept { return value_; }
56 constexpr T& operator*() const noexcept { return *value_; }
57
58private:
59 T* value_ = nullptr;
60 std::uint64_t ownerEpoch_ = 0;
61};
62
71template <class Tag>
74 std::uint64_t ownerEpoch = 0;
75
77 [[nodiscard]] constexpr bool isValid() const noexcept { return handle.isValid() && ownerEpoch != 0; }
79 [[nodiscard]] constexpr std::uint64_t packed() const noexcept { return handle.packed(); }
80 friend constexpr bool operator==(const RuntimeHandleRef&, const RuntimeHandleRef&) noexcept = default;
81};
82
83} // namespace eve::script
Object::Ptr value
Strong generation-qualified handles for non-ECS runtime registries.
Process-local slot identity tagged by the registry that owns it.
static constexpr RuntimeHandle invalid() noexcept
Returns the canonical invalid handle.
Non-owning observation of a registry-owned object.
constexpr T * operator->() const noexcept
Pointer-like access to the borrowed object.
constexpr Borrowed() noexcept=default
Constructs an unbound Borrowed.
constexpr std::uint64_t ownerEpoch() const noexcept
Returns the epoch of the owner that produced this observation.
constexpr bool isBound() const noexcept
Returns whether the observation currently names an object.
constexpr T * get() const noexcept
Returns the observed pointer, or nullptr when unbound.
constexpr Borrowed(T &value, std::uint64_t ownerEpoch=0) noexcept
Constructs a Borrowed from a live reference.
constexpr T & operator*() const noexcept
Dereferences the borrowed object; the caller owns validity proof.
Handle plus owner-lifetime epoch for a non-ECS registry object.
RuntimeHandle< Tag > handle
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.
constexpr std::uint64_t packed() const noexcept
Returns the packed slot/generation projection.