Skip to main content

SpawnProfileId.ixx File

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

Included Headers

#include <cstdint> #include <string_view> #include <helios.core.algorithms> #include <helios.core.types>

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

structSpawnProfileId

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

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

Hash specialization for SpawnProfileId. More...

Description

Strongly-typed identifier for SpawnProfile instances.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SpawnProfileId.ixx
3 * @brief Strongly-typed identifier for SpawnProfile instances.
4 */
5module;
6
7#include <cstdint>
8#include <string_view>
9
10export module helios.engine.core.data.SpawnProfileId;
11
12import helios.core.types;
13import helios.core.algorithms;
14
15
16export namespace helios::engine::core::data {
17
18 /**
19 * @brief Strongly-typed identifier for SpawnProfile instances.
20 *
21 * @details SpawnProfileId provides type-safe identification for spawn profiles,
22 * which define how entities are spawned (pool reference, placer, initializer).
23 * Using a dedicated ID type prevents accidental misuse of raw integers and
24 * enables compile-time enforcement of correct parameter passing.
25 *
26 * The ID supports hashing for use in unordered containers and comparison
27 * operators for ordered containers.
28 *
29 * ## Construction
30 *
31 * IDs can be constructed from string literals using FNV-1a hashing:
32 * ```cpp
33 * constexpr SpawnProfileId ENEMY_PROFILE{"enemy_spawn"};
34 * constexpr SpawnProfileId POWERUP_PROFILE{"powerup_spawn"};
35 * ```
36 *
37 * Uninitialized IDs for deferred assignment:
38 * ```cpp
39 * SpawnProfileId profileId{helios::core::types::no_init};
40 * profileId = SpawnProfileId{"assigned_later"};
41 * ```
42 *
43 * ## Usage
44 *
45 * ```cpp
46 * std::unordered_map<SpawnProfileId, SpawnProfile> profiles;
47 * profiles[ENEMY_PROFILE] = createEnemyProfile();
48 * ```
49 *
50 * @see SpawnProfile
51 * @see SpawnRuleId
52 * @see GameObjectPoolId
53 */
54 struct SpawnProfileId {
55
56 private:
57
58 /**
59 * @brief The underlying numeric identifier.
60 */
61 uint32_t id_{};
62
63 /**
64 * @brief Constructs a SpawnProfileId with the given numeric value.
65 *
66 * @param id The numeric identifier value.
67 */
68 explicit constexpr SpawnProfileId(const uint32_t id) noexcept
69 : id_(id) {}
70
71 public:
72
73 /**
74 * @brief Constructs an uninitialized SpawnProfileId.
75 *
76 * @details Use this constructor when the ID will be assigned later.
77 * Reading from an uninitialized ID is undefined behavior.
78 *
79 * @see helios::core::types::no_init
80 */
82
83 /**
84 * @brief Constructs a SpawnProfileId from a string literal.
85 *
86 * @details Uses FNV-1a hashing to compute a numeric ID from the string.
87 * This enables readable, compile-time constant profile identifiers.
88 *
89 * ```cpp
90 * constexpr SpawnProfileId ENEMY_PROFILE{"enemy_spawn"};
91 * ```
92 *
93 * @param str The string to hash into an ID.
94 */
95 explicit constexpr SpawnProfileId(const std::string_view str) noexcept
96 : SpawnProfileId(helios::core::algorithms::fnv1a_hash(str)) {}
97
98
99 /**
100 * @brief Returns the underlying numeric value.
101 *
102 * @return The raw identifier value.
103 */
104 [[nodiscard]] uint32_t value() const noexcept {
105 return id_;
106 }
107
108 /**
109 * @brief Default equality comparison.
110 */
111 friend constexpr bool operator==(SpawnProfileId, SpawnProfileId) noexcept = default;
112
113 /**
114 * @brief Less-than comparison for ordered containers.
115 *
116 * @param other The SpawnProfileId to compare against.
117 *
118 * @return True if this ID is less than the other.
119 */
120 constexpr bool operator<(const SpawnProfileId& other) const noexcept {
121 return id_ < other.id_;
122 }
123
124 /**
125 * @brief Greater-than comparison for ordered containers.
126 *
127 * @param other The SpawnProfileId to compare against.
128 *
129 * @return True if this ID is greater than the other.
130 */
131 constexpr bool operator>(const SpawnProfileId& other) const noexcept {
132 return id_ > other.id_;
133 }
134
135 };
136
137}
138
139/**
140 * @brief Hash specialization for SpawnProfileId.
141 *
142 * Enables use as a key in std::unordered_map and std::unordered_set.
143 */
144template<>
145struct std::hash<helios::engine::core::data::SpawnProfileId> {
146
147 /**
148 * @brief Computes the hash value for a SpawnProfileId.
149 *
150 * @param id The SpawnProfileId to hash.
151 *
152 * @return The hash value based on the underlying numeric identifier.
153 */
154 std::size_t operator()(const helios::engine::core::data::SpawnProfileId& id) const noexcept {
155 return id.value();
156 }
157
158};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.