Skip to main content

GameObjectPoolId.ixx File

Strongly-typed identifier for GameObjectPool instances. More...

Included Headers

#include <cstdint> #include <helios/helios_config.h> #include <string_view> #include <unordered_map> #include <helios.core.algorithms>

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

structGameObjectPoolId

Strongly-typed identifier for referencing a GameObjectPool. More...

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

Hash specialization for GameObjectPoolId. More...

Description

Strongly-typed identifier for GameObjectPool instances.

File Listing

The file content with the documentation metadata removed is:

1/** @file GameObjectPoolId.ixx
2 * @brief Strongly-typed identifier for GameObjectPool instances.
3 */
4module;
5
6#include <cstdint>
7#include <helios/helios_config.h>
8#include <string_view>
9#include <unordered_map>
10
11export module helios.engine.core.data.GameObjectPoolId;
12
13import helios.core.algorithms;
14
15
16export namespace helios::engine::core::data {
17
18 /**
19 * @brief Strongly-typed identifier for referencing a GameObjectPool.
20 *
21 * @details GameObjectPoolId provides type-safety when working with multiple
22 * object pools. Instead of using raw integers or strings, this wrapper ensures
23 * compile-time checking when accessing pools from a registry.
24 *
25 * The ID is hashable and comparable, making it suitable for use as a key
26 * in associative containers like `std::unordered_map`.
27 *
28 * ## Construction
29 *
30 * IDs can be constructed from string literals using FNV-1a hashing:
31 * ```cpp
32 * constexpr GameObjectPoolId BULLET_POOL{"bullets"};
33 * constexpr GameObjectPoolId ENEMY_POOL{"enemies"};
34 * ```
35 *
36 * ## Usage
37 *
38 * ```cpp
39 * auto* bullets = registry.pool(BULLET_POOL);
40 * auto* enemies = registry.pool(ENEMY_POOL);
41 * ```
42 *
43 * @see SpawnProfileId
44 * @see SpawnRuleId
45 */
46 struct GameObjectPoolId {
47
48 private:
49
50 /**
51 * @brief The underlying numeric identifier.
52 */
53 uint32_t id_;
54
55 /**
56 * @brief Constructs a GameObjectPoolId with the specified value.
57 *
58 * @param id The numeric identifier for this pool.
59 */
60 explicit constexpr GameObjectPoolId(const uint32_t id) noexcept
61 : id_(id) {
62 }
63
64 public:
65
66 /**
67 * @brief Constructs a GameObjectPoolId from a string literal.
68 *
69 * @details Uses FNV-1a hashing to compute a numeric ID from the string.
70 * This enables readable, compile-time constant pool identifiers.
71 *
72 * ```cpp
73 * constexpr GameObjectPoolId BULLET_POOL{"bullets"};
74 * ```
75 *
76 * @param str The string to hash into an ID.
77 */
78 explicit constexpr GameObjectPoolId(const std::string_view str) noexcept
79 : GameObjectPoolId(helios::core::algorithms::fnv1a_hash(str)) {}
80
81 /**
82 * @brief Returns the underlying numeric value.
83 *
84 * @return The pool ID as an unsigned 32-bit integer.
85 */
86 [[nodiscard]] uint32_t value() const noexcept {
87 return id_;
88 }
89
90 /**
91 * @brief Equality comparison operator.
92 */
93 friend constexpr bool operator ==(GameObjectPoolId, GameObjectPoolId) noexcept = default;
94
95 /**
96 * @brief Less-than comparison operator for ordered containers.
97 *
98 * @param other The GameObjectPoolId to compare against.
99 *
100 * @return True if this ID is less than other.
101 */
102 constexpr bool operator<(const GameObjectPoolId& other) const noexcept {
103 return id_ < other.id_;
104 }
105
106 /**
107 * @brief Greater-than comparison operator for ordered containers.
108 *
109 * @param other The GameObjectPoolId to compare against.
110 *
111 * @return True if this ID is greater than other.
112 */
113 constexpr bool operator>(const GameObjectPoolId& other) const noexcept {
114 return id_ > other.id_;
115 }
116
117
118
119 };
120
121}
122
123/**
124 * @brief Hash specialization for GameObjectPoolId.
125 *
126 * Enables use as a key in std::unordered_map and std::unordered_set.
127 */
128template<>
129struct std::hash<helios::engine::core::data::GameObjectPoolId> {
130 std::size_t operator()(const helios::engine::core::data::GameObjectPoolId& id) const noexcept {
131 return id.value();
132 }
133};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.