libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
UUID Class Reference

Universally Unique Identifier (UUID). More...

#include <uuid.h>

Public Types

using DataFormat = Array< uint8_t, 16 >
 Raw 16-byte storage format for a UUID.
 

Public Member Functions

 UUID ()
 Constructs an invalid (all-zero) UUID.
 
 UUID (const UUID &u)
 Copy constructor.
 
 UUID (const UUID &&u)
 Move constructor.
 
 UUID (const DataFormat &val)
 Constructs a UUID from raw 16-byte data.
 
 UUID (const DataFormat &&val)
 Move-constructs a UUID from raw 16-byte data.
 
 UUID (const char *str)
 Constructs a UUID by parsing a C-string.
 
 UUID (const String &str)
 Constructs a UUID by parsing a String.
 
UUIDoperator= (const UUID &val)
 Copy assignment operator.
 
UUIDoperator= (const UUID &&val)
 Move assignment operator.
 
UUIDoperator= (const DataFormat &val)
 Assigns from raw 16-byte data.
 
UUIDoperator= (const DataFormat &&val)
 Move-assigns from raw 16-byte data.
 
bool operator== (const UUID &other) const
 Returns true if both UUIDs are equal.
 
bool operator!= (const UUID &other) const
 Returns true if the UUIDs are not equal.
 
bool operator< (const UUID &other) const
 Less-than comparison for ordering (lexicographic).
 
bool operator> (const UUID &other) const
 Greater-than comparison for ordering (lexicographic).
 
bool operator<= (const UUID &other) const
 Less-than-or-equal comparison for ordering (lexicographic).
 
bool operator>= (const UUID &other) const
 Greater-than-or-equal comparison for ordering (lexicographic).
 
 operator String () const
 Implicit conversion to String via toString().
 
bool isValid () const
 Returns true if this UUID is not all-zero.
 
int version () const
 Returns the UUID version number.
 
String toString () const
 Returns the standard string representation of the UUID.
 
const DataFormatdata () const
 Returns a const reference to the raw 16-byte data.
 
const uint8_traw () const
 Returns a pointer to the raw byte data.
 

Static Public Member Functions

static UUID generate (int version=4)
 Convenience generator that dispatches to the appropriate generateVn() function.
 
static UUID generateV1 ()
 Generates a version 1 (timestamp + MAC) UUID.
 
static UUID generateV3 (const UUID &ns, const String &name)
 Generates a version 3 (MD5 namespace) UUID.
 
static UUID generateV4 ()
 Generates a random version 4 UUID.
 
static UUID generateV5 (const UUID &ns, const String &name)
 Generates a version 5 (SHA-1 namespace) UUID.
 
static UUID generateV7 (int64_t timestampMs=-1)
 Generates a version 7 (Unix timestamp + random) UUID.
 
static UUID fromString (const char *string, Error *err=nullptr)
 Parses a UUID from a string representation.
 

Detailed Description

Universally Unique Identifier (UUID).

Generates and manipulates RFC 4122 / RFC 9562 UUIDs.

Example
UUID id = UUID::generate(); // random v4
String str = id.toString(); // "550e8400-e29b-..."
UUID parsed = UUID::fromString(str); // round-trip
bool valid = id.isValid();
Dynamic array container wrapping std::vector.
Definition list.h:40
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
Universally Unique Identifier (UUID).
Definition uuid.h:34
static UUID fromString(const char *string, Error *err=nullptr)
Parses a UUID from a string representation.
static UUID generate(int version=4)
Convenience generator that dispatches to the appropriate generateVn() function.
Supports versions 1 (stub), 3, 4, 5, and 7.

Member Function Documentation

◆ data()

const DataFormat & UUID::data ( ) const
inline

Returns a const reference to the raw 16-byte data.

Returns
The underlying DataFormat array.

◆ fromString()

static UUID UUID::fromString ( const char string,
Error err = nullptr 
)
static

Parses a UUID from a string representation.

Parameters
stringThe UUID string (e.g. "550e8400-e29b-41d4-a716-446655440000").
errOptional error output.
Returns
The parsed UUID, or an invalid UUID on failure.

◆ generate()

static UUID UUID::generate ( int  version = 4)
static

Convenience generator that dispatches to the appropriate generateVn() function.

Parameters
versionUUID version to generate (default: 4).

For versions 3 and 5, the namespace UUID and name are taken from the Application object (appUUID and appName).

Returns
A valid UUID, or an invalid UUID if the version is unsupported or if generation fails.

◆ generateV1()

static UUID UUID::generateV1 ( )
static

Generates a version 1 (timestamp + MAC) UUID.

Note
Not implemented. Calling this will trigger an assertion failure.

◆ generateV3()

static UUID UUID::generateV3 ( const UUID ns,
const String name 
)
static

Generates a version 3 (MD5 namespace) UUID.

Parameters
nsThe namespace UUID.
nameThe name to hash within the namespace.
Returns
A deterministic version 3 UUID.

◆ generateV4()

static UUID UUID::generateV4 ( )
static

Generates a random version 4 UUID.

Returns
A valid UUID, or an invalid (all-zero) UUID on failure.

◆ generateV5()

static UUID UUID::generateV5 ( const UUID ns,
const String name 
)
static

Generates a version 5 (SHA-1 namespace) UUID.

Parameters
nsThe namespace UUID.
nameThe name to hash within the namespace.
Returns
A deterministic version 5 UUID.

◆ generateV7()

static UUID UUID::generateV7 ( int64_t  timestampMs = -1)
static

Generates a version 7 (Unix timestamp + random) UUID.

Parameters
timestampMsUnix timestamp in milliseconds. If negative, the current system time is used.
Returns
A valid, time-sortable UUID.

◆ isValid()

bool UUID::isValid ( ) const
inline

Returns true if this UUID is not all-zero.

Returns
true if the UUID contains at least one non-zero byte.

◆ raw()

const uint8_t * UUID::raw ( ) const
inline

Returns a pointer to the raw byte data.

Returns
A pointer to the first byte of the UUID.

◆ toString()

String UUID::toString ( ) const

Returns the standard string representation of the UUID.

Returns
A String in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".

◆ version()

int UUID::version ( ) const
inline

Returns the UUID version number.

Returns
The version (1-8) encoded in the UUID, or 0 if invalid.

The documentation for this class was generated from the following file: