77 #include <string_view>
78 #include <type_traits>
104 static constexpr
size_t kByteSize = 16U;
109 static constexpr
size_t kStringSize = 36U;
145 constexpr explicit
Uuid(const std::array<
value_type, kByteSize>& data) noexcept;
152 constexpr explicit
Uuid(const
value_type (&arr)[kByteSize]) noexcept;
166 template <typename ForwardIteratorT>
167 Uuid(ForwardIteratorT first, ForwardIteratorT last);
174 [[nodiscard]] constexpr
Variant variant() const noexcept;
181 [[nodiscard]] constexpr
Version version() const noexcept;
188 [[nodiscard]] constexpr
bool is_nil() const noexcept;
195 [[nodiscard]] constexpr const std::array<
value_type, kByteSize>& bytes() const noexcept;
202 [[nodiscard]] std::
string to_string() const noexcept;
209 [[nodiscard]] std::
string to_compact_string() const noexcept;
229 [[nodiscard]] static
bool is_valid(std::string_view str) noexcept;
237 [[nodiscard]] static
bool is_valid(const
char* str) noexcept;
248 [[nodiscard]] static std::optional<
Uuid> from_string(std::string_view str) noexcept;
256 [[nodiscard]] static std::optional<
Uuid> from_string(const
char* str) noexcept;
268 [[nodiscard]] static
Uuid generate_random() noexcept;
280 [[nodiscard]] static
Uuid generate_random(std::mt19937& engine) noexcept;
300 [[nodiscard]] static std::vector<
value_type> random_bytes(
size_t count) noexcept;
314 [[nodiscard]] static std::
string random_hex(
size_t byte_count = 16U) noexcept;
323 friend
bool operator==(const
Uuid& lhs, const
Uuid& rhs) noexcept;
332 friend
bool operator!=(const
Uuid& lhs, const
Uuid& rhs) noexcept;
341 friend
bool operator<(const
Uuid& lhs, const
Uuid& rhs) noexcept;
360 template <
typename ForwardIteratorT>
361 inline Uuid::Uuid(ForwardIteratorT first, ForwardIteratorT last) {
363 std::is_base_of_v<std::forward_iterator_tag,
typename std::iterator_traits<ForwardIteratorT>::iterator_category>,
364 "Uuid range constructor requires at least a forward iterator");
366 if (std::distance(first, last) ==
static_cast<std::ptrdiff_t
>(
kByteSize)) {
367 std::copy(first, last, data_.begin());
371 inline constexpr
Uuid::Uuid() noexcept = default;
376 for (
size_t i = 0U; i < kByteSize; ++i) {
382 const uint8_t octet = data_[8];
384 if ((octet & 0x80U) == 0x00U) {
388 if ((octet & 0xC0U) == 0x80U) {
392 if ((octet & 0xE0U) == 0xC0U) {
400 switch (data_[6] & 0xF0U) {
417 for (uint8_t byte_value : data_) {
418 if (byte_value != 0U) {
426 inline constexpr
const std::array<Uuid::value_type, Uuid::kByteSize>&
Uuid::bytes() const noexcept {
return data_; }
434 inline bool operator<(
const Uuid& lhs,
const Uuid& rhs) noexcept {
return lhs.data_ < rhs.data_; }
446 const auto& data =
id.bytes();
449 for (uint8_t byte_value : data) {
450 result = (result * 131U) +
static_cast<size_t>(byte_value);
Value-typed RFC 4122 UUID.
Definition: uuid.h:94
static constexpr size_t kByteSize
UUID payload length (16 bytes per RFC 4122).
Definition: uuid.h:104
constexpr bool is_nil() const noexcept
Reports whether every byte is zero (the nil UUID).
Definition: uuid.h:416
constexpr Variant variant() const noexcept
Returns the variant field inferred from octet 8.
Definition: uuid.h:381
Variant
UUID variant inferred from the high bits of octet 8.
Definition: uuid.h:115
@ kReserved
Reserved for future use (111x).
@ kRfc
RFC 4122 / DCE 1.1 (10xx).
@ kNcs
NCS backward compatibility (0xxx).
@ kMicrosoft
Microsoft GUID (110x).
constexpr const std::array< value_type, kByteSize > & bytes() const noexcept
Provides read-only access to the underlying 16-byte payload.
Definition: uuid.h:426
constexpr Uuid() noexcept
Default-constructs a nil UUID (all 16 bytes zero).
constexpr Version version() const noexcept
Returns the version field inferred from the high nibble of octet 6.
Definition: uuid.h:399
Version
UUID version inferred from the high nibble of octet 6.
Definition: uuid.h:126
@ kTimeBased
v1 time-based.
@ kNameBasedSha1
v5 Name-based SHA-1.
@ kNone
Nil UUID or invalid version nibble.
@ kDceSecurity
v2 DCE Security.
@ kRandomBased
v4 random (produced by generate_random).
@ kNameBasedMd5
v3 Name-based MD5.
uint8_t value_type
Underlying byte type used by the 16-byte payload.
Definition: uuid.h:99
void swap(Uuid &other) noexcept
Swaps contents with other in noexcept fashion.
Definition: uuid.h:428
Cross-platform macros for visibility, branch hints, copy prevention, singletons and string helpers.
#define VLINK_EXPORT
Definition: macros.h:81
constexpr bool is_valid() noexcept
Definition: name_detector.h:382
bool operator==(const Function< ReturnT(ArgsT...), SboSizeT > &cb, std::nullptr_t) noexcept
Equality with nullptr; true when cb has no stored target.
Definition: functional.h:1051
void swap(Function< ReturnT(ArgsT...), SboSizeT > &lhs, Function< ReturnT(ArgsT...), SboSizeT > &rhs) noexcept
Free-function swap; defers to the member swap of lhs.
Definition: functional.h:1046
bool operator<(const Uuid &lhs, const Uuid &rhs) noexcept
Definition: uuid.h:434
bool operator!=(const Function< ReturnT(ArgsT...), SboSizeT > &cb, std::nullptr_t) noexcept
Inequality with nullptr; true when cb stores a target.
Definition: functional.h:1061
size_t operator()(const vlink::Uuid &id) const noexcept
Definition: uuid.h:445