13 #if defined(__MSYS__) || defined(_WIN32) || defined(_WIN64)
16 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
17 #include <uuid/uuid.h>
24 const char* digits =
"0123456789abcdef";
26 std::string result(36,
'0');
29 for (
auto value : _data)
31 result[index++] = digits[(value >> 4) & 0x0F];
32 result[index++] = digits[(value >> 0) & 0x0F];
33 if ((index == 8) || (index == 13) || (index == 18) || (index == 23))
34 result[index++] =
'-';
43 #if defined(__MSYS__) || defined(_WIN32) || defined(_WIN64)
45 if (UuidCreateSequential(&uuid) != RPC_S_OK)
48 result._data[0] = (uuid.Data1 >> 24) & 0xFF;
49 result._data[1] = (uuid.Data1 >> 16) & 0xFF;
50 result._data[2] = (uuid.Data1 >> 8) & 0xFF;
51 result._data[3] = (uuid.Data1 >> 0) & 0xFF;
53 result._data[4] = (uuid.Data2 >> 8) & 0xFF;
54 result._data[5] = (uuid.Data2 >> 0) & 0xFF;
56 result._data[6] = (uuid.Data3 >> 8) & 0xFF;
57 result._data[7] = (uuid.Data3 >> 0) & 0xFF;
59 result._data[8] = uuid.Data4[0];
60 result._data[9] = uuid.Data4[1];
62 result._data[10] = uuid.Data4[2];
63 result._data[11] = uuid.Data4[3];
64 result._data[12] = uuid.Data4[4];
65 result._data[13] = uuid.Data4[5];
66 result._data[14] = uuid.Data4[6];
67 result._data[15] = uuid.Data4[7];
68 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
70 uuid_generate_time(uuid);
72 result._data[0] = uuid[0];
73 result._data[1] = uuid[1];
74 result._data[2] = uuid[2];
75 result._data[3] = uuid[3];
77 result._data[4] = uuid[4];
78 result._data[5] = uuid[5];
80 result._data[6] = uuid[6];
81 result._data[7] = uuid[7];
83 result._data[8] = uuid[8];
84 result._data[9] = uuid[9];
86 result._data[10] = uuid[10];
87 result._data[11] = uuid[11];
88 result._data[12] = uuid[12];
89 result._data[13] = uuid[13];
90 result._data[14] = uuid[14];
91 result._data[15] = uuid[15];
99 #if defined(__MSYS__) || defined(_WIN32) || defined(_WIN64)
101 if (UuidCreate(&uuid) != RPC_S_OK)
104 result._data[0] = (uuid.Data1 >> 24) & 0xFF;
105 result._data[1] = (uuid.Data1 >> 16) & 0xFF;
106 result._data[2] = (uuid.Data1 >> 8) & 0xFF;
107 result._data[3] = (uuid.Data1 >> 0) & 0xFF;
109 result._data[4] = (uuid.Data2 >> 8) & 0xFF;
110 result._data[5] = (uuid.Data2 >> 0) & 0xFF;
112 result._data[6] = (uuid.Data3 >> 8) & 0xFF;
113 result._data[7] = (uuid.Data3 >> 0) & 0xFF;
115 result._data[8] = uuid.Data4[0];
116 result._data[9] = uuid.Data4[1];
118 result._data[10] = uuid.Data4[2];
119 result._data[11] = uuid.Data4[3];
120 result._data[12] = uuid.Data4[4];
121 result._data[13] = uuid.Data4[5];
122 result._data[14] = uuid.Data4[6];
123 result._data[15] = uuid.Data4[7];
124 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
126 uuid_generate_random(uuid);
128 result._data[0] = uuid[0];
129 result._data[1] = uuid[1];
130 result._data[2] = uuid[2];
131 result._data[3] = uuid[3];
133 result._data[4] = uuid[4];
134 result._data[5] = uuid[5];
136 result._data[6] = uuid[6];
137 result._data[7] = uuid[7];
139 result._data[8] = uuid[8];
140 result._data[9] = uuid[9];
142 result._data[10] = uuid[10];
143 result._data[11] = uuid[11];
144 result._data[12] = uuid[12];
145 result._data[13] = uuid[13];
146 result._data[14] = uuid[14];
147 result._data[15] = uuid[15];
static void CryptoFill(void *buffer, size_t size)
Fill the given memory buffer with cryptographic strong random bytes.
Universally unique identifier (UUID)
std::string string() const
Get string from the current UUID in format "00000000-0000-0000-0000-000000000000".
static UUID Random()
Generate random UUID4 (randomly or pseudo-randomly generated version)
static UUID Sequential()
Generate sequential UUID1 (time based version)
static UUID Secure()
Generate secure UUID4 (secure generated version)
#define throwex
Throw extended exception macro.
Memory management definition.
C++ Common project definitions.
Universally unique identifier (UUID) definition.