11 #if defined(__MSYS__) || defined(_WIN32) || defined(_WIN64)
13 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
14 #include <uuid/uuid.h>
22 uint8_t unhex(
char ch)
24 if ((ch >=
'0') && (ch <=
'9'))
26 else if ((ch >=
'a') && (ch <=
'f'))
28 else if ((ch >=
'A') && (ch <=
'F'))
47 if ((ch ==
'-') || (ch ==
'{') || (ch ==
'}'))
54 uint8_t ui1 = Internals::unhex(v1);
55 uint8_t ui2 = Internals::unhex(v2);
56 if ((ui1 > 15) || (ui2 > 15))
58 _data[index++] = ui1 * 16 + ui2;
70 for (; index < 16; ++index)
76 const char* digits =
"0123456789abcdef";
78 std::string result(36,
'0');
81 for (
auto value :
_data)
83 result[index++] = digits[(value >> 4) & 0x0F];
84 result[index++] = digits[(value >> 0) & 0x0F];
85 if ((index == 8) || (index == 13) || (index == 18) || (index == 23))
86 result[index++] =
'-';
95 #if defined(__MSYS__) || defined(_WIN32) || defined(_WIN64)
97 if (UuidCreateSequential(&uuid) != RPC_S_OK)
100 result.
_data[0] = (uuid.Data1 >> 24) & 0xFF;
101 result.
_data[1] = (uuid.Data1 >> 16) & 0xFF;
102 result.
_data[2] = (uuid.Data1 >> 8) & 0xFF;
103 result.
_data[3] = (uuid.Data1 >> 0) & 0xFF;
105 result.
_data[4] = (uuid.Data2 >> 8) & 0xFF;
106 result.
_data[5] = (uuid.Data2 >> 0) & 0xFF;
108 result.
_data[6] = (uuid.Data3 >> 8) & 0xFF;
109 result.
_data[7] = (uuid.Data3 >> 0) & 0xFF;
111 result.
_data[8] = uuid.Data4[0];
112 result.
_data[9] = uuid.Data4[1];
114 result.
_data[10] = uuid.Data4[2];
115 result.
_data[11] = uuid.Data4[3];
116 result.
_data[12] = uuid.Data4[4];
117 result.
_data[13] = uuid.Data4[5];
118 result.
_data[14] = uuid.Data4[6];
119 result.
_data[15] = uuid.Data4[7];
120 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
122 uuid_generate_time(uuid);
124 result.
_data[0] = uuid[0];
125 result.
_data[1] = uuid[1];
126 result.
_data[2] = uuid[2];
127 result.
_data[3] = uuid[3];
129 result.
_data[4] = uuid[4];
130 result.
_data[5] = uuid[5];
132 result.
_data[6] = uuid[6];
133 result.
_data[7] = uuid[7];
135 result.
_data[8] = uuid[8];
136 result.
_data[9] = uuid[9];
138 result.
_data[10] = uuid[10];
139 result.
_data[11] = uuid[11];
140 result.
_data[12] = uuid[12];
141 result.
_data[13] = uuid[13];
142 result.
_data[14] = uuid[14];
143 result.
_data[15] = uuid[15];
151 #if defined(__MSYS__) || defined(_WIN32) || defined(_WIN64)
153 if (UuidCreate(&uuid) != RPC_S_OK)
156 result.
_data[0] = (uuid.Data1 >> 24) & 0xFF;
157 result.
_data[1] = (uuid.Data1 >> 16) & 0xFF;
158 result.
_data[2] = (uuid.Data1 >> 8) & 0xFF;
159 result.
_data[3] = (uuid.Data1 >> 0) & 0xFF;
161 result.
_data[4] = (uuid.Data2 >> 8) & 0xFF;
162 result.
_data[5] = (uuid.Data2 >> 0) & 0xFF;
164 result.
_data[6] = (uuid.Data3 >> 8) & 0xFF;
165 result.
_data[7] = (uuid.Data3 >> 0) & 0xFF;
167 result.
_data[8] = uuid.Data4[0];
168 result.
_data[9] = uuid.Data4[1];
170 result.
_data[10] = uuid.Data4[2];
171 result.
_data[11] = uuid.Data4[3];
172 result.
_data[12] = uuid.Data4[4];
173 result.
_data[13] = uuid.Data4[5];
174 result.
_data[14] = uuid.Data4[6];
175 result.
_data[15] = uuid.Data4[7];
176 #elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
178 uuid_generate_random(uuid);
180 result.
_data[0] = uuid[0];
181 result.
_data[1] = uuid[1];
182 result.
_data[2] = uuid[2];
183 result.
_data[3] = uuid[3];
185 result.
_data[4] = uuid[4];
186 result.
_data[5] = uuid[5];
188 result.
_data[6] = uuid[6];
189 result.
_data[7] = uuid[7];
191 result.
_data[8] = uuid[8];
192 result.
_data[9] = uuid[9];
194 result.
_data[10] = uuid[10];
195 result.
_data[11] = uuid[11];
196 result.
_data[12] = uuid[12];
197 result.
_data[13] = uuid[13];
198 result.
_data[14] = uuid[14];
199 result.
_data[15] = uuid[15];
208 swap(_data, uuid._data);
231 std::hash<uint8_t> hasher;
232 for (
size_t i = 0; i <
value.data().size(); ++i)
233 result = result * 31 + hasher(
value.data()[i]);
Universally unique identifier (UUID)
UUID()
Default constructor.
void swap(UUID &uuid) noexcept
Swap two instances.
static UUID Random()
Generate random UUID4 (randomly or pseudo-randomly generated version)
static UUID Sequential()
Generate sequential UUID1 (time based version)
std::string string() const
Get string from the current UUID in format "00000000-0000-0000-0000-000000000000".
std::array< uint8_t, 16 > _data
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void swap(UUID &uuid1, UUID &uuid2) noexcept
Universally unique identifier (UUID) definition.