ActiveLib
Loading...
Searching...
No Matches
Guid.h
1
6#ifndef ACTIVE_UTILITY_GUID
7#define ACTIVE_UTILITY_GUID
8
9#include "Active/Utility/String.h"
10
11namespace active::utility {
12
16 class Guid {
17 public:
18
24 static Guid fromInt(int64_t val);
30 static int64_t toInt(const Guid& guid);
31
32 // MARK: - Types
33
34 using Raw = std::pair<uint64_t, uint64_t>;
36 using Option = std::optional<Guid>;
37
38 // MARK: - Constructors
39
44 Guid(bool autoGenerate = false);
45
50 explicit Guid(const String& uuidString);
51
52 // MARK: - Operators
53
54 friend auto operator<=>(const Guid&, const Guid&) = default;
55 friend bool operator==(const Guid&, const Guid&) = default;
56 friend bool operator!=(const Guid&, const Guid&) = default;
57 friend bool operator<(const Guid&, const Guid&) = default;
62 operator String() const { return string(); }
67 operator std::string() const { return string(); }
72 operator bool() const { return (m_value.first != 0) || (m_value.second != 0); }
73
74 // MARK: - Functions (const)
75
80 const Raw& raw() const { return m_value; }
85 String string() const;
86
87 // MARK: - Functions (mutating)
88
92 void reset();
96 void clear() { m_value = {}; }
97
98 private:
99 //The guid value
100 Raw m_value = {};
101 };
102
103}
104
106template<>
107struct std::hash<active::utility::Guid> {
108 std::size_t operator() (const active::utility::Guid& guid) const {
109 return static_cast<std::size_t>(guid.raw().first ^ guid.raw().second);
110 }
111};
112
113#endif //ACTIVE_UTILITY_GUID
Definition Guid.h:16
Guid(bool autoGenerate=false)
Definition Guid.cpp:65
static int64_t toInt(const Guid &guid)
Definition Guid.cpp:55
static Guid fromInt(int64_t val)
Definition Guid.cpp:41
std::optional< Guid > Option
Optional.
Definition Guid.h:36
void reset()
Definition Guid.cpp:119
operator std::string() const
Definition Guid.h:67
void clear()
Definition Guid.h:96
const Raw & raw() const
Definition Guid.h:80
A Unicode-aware string class.
Definition String.h:51
Definition Base64Transport.h:11