StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
ID.hpp
1#pragma once
2#include <cstdint>
3#include <functional>
4#include <stdint.h>
5
6namespace StevEngine::Utilities {
13 class ID {
14 public:
18 ID();
19
24 ID(const ID& other);
25
30 ID(uint8_t* raw);
31
36 ID(const char* text);
37
42 const char* GetString() const;
43
49 ID& operator=(const ID& other);
50
56 bool operator==(const ID& other) const;
57
63 bool operator<(const ID& other) const;
64
71 bool operator()(const ID& lhs, const ID& rhs) const;
72
77 bool IsNull() const;
78
80 static ID empty;
81
82 const uint8_t* GetRaw() const { return raw; }
83
84 private:
85 uint8_t raw[16];
86 };
87}
88
89template<> struct std::hash<StevEngine::Utilities::ID> {
95 std::size_t operator()(const StevEngine::Utilities::ID& k) const {
96 size_t result = 0;
97 std::hash<uint8_t> hasher;
98 auto values = k.GetRaw();
99 for (uint8_t i = 0; i < 16; i++) {
100 result = result * 31 + hasher(values[i]);
101 }
102 return result;
103 }
104};
UUID-based unique identifier.
Definition ID.hpp:13
static ID empty
Null/empty ID value.
Definition ID.hpp:80
bool operator==(const ID &other) const
Equality comparison.
Definition ID.cpp:68
const char * GetString() const
Get string representation.
Definition ID.cpp:18
ID & operator=(const ID &other)
Assignment operator.
Definition ID.cpp:63
bool IsNull() const
Check if ID is null/empty.
Definition ID.cpp:61
bool operator<(const ID &other) const
Less than comparison for sorting.
Definition ID.cpp:75
bool operator()(const ID &lhs, const ID &rhs) const
Compare function for containers.
Definition ID.cpp:83
ID()
Generate new random UUID.
Definition ID.cpp:24
std::size_t operator()(const StevEngine::Utilities::ID &k) const
Hash function for ID.
Definition ID.hpp:95