forked from LiteLDev/LeviLamina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUUID.h
66 lines (47 loc) · 1.68 KB
/
UUID.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include "mc/_HeaderOutputPredefine.h"
namespace mce {
class UUID {
public:
uint64 a, b;
[[nodiscard]] constexpr UUID(uint64 a = 0, uint64 b = 0) noexcept : a(a), b(b) {}
[[nodiscard]] inline UUID(std::string const& uuidStr) : UUID(fromString(uuidStr)) {}
[[nodiscard]] inline UUID(std::string_view uuidStr) : UUID(fromString(std::string{uuidStr})) {}
LLNDAPI static mce::UUID random();
[[nodiscard]] inline static mce::UUID fromStringHash(std::string_view sv) {
return {ll::hash_utils::doHash(sv), ll::hash_utils::doHash2(sv)};
}
[[nodiscard]] inline explicit operator bool() const { return a != 0 && b != 0; }
[[nodiscard]] inline explicit operator std::string() const { return asString(); }
[[nodiscard]] constexpr bool operator==(UUID const& other) const { return (a == other.a) && (b == other.b); }
[[nodiscard]] constexpr std::strong_ordering operator<=>(UUID const& other) const {
if (a != other.a) {
return a <=> other.a;
}
return b <=> other.b;
}
public:
// member functions
// NOLINTBEGIN
MCAPI ::std::string asString() const;
// NOLINTEND
public:
// static functions
// NOLINTBEGIN
MCAPI static bool canParse(::std::string const& in);
MCAPI static ::mce::UUID fromString(::std::string const& in);
// NOLINTEND
public:
// static variables
// NOLINTBEGIN
MCAPI static ::mce::UUID& EMPTY();
MCAPI static uint64& STRING_LENGTH();
// NOLINTEND
};
} // namespace mce
namespace std {
template <>
struct hash<mce::UUID> {
size_t operator()(mce::UUID const& id) const noexcept { return id.a ^ (522133279 * id.b); }
};
} // namespace std