26 typedef uint8_t value_type;
27 typedef uint8_t& reference;
28 typedef uint8_t
const& const_reference;
29 typedef uint8_t* iterator;
30 typedef uint8_t
const* const_iterator;
31 typedef std::size_t size_type;
32 typedef std::ptrdiff_t difference_type;
34 static constexpr size_type static_size()
noexcept {
return 16; }
37 constexpr uuid() noexcept
42 constexpr uuid(
const uuid& other) noexcept
43 : data{other.data[0], other.data[1], other.data[2], other.data[3],
44 other.data[4], other.data[5], other.data[6], other.data[7],
45 other.data[8], other.data[9], other.data[10], other.data[11],
46 other.data[12], other.data[13], other.data[14], other.data[15]}
50 constexpr uuid& operator=(
const uuid& other)
noexcept
52 for(
int i = 0; i < 16; i++)
53 data[i] = other.data[i];
57 constexpr uuid(
const uint8_t (&other)[16]) noexcept
58 : data{other[0], other[1], other[2], other[3], other[4], other[5],
59 other[6], other[7], other[8], other[9], other[10], other[11],
60 other[12], other[13], other[14], other[15]}
64 constexpr auto begin()
noexcept {
return &data[0]; }
65 constexpr auto end()
noexcept {
return &data[0] + 16; }
67 constexpr auto begin()
const noexcept {
return &data[0]; }
68 constexpr auto end()
const noexcept {
return &data[0] + 16; }
70 constexpr size_type size()
const noexcept {
return static_size(); }
72 constexpr bool is_nil()
const noexcept
74 for(std::size_t i = 0; i <
sizeof(data); ++i)
89 variant_type variant()
const noexcept
93 unsigned char octet7 = data[8];
94 if((octet7 & 0x80) == 0x00)
98 else if((octet7 & 0xC0) == 0x80)
100 return variant_rfc_4122;
102 else if((octet7 & 0xE0) == 0xC0)
104 return variant_microsoft;
109 return variant_future;
115 version_unknown = -1,
116 version_time_based = 1,
117 version_dce_security = 2,
118 version_name_based_md5 = 3,
119 version_random_number_based = 4,
120 version_name_based_sha1 = 5
122 version_type version()
const noexcept
126 uint8_t octet9 = data[6];
127 if((octet9 & 0xF0) == 0x10)
129 return version_time_based;
131 else if((octet9 & 0xF0) == 0x20)
133 return version_dce_security;
135 else if((octet9 & 0xF0) == 0x30)
137 return version_name_based_md5;
139 else if((octet9 & 0xF0) == 0x40)
141 return version_random_number_based;
143 else if((octet9 & 0xF0) == 0x50)
145 return version_name_based_sha1;
149 return version_unknown;
182 lhs.data, lhs.data + uuid::static_size(), rhs.data,
218 static constexpr uuid compute(
const char (&s)[N])
220 static_assert(N == 37,
"Invalid uuid");
221 return compute(s, s + N);
224 template <
typename CharIterator>
225 static constexpr uuid compute(CharIterator begin, CharIterator end)
230 bool has_dashes =
false;
234 for(
auto it_byte = u; it_byte != u + 16; ++it_byte, ++i)
243 has_dashes = is_dash(c);
252 if(i == 6 || i == 8 || i == 10)
260 throw std::runtime_error{
"Invalid uuid"};
264 auto res = get_value(c);
275 static constexpr unsigned char get_value(
char c)
318 throw std::runtime_error{
"Invalid uuid"};
322 static constexpr unsigned char get_value(QChar c) {
return get_value(c.toLatin1()); }
324 static constexpr bool is_dash(
char c) {
return c ==
'-'; }
325 static constexpr bool is_dash(QChar c) {
return c.toLatin1() ==
'-'; }