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 MCAPI ::std::string asString() const;
40 // NOLINTEND
41
42public:
43 // static functions
44 // NOLINTBEGIN
45 MCAPI static bool canParse(::std::string const& in);
46
47 MCAPI static ::mce::UUID fromString(::std::string const& in);
48 // NOLINTEND
49
50public:
51 // static variables
52 // NOLINTBEGIN
53 MCAPI static ::mce::UUID& EMPTY();
54
55 MCAPI static uint64& STRING_LENGTH();
56 // NOLINTEND
57};
58
59} // namespace mce
60
61namespace std {
62template <>
63struct hash<mce::UUID> {
64 size_t operator()(mce::UUID const& id) const noexcept { return id.a ^ (522133279 * id.b); }
65};
66} // namespace std
Definition UUID.h:7
STL namespace.