2 #include <score/serialization/VisitorInterface.hpp>
6 #include <score_lib_base_export.h>
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;
158 constexpr
inline bool operator==(
uuid const& lhs,
uuid const& rhs) noexcept
160 for(std::size_t i = 0; i < uuid::static_size(); ++i)
162 if(lhs.data[i] != rhs.data[i])
168 constexpr
inline bool operator!=(uuid
const& lhs, uuid
const& rhs) noexcept
170 return !(lhs == rhs);
173 #if __cpp_lib_constexpr_algorithms >= 201806L
174 #define constexpr_algorithm constexpr
176 #define constexpr_algorithm
179 constexpr_algorithm
inline bool operator<(uuid
const& lhs, uuid
const& rhs) noexcept
181 return std::lexicographical_compare(
182 lhs.data, lhs.data + uuid::static_size(), rhs.data,
183 rhs.data + uuid::static_size());
186 constexpr_algorithm
inline bool operator>(uuid
const& lhs, uuid
const& rhs) noexcept
191 constexpr_algorithm
inline bool operator<=(uuid
const& lhs, uuid
const& rhs) noexcept
196 constexpr_algorithm
inline bool operator>=(uuid
const& lhs, uuid
const& rhs) noexcept
202 constexpr
inline std::size_t hash_value(uuid
const& u) noexcept
204 std::size_t seed = 0;
205 for(uuid::const_iterator i = u.begin(), e = u.end(); i != e; ++i)
207 seed ^=
static_cast<std::size_t
>(*i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
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() ==
'-'; }
334 #define return_uuid(text) \
337 constexpr const auto t = score::uuids::string_generator::compute((text)); \
341 template <
typename Tag>
366 constexpr
UuidKey() noexcept =
default;
369 constexpr
UuidKey& operator=(
const UuidKey& other) noexcept =
default;
378 explicit constexpr
UuidKey(
const char (&txt)[N])
379 :
score::uuid_t(score::uuids::string_generator::compute<N>(txt))
383 template <
typename Iterator>
385 :
score::uuid_t(score::uuids::string_generator::compute(beg_it, end_it))
389 constexpr
static UuidKey fromString(
const std::string& str)
391 return UuidKey{str.begin(), str.end()};
394 constexpr
static UuidKey fromString(
const QString& str)
396 return UuidKey{str.begin(), str.end()};
399 constexpr
const score::uuid_t& impl()
const {
return *
this; }
405 template <
typename T>
408 constexpr std::size_t operator()(
const UuidKey<T>& kagi)
const noexcept
410 return score::uuids::hash_value(kagi.impl());
415 #include <score/serialization/VisitorInterface.hpp>
417 struct is_custom_serialized<
score::uuid_t> : std::true_type
429 template <
typename U>
450 template <
typename U>
Definition: VisitorInterface.hpp:53
Definition: DataStreamVisitor.hpp:27
Definition: DataStreamVisitor.hpp:202
Definition: VisitorInterface.hpp:61
Definition: JSONVisitor.hpp:52
Definition: JSONVisitor.hpp:423
Definition: UuidKey.hpp:343
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: lv2_atom_helpers.hpp:99
Definition: VisitorInterface.hpp:13
Definition: UuidKey.hpp:214
Definition: UuidKey.hpp:24