25#if defined(USE_UUID_CREATE)
27#elif defined(USE_CFUUID)
28# include <CoreFoundation/CFUUID.h>
29#elif defined(USE_LIBUUID)
45 std::string::const_iterator& inputIt,
46 const std::string::const_iterator& inputEnd)
48 if (inputIt == inputEnd)
51 const char c1 = *inputIt++;
53 if (!std::isxdigit(c1))
56 if (inputIt == inputEnd)
59 const char c2 = *inputIt++;
61 if (!std::isxdigit(c2))
84#if defined(USE_UUID_CREATE)
87 if (RPC_S_OK != ::UuidCreate(&winUid))
92 std::memcpy(uuid.
mData.data(), &winUid,
sizeof(winUid));
95#elif defined(USE_CFUUID)
96 CFUUIDBytes bytes = CFUUIDGetUUIDBytes(
97 CF_ptr<CFUUIDRef>{ CFUUIDCreate(NULL) }.get());
101 std::memcpy(uuid.
mData.data(), &bytes,
sizeof(bytes));
104#elif defined(USE_LIBUUID)
107 uuid_generate(newId);
111 std::memcpy(uuid.
mData.data(), newId,
sizeof(newId));
115# error "UUID generator is not defined"
121 const size_t length =
str.length();
126 const bool hasBraces =
str[0] ==
'{';
133 const unsigned int iteratorOffset = hasBraces ? 1 : 0;
135 std::string::const_iterator currentSymbol =
str.begin() + iteratorOffset;
136 std::string::const_iterator inputEnd =
str.end() - iteratorOffset;
139 Bytes::iterator currentByte = uuid.
mData.begin();
141 for (
int i = 0; i < 16; ++i)
143 if (!
readByte(currentByte, currentSymbol, inputEnd))
146 if (currentSymbol != inputEnd && *currentSymbol ==
'-')
155 return std::all_of(
mData.begin(),
mData.end(),
156 [](uint8_t c) { return c == 0; });
159Uuid::operator bool() const noexcept
166 return mData == rhs.mData;
171 return mData != rhs.mData;
176 return mData > rhs.mData;
181 return mData >= rhs.mData;
186 return mData < rhs.mData;
191 return mData <= rhs.mData;
203 const int bytesWritten = snprintf(
204 buffer,
sizeof(buffer),
205 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
219 const int bytesWritten = snprintf(
220 buffer,
sizeof(buffer),
221 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
246 enum :
unsigned long long
248 Value = 0x9e3779b97f4a7c15ULL
254 const std::hash<uint8_t> hasher;
256 constexpr std::size_t goldenRatio =
GoldenRatio<
sizeof(std::size_t)>::Value;
258 std::size_t seed = ~0;
260 for (uint8_t
byte :
mData)
262 seed ^= hasher(seed) + goldenRatio + (seed << 6) + (seed >> 2);
Wrap resource pointers from Apple Core SDK for RAII.
Define helper functions for hex-to-num conversion.
Declare a class to generate and parse UUIDs.
Utility class that generates and parses UUIDs.
static Uuid Generate()
Generate a new UUID.
bool operator!=(const Uuid &other) const noexcept
bool operator<=(const Uuid &other) const noexcept
std::size_t GetHash() const noexcept
bool operator>=(const Uuid &other) const noexcept
bool operator>(const Uuid &other) const noexcept
bool IsNil() const noexcept
Checks, if the UUID is nil.
Uuid()
Creates a nil UUID.
std::string ToString() const
Get a string in the xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.
bool operator==(const Uuid &other) const noexcept
bool operator<(const Uuid &other) const noexcept
std::string ToHexString() const
Get a string in the xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx format.
const Bytes & ToBytes() const noexcept
Get the 16 bytes long array with the raw UUID data.
static Uuid FromString(const std::string &str)
std::array< uint8_t, 16 > Bytes
bool readByte(Uuid::Bytes::iterator &outputIt, std::string::const_iterator &inputIt, const std::string::const_iterator &inputEnd)
constexpr int BRACED_UUID_LENGTH
constexpr int HEX_UUID_LENGTH
constexpr int UUID_LENGTH
uint8_t HexCharToNum(char c) noexcept