Skip to main content

RuntimeHandle.ixx File

Lightweight handle pairing a strong identifier with a runtime index. More...

Included Headers

#include <cstdint> #include <string_view> #include <helios.core.types> #include <helios.core.data.StrongId>

Namespaces Index

namespacehelios
namespacecore

Core utilities shared across the helios engine. More...

namespacedata

Core data primitives for identifiers, handles, and type indexing. More...

Classes Index

structRuntimeHandle<StrongIdentifier, RuntimeId>

A lightweight handle that pairs a stable StrongIdentifier with a dense RuntimeId. More...

structhash<helios::core::data::RuntimeHandle< StrongIdentifier, RuntimeId >>

Hash specialization for RuntimeHandle. More...

Description

Lightweight handle pairing a strong identifier with a runtime index.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file RuntimeHandle.ixx
3 * @brief Lightweight handle pairing a strong identifier with a runtime index.
4 */
5module;
6
7#include <cstdint>
8#include <string_view>
9
10export module helios.core.data.RuntimeHandle;
11
12import helios.core.data.StrongId;
13import helios.core.types;
14
15
16using namespace helios::core::types;
17export namespace helios::core::data {
18
19 /**
20 * @brief A lightweight handle that pairs a stable StrongIdentifier with a dense RuntimeId.
21 *
22 * @details `RuntimeHandle` bridges the gap between content-authored, hash-based
23 * identifiers (`StrongId`) and fast, contiguous runtime indices used by pools
24 * and registries. The handle is a plain value type suitable for storage in
25 * components, containers, and command buffers.
26 *
27 * Equality is defined over both fields; two handles are equal only when both
28 * their `strongId` and `runtimeId` match.
29 *
30 * A `std::hash` specialization is provided so that `RuntimeHandle` can be used
31 * as a key in unordered containers.
32 *
33 * @tparam StrongIdentifier The compile-time identifier type (typically a `StrongId<Tag>`).
34 * @tparam RuntimeId The dense runtime index type (typically `uint32_t`).
35 *
36 * @see StrongId
37 * @see DenseRuntimeHandleRegistry
38 */
39 template<typename StrongIdentifier, typename RuntimeId>
40 struct RuntimeHandle {
41
42 /**
43 * @brief The stable, content-authored identifier.
44 */
45 StrongIdentifier strongId{};
46
47 /**
48 * @brief The dense runtime index assigned by a registry or pool.
49 */
50 RuntimeId runtimeId{};
51
52 /**
53 * @brief Defaulted equality comparison over both fields.
54 */
55 friend bool operator==(const RuntimeHandle&, const RuntimeHandle&) = default;
56
57
58 };
59
60
61}
62
63/**
64 * @brief Hash specialization for RuntimeHandle.
65 *
66 * @details Packs `strongId` and `runtimeId` into a single 64-bit value
67 * before hashing, assuming both underlying types are `uint32_t`.
68 *
69 * @tparam StrongIdentifier The compile-time identifier type.
70 * @tparam RuntimeId The runtime index type.
71 */
72template<typename StrongIdentifier, typename RuntimeId>
73struct std::hash<helios::core::data::RuntimeHandle<StrongIdentifier, RuntimeId>> {
75
76 static_assert(std::is_same_v<helios::core::types::StrongId_t, uint32_t>);
77 static_assert(std::is_same_v<RuntimeId, uint32_t>);
78
79 const uint64_t packed = (static_cast<uint64_t>(handle.strongId.value()) << 32) |
80 static_cast<uint64_t>(handle.runtimeId);
81
82 return std::hash<uint64_t>{}(packed);
83 }
84};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.