Skip to main content

StrongId.ixx File

Strongly-typed identifier template. More...

Included Headers

#include <cstdint> #include <string_view> #include <helios.ecs.types.TypeDefs> #include <helios.ecs.types.FuncDefs>

Namespaces Index

namespacehelios
namespaceecs
namespacetypes

Classes Index

structStrongId<Tag>

A strongly-typed identifier using tag-based type safety. More...

structhash<helios::ecs::types::StrongId< Tag >>

Description

Strongly-typed identifier template.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cstdint>
8#include <string_view>
9
10export module helios.ecs.types.StrongId;
11
12import helios.ecs.types.FuncDefs;
13import helios.ecs.types.TypeDefs;
14
15export namespace helios::ecs::types {
16
26 template<typename Tag>
27 struct StrongId {
28
29 private:
30
34 StrongId_t id_{};
35
36 public:
37
45 explicit constexpr StrongId(const std::string_view str) noexcept
46 : StrongId(fnv1a_hash(str)) {}
47
48
54 explicit constexpr StrongId(const StrongId_t id) noexcept
55 : id_(id) {
56 }
57
63 explicit constexpr StrongId(no_init_t) {}
64
68 constexpr StrongId() noexcept = default;
69
75 [[nodiscard]] bool isValid() const noexcept {
76 return id_ != 0;
77 }
78
84 [[nodiscard]] StrongId_t value() const noexcept {
85 return id_;
86 }
87
93 [[nodiscard]] explicit operator bool() const noexcept {
94 return id_ != 0;
95 }
96
100 friend constexpr bool operator==(StrongId, StrongId) noexcept = default;
101
109 constexpr bool operator<(const StrongId& other) const noexcept {
110 return id_ < other.id_;
111 }
112
120 constexpr bool operator>(const StrongId& other) const noexcept {
121 return id_ > other.id_;
122 }
123
124 };
125
126}
127
128
129template<typename Tag>
130struct std::hash<helios::ecs::types::StrongId<Tag>> {
132 return id.value();
133 }
134
135};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.