summaryrefslogtreecommitdiff
path: root/src/common/new_uuid.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/new_uuid.h')
-rw-r--r--src/common/new_uuid.h141
1 files changed, 0 insertions, 141 deletions
diff --git a/src/common/new_uuid.h b/src/common/new_uuid.h
deleted file mode 100644
index 44665ad5a..000000000
--- a/src/common/new_uuid.h
+++ /dev/null
@@ -1,141 +0,0 @@
1// Copyright 2022 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <functional>
9#include <string>
10#include <string_view>
11
12#include "common/common_types.h"
13
14namespace Common {
15
16struct NewUUID {
17 std::array<u8, 0x10> uuid{};
18
19 /// Constructs an invalid UUID.
20 constexpr NewUUID() = default;
21
22 /// Constructs a UUID from a reference to a 128 bit array.
23 constexpr explicit NewUUID(const std::array<u8, 16>& uuid_) : uuid{uuid_} {}
24
25 /**
26 * Constructs a UUID from either:
27 * 1. A 32 hexadecimal character string representing the bytes of the UUID
28 * 2. A RFC 4122 formatted UUID string, in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
29 *
30 * The input string may contain uppercase or lowercase characters, but they must:
31 * 1. Contain valid hexadecimal characters (0-9, a-f, A-F)
32 * 2. Not contain the "0x" hexadecimal prefix
33 *
34 * Should the input string not meet the above requirements,
35 * an assert will be triggered and an invalid UUID is set instead.
36 */
37 explicit NewUUID(std::string_view uuid_string);
38
39 ~NewUUID() = default;
40
41 constexpr NewUUID(const NewUUID&) noexcept = default;
42 constexpr NewUUID(NewUUID&&) noexcept = default;
43
44 constexpr NewUUID& operator=(const NewUUID&) noexcept = default;
45 constexpr NewUUID& operator=(NewUUID&&) noexcept = default;
46
47 /**
48 * Returns whether the stored UUID is valid or not.
49 *
50 * @returns True if the stored UUID is valid, false otherwise.
51 */
52 constexpr bool IsValid() const {
53 return uuid != std::array<u8, 0x10>{};
54 }
55
56 /**
57 * Returns whether the stored UUID is invalid or not.
58 *
59 * @returns True if the stored UUID is invalid, false otherwise.
60 */
61 constexpr bool IsInvalid() const {
62 return !IsValid();
63 }
64
65 /**
66 * Returns a 32 hexadecimal character string representing the bytes of the UUID.
67 *
68 * @returns A 32 hexadecimal character string of the UUID.
69 */
70 std::string RawString() const;
71
72 /**
73 * Returns a RFC 4122 formatted UUID string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
74 *
75 * @returns A RFC 4122 formatted UUID string.
76 */
77 std::string FormattedString() const;
78
79 /**
80 * Returns a 64-bit hash of the UUID for use in hash table data structures.
81 *
82 * @returns A 64-bit hash of the UUID.
83 */
84 size_t Hash() const noexcept;
85
86 /// DO NOT USE. Copies the contents of the UUID into a u128.
87 u128 AsU128() const;
88
89 /**
90 * Creates a default UUID "yuzu Default UID".
91 *
92 * @returns A UUID with its bytes set to the ASCII values of "yuzu Default UID".
93 */
94 static constexpr NewUUID MakeDefault() {
95 return NewUUID{
96 {'y', 'u', 'z', 'u', ' ', 'D', 'e', 'f', 'a', 'u', 'l', 't', ' ', 'U', 'I', 'D'},
97 };
98 }
99
100 /**
101 * Creates a random UUID.
102 *
103 * @returns A random UUID.
104 */
105 static NewUUID MakeRandom();
106
107 /**
108 * Creates a random UUID with a seed.
109 *
110 * @param seed A seed to initialize the Mersenne-Twister RNG
111 *
112 * @returns A random UUID.
113 */
114 static NewUUID MakeRandomWithSeed(u32 seed);
115
116 /**
117 * Creates a random UUID. The generated UUID is RFC 4122 Version 4 compliant.
118 *
119 * @returns A random UUID that is RFC 4122 Version 4 compliant.
120 */
121 static NewUUID MakeRandomRFC4122V4();
122
123 friend constexpr bool operator==(const NewUUID& lhs, const NewUUID& rhs) = default;
124};
125static_assert(sizeof(NewUUID) == 0x10, "UUID has incorrect size.");
126
127/// An invalid UUID. This UUID has all its bytes set to 0.
128constexpr NewUUID InvalidUUID = {};
129
130} // namespace Common
131
132namespace std {
133
134template <>
135struct hash<Common::NewUUID> {
136 size_t operator()(const Common::NewUUID& uuid) const noexcept {
137 return uuid.Hash();
138 }
139};
140
141} // namespace std