NDEVR
API Documentation
UUID.h
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/BufferBase.h>
36#include <NDEVR/StringView.h>
37namespace NDEVR
38{
39 class StringView;
59
60 class UUID : public Vector<16, uint01>
61 {
62 public:
66 constexpr UUID()
67 : Vector<16, uint01>(Constant<uint01>::Invalid)
68 {}
69
74 constexpr explicit UUID(const Vector<16, uint01>& bytes) noexcept
75 : Vector<16, uint01>(bytes)
76 {}
77
82 explicit UUID(const uint01& other) noexcept
83 : Vector<16, uint01>(0)
84 {
85 *this = appendUUID(other);
86 }
87
92 explicit UUID(const uint02& other) noexcept
93 : Vector<16, uint01>(0)
94 {
95 *this = appendUUID(other);
96 }
97
102 explicit UUID(const uint04& other) noexcept
103 : Vector<16, uint01>(0)
104 {
105 *this = appendUUID(other);
106 }
107
112 explicit UUID(const uint08& other) noexcept
113 : Vector<16, uint01>(0)
114 {
115 *this = appendUUID(other);
116 }
117
122 explicit UUID(const sint01& other) noexcept
123 : Vector<16, uint01>(0)
124 {
125 *this = appendUUID(other);
126 }
127
132 explicit UUID(const sint02& other) noexcept
133 : Vector<16, uint01>(0)
134 {
135 *this = appendUUID(other);
136 }
137
142 explicit UUID(const sint04& other) noexcept
143 : Vector<16, uint01>(0)
144 {
145 *this = appendUUID(other);
146 }
147
152 explicit UUID(const sint08& other) noexcept
153 : Vector<16, uint01>(0)
154 {
155 *this = appendUUID(other);
156 }
157
162 explicit UUID(const fltp04& other) noexcept
163 : Vector<16, uint01>(0)
164 {
165 *this = appendUUID(other);
166 }
167
172 explicit UUID(const fltp08& other) noexcept
173 : Vector<16, uint01>(0)
174 {
175 *this = appendUUID(other);
176 }
177
187
188 NDEVR_BASE_API uint01* getUniquePointer() const;
189
199
200 NDEVR_BASE_API static UUID CreateUUID();
201
208 NDEVR_BASE_API static constexpr UUID CreateUUID(const StringView& identifier)
209 {
210 UUID id = UUID(Constant<Vector<16, uint01>>::Invalid);
211 uint01 i = 0;
212 for (uint04 n = 0; n < identifier.size(); n++)
213 {
214 id[i] = id[i] ^ identifier[n];
215 i = (i + 1) % 16;
216 }
217 return id;
218 }
219
225 [[nodiscard]] NDEVR_BASE_API UUID appendBoolUUID(bool offset) const;
226
232 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const StringView& identifier) const;
233
239 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(uint04 offset) const;
240
246 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(uint08 offset) const;
247
253 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(sint04 offset) const;
254
260 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(sint08 offset) const;
261
267 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(fltp04 offset) const;
268
274 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const Vector<3, fltp04>& offset) const;
275
281 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(fltp08 offset) const;
282
288 [[nodiscard]] NDEVR_BASE_API UUID appendUUID(const UUID& offset) const;
289
295 template<uint01 t_size, class t_type>
296 [[nodiscard]] UUID appendUUID(const Vector<t_size, t_type>& offset) const
297 {
298 UUID id(*this);
299 for (uint01 i = 0; i < t_size; i++)
300 id = id.appendUUID(offset[i]);
301 return id;
302 }
303
309 template<size_t t_size, class t_type>
310 [[nodiscard]] UUID appendUUID(const t_type(&value)[t_size])
311 {
312 UUID id(*this);
313 for (uint01 i = 0; i < t_size; i++)
314 id = id.appendUUID(value[i]);
315 return id;
316 }
317
323 template<size_t t_size>
324 [[nodiscard]] UUID appendUUID(const char(&value)[t_size])
325 {
326 return appendUUID(StringView(value));
327 }
328
333 constexpr size_t hash() const
334 {
335 std::size_t value = 0;
336 for (uint01 i = 0; i < 8; i++)
337 {
338 value = value * 256 + ((*this)[i + 0] ^ (*this)[i + 8]);
339 }
340 return value;
341 }
342
347 constexpr size_t operator()() const
348 {
349 return hash();
350 }
351
357 bool operator<(const UUID& other) const
358 {
359 for (uint01 i = 0; i < 16; i++)
360 {
361 if ((*this)[i] == other[i])
362 continue;
363 return (*this)[i] < other[i];
364 }
365 return false;
366 }
367
373 bool operator<=(const UUID& other) const
374 {
375 for (uint01 i = 0; i < 16; i++)
376 {
377 if ((*this)[i] == other[i])
378 continue;
379 return (*this)[i] < other[i];
380 }
381 return true;
382 }
383
389 bool operator>(const UUID& other) const
390 {
391 for (uint01 i = 0; i < 16; i++)
392 {
393 if ((*this)[i] == other[i])
394 continue;
395 return (*this)[i] > other[i];
396 }
397 return false;
398 }
399
405 bool operator>=(const UUID& other) const
406 {
407 for (uint01 i = 0; i < 16; i++)
408 {
409 if ((*this)[i] == other[i])
410 continue;
411 return (*this)[i] > other[i];
412 }
413 return true;
414 }
415 };
416
421 template<>
422 struct ObjectInfo<UUID, true, false>
423 {
424 static const uint01 Dimensions = 16;
425 static const bool Vector = true;
426 static const bool Buffer = false;
427 static const bool Primitive = true;
428 static const bool Pointer = false;
429 static const bool Unsigned = false;
430 static const bool Float = false;
431 static const bool Integer = false;
432 static const bool Number = false;
433 static const bool Enum = false;
434 static const bool String = true;
435 static const bool Color = false;
436 static const bool Boolean = false;
437
443 };
444 template<> constexpr const UUID Constant<UUID>::Invalid = UUID(Constant<Vector<16, uint01>>::Invalid);
445 template<> constexpr const UUID Constant<UUID>::Max = UUID(Constant<Vector<16, uint01>>::Max);
446 template<> constexpr const UUID Constant<UUID>::Min = UUID(Constant<Vector<16, uint01>>::Min);
447}
448namespace std//Define things to allow use within std libs
449{
454 template <>
455 struct hash<NDEVR::UUID>
456 {
462 std::size_t operator()(const UUID& s) const noexcept
463 {
464 std::size_t value = 0;
465 for (uint01 i = 0; i < 8; i++)
466 {
467 value = value * 256 + (s[i + 0U] ^ s[i + 8U]);
468 }
469 return value;
470 }
471 };
472};
473#ifdef _MSC_VER
474 //Used to help debugging
478 namespace natvis
479 {
480 struct x4lo { unsigned __int8 v : 4; unsigned __int8 _ : 4; };
481 struct x4hi { unsigned __int8 _ : 4; unsigned __int8 v : 4; };
482 struct x8 { unsigned __int8 _; };
483 struct x32 { __int32 _; };
484 }
485#endif
The core String View class for the NDEVR API.
Definition StringView.h:58
constexpr uint04 size() const
Returns the byte size of this string view.
Definition StringView.h:435
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
UUID(const sint08 &other) noexcept
Constructs a UUID by appending a sint08 value to a zero-initialized UUID.
Definition UUID.h:152
UUID appendUUID(sint08 offset) const
Appends a sint08 value to this UUID, producing a new derived UUID.
UUID(const uint04 &other) noexcept
Constructs a UUID by appending a uint04 value to a zero-initialized UUID.
Definition UUID.h:102
bool operator<(const UUID &other) const
Less-than comparison operator using lexicographic byte ordering.
Definition UUID.h:357
constexpr UUID()
Constructs an invalid (default) UUID with all bytes set to the invalid constant.
Definition UUID.h:66
UUID(const sint02 &other) noexcept
Constructs a UUID by appending a sint02 value to a zero-initialized UUID.
Definition UUID.h:132
UUID appendUUID(uint04 offset) const
Appends a uint04 value to this UUID, producing a new derived UUID.
UUID(const sint01 &other) noexcept
Constructs a UUID by appending a sint01 value to a zero-initialized UUID.
Definition UUID.h:122
constexpr size_t hash() const
Computes a hash value for this UUID by XOR-folding the upper and lower 8 bytes.
Definition UUID.h:333
UUID(const fltp04 &other) noexcept
Constructs a UUID by appending a fltp04 value to a zero-initialized UUID.
Definition UUID.h:162
static constexpr UUID CreateUUID(const StringView &identifier)
Creates a deterministic UUID from a string identifier by XOR-folding its characters into the 16-byte ...
Definition UUID.h:208
UUID appendBoolUUID(bool offset) const
Appends a boolean value to this UUID, producing a new derived UUID.
uint01 * getUniquePointer() const
constexpr UUID(const Vector< 16, uint01 > &bytes) noexcept
Constructs a UUID from a raw 16-byte vector.
Definition UUID.h:74
UUID(const uint08 &other) noexcept
Constructs a UUID by appending a uint08 value to a zero-initialized UUID.
Definition UUID.h:112
UUID(const uint01 &other) noexcept
Constructs a UUID by appending a uint01 value to a zero-initialized UUID.
Definition UUID.h:82
UUID appendUUID(const Vector< t_size, t_type > &offset) const
Appends each element of a vector to this UUID sequentially, producing a new derived UUID.
Definition UUID.h:296
UUID appendUUID(uint08 offset) const
Appends a uint08 value to this UUID, producing a new derived UUID.
UUID(const uint02 &other) noexcept
Constructs a UUID by appending a uint02 value to a zero-initialized UUID.
Definition UUID.h:92
UUID appendUUID(const char(&value)[t_size])
Appends a string literal to this UUID by converting it to a StringView first.
Definition UUID.h:324
UUID appendUUID(const Vector< 3, fltp04 > &offset) const
Appends a 3D float vector to this UUID, producing a new derived UUID.
UUID appendUUID(const UUID &offset) const
Appends another UUID to this UUID, producing a new derived UUID.
constexpr size_t operator()() const
Function call operator that returns the hash of this UUID.
Definition UUID.h:347
UUID appendUUID(sint04 offset) const
Appends a sint04 value to this UUID, producing a new derived UUID.
bool operator<=(const UUID &other) const
Less-than-or-equal comparison operator using lexicographic byte ordering.
Definition UUID.h:373
UUID(const fltp08 &other) noexcept
Constructs a UUID by appending a fltp08 value to a zero-initialized UUID.
Definition UUID.h:172
UUID appendUUID(fltp08 offset) const
Appends a fltp08 value to this UUID, producing a new derived UUID.
UUID appendUUID(const t_type(&value)[t_size])
Appends each element of a C-style array to this UUID sequentially, producing a new derived UUID.
Definition UUID.h:310
UUID(const sint04 &other) noexcept
Constructs a UUID by appending a sint04 value to a zero-initialized UUID.
Definition UUID.h:142
UUID appendUUID(fltp04 offset) const
Appends a fltp04 value to this UUID, producing a new derived UUID.
UUID appendUUID(const StringView &identifier) const
Appends a string identifier to this UUID, producing a new derived UUID.
bool operator>(const UUID &other) const
Greater-than comparison operator using lexicographic byte ordering.
Definition UUID.h:389
bool operator>=(const UUID &other) const
Greater-than-or-equal comparison operator using lexicographic byte ordering.
Definition UUID.h:405
static UUID CreateUUID()
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
int16_t sint02
-Defines an alias representing a 2 byte, signed integer.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
int8_t sint01
-Defines an alias representing a 1 byte, signed integer.
int64_t sint08
-Defines an alias representing an 8 byte, signed integer -Can represent exact integer values -9223372...
STL namespace.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
static const bool Primitive
Whether this type is a primitive type.
Definition UUID.h:427
static const bool Pointer
Whether this type is a pointer type.
Definition UUID.h:428
static const bool String
Whether this type has string-like behavior.
Definition UUID.h:434
static const bool Number
Whether this type is a numeric type.
Definition UUID.h:432
static const bool Boolean
Whether this type is a boolean.
Definition UUID.h:436
static const bool Unsigned
Whether this type is unsigned.
Definition UUID.h:429
static constexpr ObjectInfo< uint01, false, false > VectorSub()
Returns the ObjectInfo for the underlying uint01 vector element type.
Definition UUID.h:442
static const bool Vector
Whether this type is a vector type.
Definition UUID.h:425
static const bool Enum
Whether this type is an enumeration.
Definition UUID.h:433
static const bool Buffer
Whether this type is a buffer type.
Definition UUID.h:426
static const bool Integer
Whether this type is an integer type.
Definition UUID.h:431
static const bool Float
Whether this type is a floating-point type.
Definition UUID.h:430
static const uint01 Dimensions
Number of byte dimensions in the UUID.
Definition UUID.h:424
static const bool Color
Whether this type represents a color.
Definition UUID.h:435
Information about the object.
Definition ObjectInfo.h:55