Skip to main content

FontId.ixx File

Strongly-typed identifier for font families. More...

Included Headers

#include <cstdint> #include <string_view> #include <helios.core.types> #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

structFontId

Strongly-typed identifier for font families used in text rendering. More...

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

Hash specialization for `FontId` to enable use in unordered containers. More...

Description

Strongly-typed identifier for font families.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file FontId.ixx
3 * @brief Strongly-typed identifier for font families.
4 */
5module;
6
7#include <cstdint>
8#include <string_view>
9
10export module helios.engine.core.data.FontId;
11
12import helios.core.algorithms;
13import helios.core.types;
14
15export namespace helios::engine::core::data {
16
17 /**
18 * @brief Strongly-typed identifier for font families used in text rendering.
19 *
20 * `FontId` provides a compile-time or runtime identifier for font families
21 * registered with the `TextRenderer`. It uses FNV-1a hashing to convert
22 * string names to unique 32-bit identifiers.
23 *
24 * ## Usage
25 *
26 * ```cpp
27 * // Compile-time construction from string literal
28 * constexpr FontId arialFont("Arial");
29 * constexpr FontId monoFont("Monospace");
30 *
31 * // Register font with TextRenderer
32 * textRenderer.addFontFamily(arialFont, "fonts/arial.ttf");
33 *
34 * // Use in TextMesh
35 * TextMesh props{arialFont, {100.0f, 200.0f}, 1.0f};
36 * ```
37 *
38 * @see TextRenderer::addFontFamily()
39 * @see TextMesh
40 */
41 struct FontId {
42
43 private:
44
45 /**
46 * @brief The hashed identifier value.
47 */
48 uint32_t id_{};
49
50 /**
51 * @brief Private constructor from raw hash value.
52 *
53 * @param id The pre-computed hash value.
54 */
55 explicit constexpr FontId(const uint32_t id) noexcept
56 : id_(id) {
57 }
58
59 public:
60
61 /**
62 * @brief Constructs a FontId from a string name.
63 *
64 * Uses FNV-1a hashing to convert the string to a 32-bit identifier.
65 * This constructor is `constexpr`, allowing compile-time evaluation.
66 *
67 * @param str The font family name (e.g., "Arial", "Monospace").
68 */
69 explicit constexpr FontId(const std::string_view str) noexcept
71
72 explicit constexpr FontId(helios::core::types::no_init_t) {};
73
74 /**
75 * @brief Returns the raw identifier value.
76 *
77 * @return The 32-bit hash value.
78 */
79 [[nodiscard]] uint32_t value() const noexcept {
80 return id_;
81 }
82
83 /**
84 * @brief Equality comparison operator.
85 */
86 friend constexpr bool operator==(FontId, FontId) noexcept = default;
87
88 /**
89 * @brief Less-than comparison for ordered containers.
90 *
91 * @param other The FontId to compare against.
92 *
93 * @return `true` if this id is less than `other`.
94 */
95 constexpr bool operator<(const FontId& other) const noexcept {
96 return id_ < other.id_;
97 }
98
99 /**
100 * @brief Greater-than comparison for ordered containers.
101 *
102 * @param other The FontId to compare against.
103 *
104 * @return `true` if this id is greater than `other`.
105 */
106 constexpr bool operator>(const FontId& other) const noexcept {
107 return id_ > other.id_;
108 }
109
110 };
111
112}
113
114/**
115 * @brief Hash specialization for `FontId` to enable use in unordered containers.
116 */
117template<>
118struct std::hash<helios::engine::core::data::FontId> {
119
120 /**
121 * @brief Computes the hash value for a FontId.
122 *
123 * @param id The FontId to hash.
124 *
125 * @return The hash value (same as the internal id).
126 */
127 std::size_t operator()(const helios::engine::core::data::FontId& id) const noexcept {
128 return id.value();
129 }
130
131};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.