26 friend struct std::hash<
uuid>;
27 typedef uint8_t value_type;
28 typedef uint8_t& reference;
29 typedef uint8_t
const& const_reference;
30 typedef uint8_t* iterator;
31 typedef uint8_t
const* const_iterator;
32 typedef std::size_t size_type;
33 typedef std::ptrdiff_t difference_type;
35 static constexpr size_type static_size()
noexcept {
return 16; }
38 constexpr uuid() noexcept
43 constexpr uuid(
const uuid& other) noexcept
44 : data{other.data[0], other.data[1], other.data[2], other.data[3],
45 other.data[4], other.data[5], other.data[6], other.data[7],
46 other.data[8], other.data[9], other.data[10], other.data[11],
47 other.data[12], other.data[13], other.data[14], other.data[15]}
51 constexpr uuid& operator=(
const uuid& other)
noexcept
53 for(
int i = 0; i < 16; i++)
54 data[i] = other.data[i];
58 constexpr uuid(
const uint8_t (&other)[16]) noexcept
59 : data{other[0], other[1], other[2], other[3], other[4], other[5],
60 other[6], other[7], other[8], other[9], other[10], other[11],
61 other[12], other[13], other[14], other[15]}
65 constexpr auto begin()
noexcept {
return &data[0]; }
66 constexpr auto end()
noexcept {
return &data[0] + 16; }
68 constexpr auto begin()
const noexcept {
return &data[0]; }
69 constexpr auto end()
const noexcept {
return &data[0] + 16; }
71 constexpr size_type size()
const noexcept {
return static_size(); }
73 constexpr bool is_nil()
const noexcept
75 for(std::size_t i = 0; i <
sizeof(data); ++i)
90 variant_type variant()
const noexcept
94 unsigned char octet7 = data[8];
95 if((octet7 & 0x80) == 0x00)
99 else if((octet7 & 0xC0) == 0x80)
101 return variant_rfc_4122;
103 else if((octet7 & 0xE0) == 0xC0)
105 return variant_microsoft;
110 return variant_future;
116 version_unknown = -1,
117 version_time_based = 1,
118 version_dce_security = 2,
119 version_name_based_md5 = 3,
120 version_random_number_based = 4,
121 version_name_based_sha1 = 5
123 version_type version()
const noexcept
127 uint8_t octet9 = data[6];
128 if((octet9 & 0xF0) == 0x10)
130 return version_time_based;
132 else if((octet9 & 0xF0) == 0x20)
134 return version_dce_security;
136 else if((octet9 & 0xF0) == 0x30)
138 return version_name_based_md5;
140 else if((octet9 & 0xF0) == 0x40)
142 return version_random_number_based;
144 else if((octet9 & 0xF0) == 0x50)
146 return version_name_based_sha1;
150 return version_unknown;
183 lhs.data, lhs.data + uuid::static_size(), rhs.data,
220 static constexpr uuid compute(
const char (&s)[N])
222 static_assert(N == 37,
"Invalid uuid");
223 return compute(s, s + N);
226 template <
typename CharIterator>
227 static constexpr uuid compute(CharIterator begin, CharIterator end)
232 bool has_dashes =
false;
236 for(
auto it_byte = u; it_byte != u + 16; ++it_byte, ++i)
245 has_dashes = is_dash(c);
254 if(i == 6 || i == 8 || i == 10)
262 throw std::runtime_error{
"Invalid uuid"};
266 auto res = get_value(c);
277 static constexpr unsigned char get_value(
char c)
320 throw std::runtime_error{
"Invalid uuid"};
324 static constexpr unsigned char get_value(QChar c) {
return get_value(c.toLatin1()); }
326 static constexpr bool is_dash(
char c) {
return c ==
'-'; }
327 static constexpr bool is_dash(QChar c) {
return c.toLatin1() ==
'-'; }