14 inline constexpr uint8_t unhex(
char ch)
16 if ((ch >=
'0') && (ch <=
'9'))
18 else if ((ch >=
'a') && (ch <=
'f'))
20 else if ((ch >=
'A') && (ch <=
'F'))
23 throwex DomainException(
"Invalid UUID character");
29 inline constexpr
UUID::UUID(
const char* uuid,
size_t size)
37 for (
size_t i = 0; i < size; ++i)
40 if ((ch ==
'-') || (ch ==
'{') || (ch ==
'}'))
47 uint8_t ui1 = Internals::unhex(v1);
48 uint8_t ui2 = Internals::unhex(v2);
49 if ((ui1 > 15) || (ui2 > 15))
51 _data[index++] = ui1 * 16 + ui2;
63 for (; index < 16; ++index)
70 swap(_data, uuid._data);
80 #if defined(FMT_VERSION)
82 struct fmt::formatter<
CppCommon::UUID> : formatter<std::string_view>
84 template <
typename FormatContext>
97 typedef size_t result_type;
99 result_type operator() (
const argument_type& value)
const
101 result_type result = 17;
102 std::hash<uint8_t> hasher;
103 for (
size_t i = 0; i < value.data().size(); ++i)
104 result = result * 31 + hasher(value.data()[i]);
Universally unique identifier (UUID)
std::string string() const
Get string from the current UUID in format "00000000-0000-0000-0000-000000000000".
void swap(UUID &uuid) noexcept
Swap two instances.
constexpr UUID()
Default constructor.
#define throwex
Throw extended exception macro.
C++ Common project definitions.
std::string format(fmt::format_string< T... > pattern, T &&... args)
Format string.
void swap(FileCache &cache1, FileCache &cache2) noexcept
void swap(UUID &uuid1, UUID &uuid2) noexcept