xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::core::Uuid Class Reference

A UUID. More...

#include <core/Uuid.hpp>

Public Member Functions

constexpr Uuid ()=default
 Default constructor. Generates a nil UUID.
 
auto hash () const noexcept -> std::size_t
 Calculates a hash value for the UUID.
 
template<tools::CharType Char, typename CharTraits = std::char_traits<Char>>
auto toBasicString () const -> string::BasicFixedString< Char, kStringSize, CharTraits >
 Converts the UUID to a string.
 
auto toString () const -> std::string
 Converts the UUID to a string of type char.
 
auto toWString () const -> std::wstring
 Converts the UUID to a string of type wchar_t.
 
auto toU8String () const -> std::u8string
 Converts the UUID to a string of type char8_t.
 
auto toU16String () const -> std::u16string
 Converts the UUID to a string of type char16_t.
 
auto toU32String () const -> std::u32string
 Converts the UUID to a string of type char32_t.
 
auto rawData () const -> std::span< const std::byte, kRawDataSize >
 Gets the raw data of the UUID.
 
constexpr auto operator== (const Uuid &rhs) const -> bool
 Comparison operator.
 
constexpr auto operator<=> (const Uuid &rhs) const -> std::strong_ordering
 Three-Way-Comparison operator.
 
constexpr auto isNull () const noexcept -> bool
 Determines if the UUID is 00000000-0000-0000-0000-000000000000
 

Static Public Member Functions

template<tools::StringViewable String>
static auto fromString (const String &string) -> eh::expected< Uuid, std::error_code >
 Creates a new UUID from a string.
 
static auto fromRawData (const std::span< const std::byte, kRawDataSize > &data) -> Uuid
 Creates a new UUID from raw data.
 
static auto create () -> Uuid
 Creates a new UUID.
 
static auto createVersion4 () -> Uuid
 Creates a version 4 UUID.
 
static auto createVersion5 (const Uuid &namespaceUuid, const void *data, std::size_t size) -> Uuid
 Creates a version 5 UUID from a block of memory.
 
template<tools::StringViewable String>
static auto createVersion5 (const Uuid &namespaceUuid, const String &string) -> Uuid
 Creates a version 5 UUID from a Unicode string.
 
template<memory::MemoryRegion Region>
requires (!tools::StringViewable<Region>)
static auto createVersion5 (const Uuid &namespaceUuid, const Region &region) -> Uuid
 Creates a version 5 UUID from a memory region.
 
template<memory::MemoryIterator Iterator>
static auto createVersion5 (const Uuid &namespaceUuid, Iterator begin, Iterator end) -> Uuid
 Creates a version 5 UUID from a memory region defined by a pair of iterators.
 
template<memory::MemoryIterator Iterator>
requires (!std::convertible_to<Iterator, const void *>)
static auto createVersion5 (const Uuid &namespaceUuid, Iterator begin, std::iter_difference_t< Iterator > size) -> Uuid
 Creates a version 5 UUID from a memory region defined by an iterator and a size.
 

Static Public Attributes

static constexpr std::size_t kRawDataSize
 The size of the raw data.
 
static constexpr std::size_t kStringSize
 The size of the string representation.
 

Related Symbols

(Note that these are not member symbols.)

consteval auto operator""_uuid (const char *string, std::size_t size) -> utils::core::Uuid
 Literal operator for creating literal UUIDs.
 

Detailed Description

A UUID.

Constructor & Destructor Documentation

◆ Uuid()

constexpr xentara::utils::core::Uuid::Uuid ( )
constexprdefault

Default constructor. Generates a nil UUID.

Member Function Documentation

◆ create()

static auto xentara::utils::core::Uuid::create ( ) -> Uuid
static

Creates a new UUID.

Creates a new general purpose UUID, using a suitable version.

◆ createVersion4()

static auto xentara::utils::core::Uuid::createVersion4 ( ) -> Uuid
static

Creates a version 4 UUID.

◆ createVersion5() [1/5]

template<memory::MemoryRegion Region>
requires (!tools::StringViewable<Region>)
static auto xentara::utils::core::Uuid::createVersion5 ( const Uuid namespaceUuid,
const Region &  region 
) -> Uuid
static

Creates a version 5 UUID from a memory region.

Parameters
namespaceUuidThe namespace UUID
regionThe memory region

◆ createVersion5() [2/5]

template<tools::StringViewable String>
static auto xentara::utils::core::Uuid::createVersion5 ( const Uuid namespaceUuid,
const String &  string 
) -> Uuid
static

Creates a version 5 UUID from a Unicode string.

Parameters
namespaceUuidThe namespace UUID
stringThe string. Must be encoded as UTF-8, UTF-16, or UTF-32.

◆ createVersion5() [3/5]

