galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
UUID.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_UTILS_UUID_HPP_
9#define GALAXY_UTILS_UUID_HPP_
10
11#include <array>
12#include <format>
13
14namespace galaxy
15{
20 class UUID final
21 {
22 public:
26 UUID();
27
31 UUID(UUID&&) noexcept;
32
36 [[maybe_unused]]
37 UUID& operator=(UUID&&) noexcept;
38
42 UUID(const UUID&) noexcept;
43
47 [[maybe_unused]]
48 UUID& operator=(const UUID&) noexcept;
49
53 ~UUID() noexcept;
54
60 [[nodiscard]]
61 std::size_t hash() noexcept;
62
68 [[nodiscard]]
69 const std::string& str() const noexcept;
70
78 [[nodiscard]]
79 bool operator==(const UUID& rhs) noexcept;
80
88 [[nodiscard]]
89 bool operator!=(const UUID& rhs) noexcept;
90
91 private:
95 std::array<unsigned char, 16> m_uuid;
96
100 std::string m_str;
101 };
102} // namespace galaxy
103
104namespace std
105{
109 template<>
110 struct hash<galaxy::UUID>
111 {
115 std::size_t operator()(galaxy::UUID& uuid) const noexcept
116 {
117 return uuid.hash();
118 }
119 };
120} // namespace std
121
122template<>
123struct std::formatter<galaxy::UUID> : std::formatter<std::string>
124{
125 auto format(const galaxy::UUID& uuid, format_context& ctx) const noexcept
126 {
127 return std::formatter<std::string>::format(uuid.str(), ctx);
128 }
129};
130
131#endif
Contains a 128bit randomly generated UUID, along with helper functions.
Definition UUID.hpp:21
std::array< unsigned char, 16 > m_uuid
UUID.
Definition UUID.hpp:95
UUID()
Constructor.
Definition UUID.cpp:16
bool operator==(const UUID &rhs) noexcept
Equality comparison.
Definition UUID.cpp:98
const std::string & str() const noexcept
Get the UUID as a string.
Definition UUID.cpp:93
bool operator!=(const UUID &rhs) noexcept
Inequality comparison.
Definition UUID.cpp:103
std::string m_str
String representation.
Definition UUID.hpp:100
UUID & operator=(UUID &&) noexcept
Move assignment operator.
Definition UUID.cpp:51
~UUID() noexcept
Destructor.
Definition UUID.cpp:79
std::size_t hash() noexcept
Get the UUID as a hash.
Definition UUID.cpp:83
Animated.cpp galaxy.
Definition Animated.cpp:16
STL namespace.
auto format(const galaxy::UUID &uuid, format_context &ctx) const noexcept
Definition UUID.hpp:125
std::size_t operator()(galaxy::UUID &uuid) const noexcept
Hash specialization function for UUID.
Definition UUID.hpp:115