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