static auto xentara::utils::core::Uuid::createVersion5 ( const Uuid namespaceUuid,
const void *  data,
std::size_t  size 
) -> Uuid
static

Creates a version 5 UUID from a block of memory.

Parameters
namespaceUuidThe namespace UUID
dataA pointer to the memory block
sizeThe size of the memory block

◆ createVersion5() [4/5]

template<memory::MemoryIterator Iterator>
static auto xentara::utils::core::Uuid::createVersion5 ( const Uuid namespaceUuid,
Iterator  begin,
Iterator  end 
) -> Uuid
static

Creates a version 5 UUID from a memory region defined by a pair of iterators.

Parameters
namespaceUuidThe namespace UUID
beginAn iterator that points at the beginning of the memory region
endAn iterator that points at the end of the memory region

◆ createVersion5() [5/5]

template<memory::MemoryIterator Iterator>
requires (!std::convertible_to<Iterator, const void *>)
static auto xentara::utils::core::Uuid::createVersion5 ( const Uuid namespaceUuid,
Iterator  begin,
std::iter_difference_t< Iterator >  size 
) -> Uuid
static

Creates a version 5 UUID from a memory region defined by an iterator and a size.

Parameters
namespaceUuidThe namespace UUID
beginAn iterator that points at the beginning of the memory region
sizeThe size of the memory region

◆ fromRawData()

static auto xentara::utils::core::Uuid::fromRawData ( const std::span< const std::byte, kRawDataSize > &  data) -> Uuid
static

Creates a new UUID from raw data.

Parameters
dataThe raw bytes that should make up the UUID, in big endian byte order. The UUID 00112233-4455-6677-8899-aabbccddeeff must be represented as { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }.
Returns
The UUID. No validity checking is done on the data.

◆ fromString()

template<tools::StringViewable String>
auto xentara::utils::core::Uuid::fromString ( const String &  string) -> eh::expected<Uuid, std::error_code>
static

Creates a new UUID from a string.

Parameters
stringThe string. The encoding of the string can be ASCII, or any encoding compatible with ASCII. This includes, but is not limited to, UTF-8, Latin-1, Windows Code Page 1252, and Windows Code Page 850 (OEM).
Returns
The UUID, or an error, if the string does not contain a valid UUID

◆ hash()

auto xentara::utils::core::Uuid::hash ( ) const -> std::size_t
noexcept

Calculates a hash value for the UUID.

◆ isNull()

constexpr auto xentara::utils::core::Uuid::isNull ( ) const -> bool
constexprnoexcept

Determines if the UUID is 00000000-0000-0000-0000-000000000000

◆ operator<=>()

constexpr auto xentara::utils::core::Uuid::operator<=> ( const Uuid rhs) const -> std::strong_ordering
constexpr

Three-Way-Comparison operator.

◆ operator==()

constexpr auto xentara::utils::core::Uuid::operator== ( const Uuid rhs) const -> bool
constexpr

Comparison operator.

◆ rawData()

auto xentara::utils::core::Uuid::rawData ( ) const -> std::span<const std::byte, kRawDataSize>

Gets the raw data of the UUID.

Returns
The raw bytes that make up the UUID, in big endian byte order. The UUID 00112233-4455-6677-8899-aabbccddeeff will be returned as { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }.

The returned span will become invalid when this Uuid object is destroyed.

◆ toBasicString()

template<tools::CharType Char, typename CharTraits >
auto xentara::utils::core::Uuid::toBasicString ( ) const -> string::BasicFixedString<Char, kStringSize, CharTraits>

Converts the UUID to a string.

◆ toString()

auto xentara::utils::core::Uuid::toString ( ) const -> std::string

Converts the UUID to a string of type char.

◆ toU16String()

auto xentara::utils::core::Uuid::toU16String ( ) const -> std::u16string

Converts the UUID to a string of type char16_t.

◆ toU32String()

auto xentara::utils::core::Uuid::toU32String ( ) const -> std::u32string

Converts the UUID to a string of type char32_t.

◆ toU8String()

auto xentara::utils::core::Uuid::toU8String ( ) const -> std::u8string

Converts the UUID to a string of type char8_t.

◆ toWString()

auto xentara::utils::core::Uuid::toWString ( ) const -> std::wstring

Converts the UUID to a string of type wchar_t.

Friends And Related Symbol Documentation

◆ operator""_uuid()

consteval auto operator""_uuid ( const char *  string,
std::size_t  size 
) -> utils::core::Uuid
related

Literal operator for creating literal UUIDs.

Member Data Documentation

◆ kRawDataSize

constexpr std::size_t xentara::utils::core::Uuid::kRawDataSize
staticconstexpr

The size of the raw data.

◆ kStringSize

constexpr std::size_t xentara::utils::core::Uuid::kStringSize
staticconstexpr

The size of the string representation.