Skip to main content

ComponentTypeId.ixx File

Compile-time type identifier for component types. More...

Included Headers

#include <functional> #include <helios.core.types> #include <helios.core.data.TypeIndexer>

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacecore

Core engine infrastructure providing fundamental building blocks. More...

namespacedata

Data structures for efficient entity management. More...

Classes Index

classComponentTypeId

Unique type identifier for component types. More...

structhelios_engine_core_data_ComponentTypes

Tag type for the TypeIndexer domain. More...

structhash<helios::engine::core::data::ComponentTypeId>

std::hash specialization for ComponentTypeId. More...

Description

Compile-time type identifier for component types.

Provides a unique, compile-time generated ID for each component type, enabling O(1) direct indexing into the component storage vector within GameObject.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ComponentTypeId.ixx
3 * @brief Compile-time type identifier for component types.
4 *
5 * @details Provides a unique, compile-time generated ID for each component type,
6 * enabling O(1) direct indexing into the component storage vector within GameObject.
7 */
8module;
9
10#include <functional>
11
12export module helios.engine.core.data.ComponentTypeId;
13
14import helios.core.data.TypeIndexer;
15import helios.core.types;
16
17export namespace helios::engine::core::data {
18
19 /**
20 * @brief Unique type identifier for component types.
21 *
22 * @details ComponentTypeId assigns a unique, monotonically increasing integer ID
23 * to each component type at compile time. This ID is used as an index into the
24 * component storage vector within GameObject, enabling O(1) access.
25 *
26 * **Usage:**
27 * ```cpp
28 * // Get the ID for a component type
29 * auto id = ComponentTypeId::id<Move2DComponent>();
30 *
31 * // Use the value as an index
32 * components_[id.value()] = std::move(component);
33 * ```
34 *
35 * **Thread Safety:** The static ID generation is thread-safe due to C++11 static
36 * initialization guarantees.
37 *
38 * @see TypeIndexer
39 * @see GameObject
40 */
42
43 /**
44 * @brief Tag type for the TypeIndexer domain.
45 */
46 struct helios_engine_core_data_ComponentTypes{};
47
48 using ComponentType = helios_engine_core_data_ComponentTypes;
49
50 /**
51 * @brief The underlying ID value.
52 */
53 size_t id_{0};
54
55
56 public:
57
58 /**
59 * @brief Constructs a ComponentTypeId with a specific ID value.
60 *
61 * @details This constructor initializes a ComponentTypeId object with a given
62 * ID, representing a unique identifier for a component type. The ID is used
63 * internally for indexing and retrieving components from the storage system.
64 *
65 * @param id The unique identifier assigned to the component type.
66 * This ID must be a valid non-negative value.
67 */
68 explicit ComponentTypeId(const size_t id) : id_(id) {}
69
70 /**
71 * @brief Constructs an uninitialized ComponentTypeId.
72 *
73 * @param no_init_t Tag to indicate no initialization.
74 */
76
77 /**
78 * @brief Returns the underlying ID value.
79 *
80 * @return The numeric type ID, suitable for use as an array index.
81 */
82 [[nodiscard]] size_t value() const noexcept {
83 return id_;
84 }
85
86 /**
87 * @brief Gets the ComponentTypeId for a specific component type.
88 *
89 * @details Uses TypeIndexer to generate a unique, monotonically increasing ID
90 * for each component type. The ID is generated once per type and cached.
91 *
92 * @tparam T The component type. Must be a concrete type (not abstract).
93 *
94 * @return The unique ComponentTypeId for type T.
95 */
96 template <typename T>
97 [[nodiscard]] static ComponentTypeId id() {
99 return ComponentTypeId(tid);
100 }
101
102 friend constexpr bool operator==(ComponentTypeId, ComponentTypeId) noexcept = default;
103 };
104
105
106}
107
108
109/**
110 * @brief std::hash specialization for ComponentTypeId.
111 *
112 * @details Enables use of ComponentTypeId as a key in unordered containers.
113 */
114template<>
115struct std::hash<helios::engine::core::data::ComponentTypeId> {
116 std::size_t operator()(const helios::engine::core::data::ComponentTypeId& id) const noexcept {
117 return id.value();
118 }
119
120};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.