Skip to main content

Guid.ixx File

Lightweight GUID (globally unique identifier) implementation. More...

Included Headers

#include <atomic> #include <cstdint> #include <cstddef> #include <helios.ecs.types>

Namespaces Index

namespacehelios
namespaceengine
namespaceutil

Classes Index

classGuid

Representative of a Globally Unique Identifier. More...

structhash<helios::engine::util::Guid>

Description

Lightweight GUID (globally unique identifier) implementation.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <atomic>
8#include <cstdint>
9#include <cstddef>
10
11export module helios.engine.util.Guid;
12
13import helios.ecs.types;
14
15
16export namespace helios::engine::util {
17
18
24 class Guid final {
25 private:
26 explicit Guid(uint64_t value) noexcept : value_(value) {}
27 uint64_t value_{};
28
29 public:
30
34 explicit Guid(helios::ecs::types::no_init_t) {};
35
43 constexpr bool operator==(const Guid& guid) const = default;
44
52 constexpr bool operator!=(const Guid& guid) const = default;
53
61 constexpr bool operator<(const Guid& guid) const noexcept {
62 return value_ < guid.value();
63 }
64
72 constexpr bool operator>(const Guid& guid) const noexcept {
73 return value_ > guid.value();
74 }
75
76
86 static std::atomic<uint64_t> counter{1};
87 return Guid(counter.fetch_add(1, std::memory_order_relaxed));
88 }
89
96 return value_;
97 }
98
106 [[nodiscard]] std::size_t hash() const noexcept {
107 return std::hash<uint64_t>{}(value_);
108 }
109
110 };
111
112} // namespace helios::engine::util
113
114
115template<>
116struct std::hash<helios::engine::util::Guid> {
117 std::size_t operator()(const helios::engine::util::Guid& guid) const noexcept {
118 return guid.hash();
119 }
120};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.