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: Parke
38Namespace that wraps all Logic created by Tyler Parke
39 *-----------------------------------------------------------------------------------------------**/
40
41namespace NDEVR
42{
43 /**--------------------------------------------------------------------------------------------------
44 Class: UUID
45
46 A universally unique identifier (UUID) is a 128-bit number used to identify information in
47 computer systems. The term globally unique identifier (GUID) is also used.
48
49 UUIDs are for practical purposes unique, without depending for their uniqueness on a central
50 registration authority or coordination between the parties generating them, unlike most other
51 numbering schemes. While the probability that a UUID will be duplicated is not zero, it is
52 close enough to zero to be negligible.
53
54 Thus, anyone can create a UUID and use it to identify something with near certainty that
55 the identifier does not duplicate one that has already been, or will be, created to identify
56 something else. Information labeled with UUIDs by independent parties can therefore be later
57 combined into a single database, or transmitted on the same channel, without needing
58 to resolve conflicts between identifiers.
59
60 Author: Tyler Parke
61
62 Date: 2017-11-17
63 *-----------------------------------------------------------------------------------------------**/
64
65 class UUID : public Vector<16, uint01>
66 {
67 public:
68 constexpr UUID()
69 : Vector<16, uint01>(Constant<uint01>::NaN)
70 {}
71 constexpr explicit UUID(const Vector<16, uint01>& bytes) noexcept
72 : Vector<16, uint01>(bytes)
73 {}
74 explicit UUID(const bool& other) noexcept
76 {
77 *this = appendUUID(other);
78 }
79 explicit UUID(const uint01& other) noexcept
81 {
82 *this = appendUUID(other);
83 }
84 explicit UUID(const uint02& other) noexcept
86 {
87 *this = appendUUID(other);
88 }
89 explicit UUID(const uint04& other) noexcept
91 {
92 *this = appendUUID(other);
93 }
94 explicit UUID(const uint08& other) noexcept
96 {
97 *this = appendUUID(other);
98 }
99 explicit UUID(const sint01& other) noexcept
101 {
102 *this = appendUUID(other);
103 }
104 explicit UUID(const sint02& other) noexcept
106 {
107 *this = appendUUID(other);
108 }
109 explicit UUID(const sint04& other) noexcept
111 {
112 *this = appendUUID(other);
113 }
114 explicit UUID(const sint08& other) noexcept
116 {
117 *this = appendUUID(other);
118 }
119
120 explicit UUID(const fltp04& other) noexcept
122 {
123 *this = appendUUID(other);
124 }
125 explicit UUID(const fltp08& other) noexcept
127 {
128 *this = appendUUID(other);
129 }
130
131 /**--------------------------------------------------------------------------------------------------
132 Fn: uint01* UUID::getUniquePointer() const;
133
134 Gets unique pointer.
135
136 Author: Tyler Parke
137
138 Date: 2017-11-17
139
140 Returns: Null if it fails, else the unique pointer.
141 *-----------------------------------------------------------------------------------------------**/
142
144
145 /**--------------------------------------------------------------------------------------------------
146 Fn: static UUID UUID::CreateUUID();
147
148 Creates the uuid.
149
150 Author: Tyler Parke
151
152 Date: 2017-11-17
153
154 Returns: The new uuid.
155 *-----------------------------------------------------------------------------------------------**/
156
158 NDEVR_BASE_API static constexpr UUID CreateUUID(const char* identifier)
159 {
161 uint01 i = 0;
162 while (*identifier)
163 {
164 id[i] = id[i] ^ *identifier;
165 i = (i + 1) % 16;
166 identifier++;
167 }
168 return id;
169 }
170 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(bool offset) const;
171 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const char* identifier) const;
172 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(uint04 offset) const;
173 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(uint08 offset) const;
174 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(sint04 offset) const;
175 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(sint08 offset) const;
176 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(fltp04 offset) const;
177 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const Vector<3, fltp04>& offset) const;
178 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(fltp08 offset) const;
179 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const UUID& offset) const;
180 template<uint01 t_size, class t_type>
181 [[nodiscard]] UUID appendUUID(const Vector<t_size, t_type>& offset) const
182 {
183 UUID id(*this);
184 for (uint01 i = 0; i < t_size; i++)
185 id = id.appendUUID(offset[i]);
186 return id;
187 }
188 constexpr size_t hash() const
189 {
190 std::size_t value = 0;
191 for (uint01 i = 0; i < 8; i++)
192 {
193 value = value * 256 + ((*this)[i + 0] ^ (*this)[i + 8]);
194 }
195 return value;
196 }
197 constexpr size_t operator()() const
198 {
199 return hash();
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 false;
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 true;
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 false;
230 }
231 bool operator>=(const UUID& other) const
232 {
233 for (uint01 i = 0; i < 16; i++)
234 {
235 if ((*this)[i] == other[i])
236 continue;
237 return (*this)[i] > other[i];
238 }
239 return true;
240 }
241 };
242
243 template<>
244 struct ObjectInfo<UUID, true, false>
245 {
246 static const uint01 Dimensions = 16;
247 static const bool Vector = true;
248 static const bool Buffer = false;
249 static const bool Primitive = true;
250 static const bool Pointer = false;
251 static const bool Unsigned = false;
252 static const bool Float = false;
253 static const bool Integer = false;
254 static const bool Number = false;
255 static const bool Enum = false;
256 static const bool String = true;
257 static const bool Color = false;
258 static const bool Boolean = false;
260 };
261 template<> constexpr const UUID Constant<UUID>::NaN = UUID(Constant<Vector<16, uint01>>::NaN);
262 template<> constexpr const UUID Constant<UUID>::Max = UUID(Constant<Vector<16, uint01>>::Max);
263 template<> constexpr const UUID Constant<UUID>::Min = UUID(Constant<Vector<16, uint01>>::Min);
264}
265namespace std//Define things to allow use within std libs
266{
267 template <>
268 struct hash<NDEVR::UUID>
269 {
270 std::size_t operator()(const NDEVR::UUID& s) const noexcept
271 {
272 std::size_t value = 0;
273 for (NDEVR::uint01 i = 0; i < 8; i++)
274 {
275 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
276 }
277 return value;
278 }
279 };
280};
281#ifdef _MSC_VER
282 //Used to help debugging
283 namespace natvis
284 {
285 struct x4lo { unsigned __int8 v : 4; unsigned __int8 _ : 4; }; // NOLINT(clang-diagnostic-language-extension-token)
286 struct x4hi { unsigned __int8 _ : 4; unsigned __int8 v : 4; }; // NOLINT(clang-diagnostic-language-extension-token)
287 struct x8 { unsigned __int8 _; }; // NOLINT(clang-diagnostic-language-extension-token)
288 struct x32 { __int32 _; }; // NOLINT(clang-diagnostic-language-extension-token)
289 }
290#endif
#define NDEVR_BASE_API
Definition DLLInfo.h:78
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Color.h:36
Definition Pointer.hpp:62
Definition String.h:40
Definition UUID.h:66
constexpr size_t hash() const
Definition UUID.h:188
UUID(const uint04 &other) noexcept
Definition UUID.h:89
constexpr UUID()
Definition UUID.h:68
bool operator>=(const UUID &other) const
Definition UUID.h:231
UUID(const sint08 &other) noexcept
Definition UUID.h:114
UUID(const fltp04 &other) noexcept
Definition UUID.h:120
UUID(const bool &other) noexcept
Definition UUID.h:74
bool operator>(const UUID &other) const
Definition UUID.h:221
NDEVR_BASE_API uint01 * getUniquePointer() const
Definition UUID.cpp:25
UUID(const sint01 &other) noexcept
Definition UUID.h:99
UUID appendUUID(const Vector< t_size, t_type > &offset) const
Definition UUID.h:181
NDEVR_BASE_API UUID appendUUID(bool offset) const
Definition UUID.cpp:168
constexpr size_t operator()() const
Definition UUID.h:197
UUID(const sint02 &other) noexcept
Definition UUID.h:104
UUID(const sint04 &other) noexcept
Definition UUID.h:109
bool operator<=(const UUID &other) const
Definition UUID.h:211
constexpr UUID(const Vector< 16, uint01 > &bytes) noexcept
Definition UUID.h:71
bool operator<(const UUID &other) const
Definition UUID.h:201
UUID(const uint08 &other) noexcept
Definition UUID.h:94
UUID(const uint01 &other) noexcept
Definition UUID.h:79
static NDEVR_BASE_API UUID CreateUUID()
Definition UUID.cpp:150
static NDEVR_BASE_API constexpr UUID CreateUUID(const char *identifier)
Definition UUID.h:158
UUID(const fltp08 &other) noexcept
Definition UUID.h:125
UUID(const uint02 &other) noexcept
Definition UUID.h:84
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
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:76
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
Definition BaseValues.hpp:86
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
int8_t sint01
-Defines an alias representing a 1 byte, signed integer. -Can represent exact integer values -127 thr...
Definition BaseValues.hpp:56
int16_t sint02
-Defines an alias representing a 2 byte, signed integer. -Can represent exact integer values -32767 t...
Definition BaseValues.hpp:66
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:109
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition File.h:213
Definition BaseValues.hpp:272
static constexpr ObjectInfo< uint01, false, false > VectorSub()
Definition UUID.h:259
Information about the object.
Definition ObjectInfo.h:56
std::size_t operator()(const NDEVR::UUID &s) const noexcept
Definition UUID.h:270