API Documentation
Loading...
Searching...
No Matches
UUID.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: UUID
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Vector.h>
35#include <NDEVR/ObjectInfo.h>
36
37namespace NDEVR
38{
39 /**--------------------------------------------------------------------------------------------------
40 \brief A universally unique identifier (UUID) is a 128-bit number used to identify information in
41 computer systems. The term globally unique identifier (GUID) is also used.
42
43 UUIDs are for practical purposes unique, without depending for their uniqueness on a central
44 registration authority or coordination between the parties generating them, unlike most other
45 numbering schemes. While the probability that a UUID will be duplicated is not zero, it is
46 close enough to zero to be negligible.
47
48 Thus, anyone can create a UUID and use it to identify something with near certainty that
49 the identifier does not duplicate one that has already been, or will be, created to identify
50 something else. Information labeled with UUIDs by independent parties can therefore be later
51 combined into a single database, or transmitted on the same channel, without needing
52 to resolve conflicts between identifiers.
53
54 Author: Tyler Parke
55
56 Date: 2017-11-17
57 **/
58
59 class UUID : public Vector<16, uint01>
60 {
61 public:
62 constexpr UUID()
64 {}
65 constexpr explicit UUID(const Vector<16, uint01>& bytes) noexcept
66 : Vector<16, uint01>(bytes)
67 {}
68 explicit UUID(const bool& other) noexcept
70 {
71 *this = appendUUID(other);
72 }
73 explicit UUID(const uint01& other) noexcept
75 {
76 *this = appendUUID(other);
77 }
78 explicit UUID(const uint02& other) noexcept
80 {
81 *this = appendUUID(other);
82 }
83 explicit UUID(const uint04& other) noexcept
85 {
86 *this = appendUUID(other);
87 }
88 explicit UUID(const uint08& other) noexcept
90 {
91 *this = appendUUID(other);
92 }
93 explicit UUID(const sint01& other) noexcept
95 {
96 *this = appendUUID(other);
97 }
98 explicit UUID(const sint02& other) noexcept
100 {
101 *this = appendUUID(other);
102 }
103 explicit UUID(const sint04& other) noexcept
105 {
106 *this = appendUUID(other);
107 }
108 explicit UUID(const sint08& other) noexcept
110 {
111 *this = appendUUID(other);
112 }
113
114 explicit UUID(const fltp04& other) noexcept
116 {
117 *this = appendUUID(other);
118 }
119 explicit UUID(const fltp08& other) noexcept
121 {
122 *this = appendUUID(other);
123 }
124
125 /**--------------------------------------------------------------------------------------------------
126 Gets unique pointer.
127
128 Author: Tyler Parke
129
130 Date: 2017-11-17
131
132 \returns Null if it fails, else the unique pointer.
133 **/
134
136
137 /**--------------------------------------------------------------------------------------------------
138 Creates the uuid.
139
140 Author: Tyler Parke
141
142 Date: 2017-11-17
143
144 \returns The new uuid.
145 **/
146
148 NDEVR_BASE_API static constexpr UUID CreateUUID(const char* identifier)
149 {
151 uint01 i = 0;
152 while (*identifier)
153 {
154 id[i] = id[i] ^ *identifier;
155 i = (i + 1) % 16;
156 identifier++;
157 }
158 return id;
159 }
160 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(bool offset) const;
161 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const char* identifier) const;
162 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(uint04 offset) const;
163 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(uint08 offset) const;
164 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(sint04 offset) const;
165 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(sint08 offset) const;
166 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(fltp04 offset) const;
167 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const Vector<3, fltp04>& offset) const;
168 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(fltp08 offset) const;
169 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const UUID& offset) const;
170 template<uint01 t_size, class t_type>
171 [[nodiscard]] UUID appendUUID(const Vector<t_size, t_type>& offset) const
172 {
173 UUID id(*this);
174 for (uint01 i = 0; i < t_size; i++)
175 id = id.appendUUID(offset[i]);
176 return id;
177 }
178 constexpr size_t hash() const
179 {
180 std::size_t value = 0;
181 for (uint01 i = 0; i < 8; i++)
182 {
183 value = value * 256 + ((*this)[i + 0] ^ (*this)[i + 8]);
184 }
185 return value;
186 }
187 constexpr size_t operator()() const
188 {
189 return hash();
190 }
191 bool operator<(const UUID& other) const
192 {
193 for (uint01 i = 0; i < 16; i++)
194 {
195 if ((*this)[i] == other[i])
196 continue;
197 return (*this)[i] < other[i];
198 }
199 return false;
200 }
201 bool operator<=(const UUID& other) const
202 {
203 for (uint01 i = 0; i < 16; i++)
204 {
205 if ((*this)[i] == other[i])
206 continue;
207 return (*this)[i] < other[i];
208 }
209 return true;
210 }
211 bool operator>(const UUID& other) const
212 {
213 for (uint01 i = 0; i < 16; i++)
214 {
215 if ((*this)[i] == other[i])
216 continue;
217 return (*this)[i] > other[i];
218 }
219 return false;
220 }
221 bool operator>=(const UUID& other) const
222 {
223 for (uint01 i = 0; i < 16; i++)
224 {
225 if ((*this)[i] == other[i])
226 continue;
227 return (*this)[i] > other[i];
228 }
229 return true;
230 }
231 };
232
233 template<>
234 struct ObjectInfo<UUID, true, false>
235 {
236 static const uint01 Dimensions = 16;
237 static const bool Vector = true;
238 static const bool Buffer = false;
239 static const bool Primitive = true;
240 static const bool Pointer = false;
241 static const bool Unsigned = false;
242 static const bool Float = false;
243 static const bool Integer = false;
244 static const bool Number = false;
245 static const bool Enum = false;
246 static const bool String = true;
247 static const bool Color = false;
248 static const bool Boolean = false;
249 static constexpr ObjectInfo<uint01, false, false> VectorSub() { return ObjectInfo<uint01, false, false>(); }
250 };
252 template<> constexpr const UUID Constant<UUID>::Max = UUID(Constant<Vector<16, uint01>>::Max);
253 template<> constexpr const UUID Constant<UUID>::Min = UUID(Constant<Vector<16, uint01>>::Min);
254}
255namespace std//Define things to allow use within std libs
256{
257 template <>
258 struct hash<NDEVR::UUID>
259 {
260 std::size_t operator()(const NDEVR::UUID& s) const noexcept
261 {
262 std::size_t value = 0;
263 for (NDEVR::uint01 i = 0; i < 8; i++)
264 {
265 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
266 }
267 return value;
268 }
269 };
270};
271#ifdef _MSC_VER
272 //Used to help debugging
273 namespace natvis
274 {
275 struct x4lo { unsigned __int8 v : 4; unsigned __int8 _ : 4; }; // NOLINT(clang-diagnostic-language-extension-token)
276 struct x4hi { unsigned __int8 _ : 4; unsigned __int8 v : 4; }; // NOLINT(clang-diagnostic-language-extension-token)
277 struct x8 { unsigned __int8 _; }; // NOLINT(clang-diagnostic-language-extension-token)
278 struct x32 { __int32 _; }; // NOLINT(clang-diagnostic-language-extension-token)
279 }
280#endif
#define NDEVR_BASE_API
Definition DLLInfo.h:57
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
static UUID CreateUUID()
constexpr size_t hash() const
Definition UUID.h:178
UUID(const uint04 &other) noexcept
Definition UUID.h:83
UUID appendUUID(uint08 offset) const
constexpr UUID()
Definition UUID.h:62
bool operator>=(const UUID &other) const
Definition UUID.h:221
UUID(const sint08 &other) noexcept
Definition UUID.h:108
UUID(const fltp04 &other) noexcept
Definition UUID.h:114
UUID appendUUID(fltp08 offset) const
UUID(const bool &other) noexcept
Definition UUID.h:68
bool operator>(const UUID &other) const
Definition UUID.h:211
uint01 * getUniquePointer() const
UUID(const sint01 &other) noexcept
Definition UUID.h:93
UUID appendUUID(const Vector< t_size, t_type > &offset) const
Definition UUID.h:171
UUID appendUUID(bool offset) const
constexpr size_t operator()() const
Definition UUID.h:187
UUID(const sint02 &other) noexcept
Definition UUID.h:98
UUID appendUUID(const char *identifier) const
UUID(const sint04 &other) noexcept
Definition UUID.h:103
bool operator<=(const UUID &other) const
Definition UUID.h:201
UUID appendUUID(const UUID &offset) const
UUID appendUUID(sint04 offset) const
constexpr UUID(const Vector< 16, uint01 > &bytes) noexcept
Definition UUID.h:65
bool operator<(const UUID &other) const
Definition UUID.h:191
UUID appendUUID(const Vector< 3, fltp04 > &offset) const
UUID(const uint08 &other) noexcept
Definition UUID.h:88
static constexpr UUID CreateUUID(const char *identifier)
Definition UUID.h:148
UUID(const uint01 &other) noexcept
Definition UUID.h:73
UUID appendUUID(sint08 offset) const
UUID(const fltp08 &other) noexcept
Definition UUID.h:119
UUID appendUUID(fltp04 offset) const
UUID appendUUID(uint04 offset) const
UUID(const uint02 &other) noexcept
Definition UUID.h:78
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:71
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
int8_t sint01
-Defines an alias representing a 1 byte, signed integer. -Can represent exact integer values -127 thr...
Definition BaseValues.hpp:50
int16_t sint02
-Defines an alias representing a 2 byte, signed integer. -Can represent exact integer values -32767 t...
Definition BaseValues.hpp:57
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:88
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Definition BitFlag.hpp:249
Definition File.h:211
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233