QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Quasar::UUID Class Reference

Permanent identifier for entities, assets and any object that must keep the same identity across sessions. More...

#include <quasar/core/UUID.h>

Public Member Functions

constexpr UUID ()=default
 Creates an invalid UUID, with the value 0.
constexpr UUID (std::uint64_t value)
 Creates a UUID from a saved value, for example when a scene is loaded.
constexpr std::uint64_t GetValue () const
 Returns the raw value, to save the UUID in a file.
constexpr bool IsValid () const
 Returns true if the UUID is not the reserved value 0.
std::string ToString () const
 Returns the UUID as text, to save it in a file: 16 lowercase hexadecimal digits.
constexpr auto operator<=> (const UUID &) const =default
 Compares two UUIDs by their value, so they can be sorted and used as map keys.

Static Public Member Functions

static UUID Generate ()
 Creates a new random UUID.
static std::optional< UUID > FromString (std::string_view text)
 Reads a UUID from the text written by ToString().

Detailed Description

Permanent identifier for entities, assets and any object that must keep the same identity across sessions.

The value is saved as is in scene and asset files. The value 0 is reserved: a default-constructed UUID is invalid. Use Generate() to create a new identifier. A UUID can be used as a key in std::map and std::unordered_map.

Constructor & Destructor Documentation

◆ UUID()

Quasar::UUID::UUID ( std::uint64_t value)
inlineexplicitconstexpr

Creates a UUID from a saved value, for example when a scene is loaded.

Parameters
valueThe value returned by GetValue() when the UUID was saved.

Member Function Documentation

◆ Generate()

UUID Quasar::UUID::Generate ( )
static

Creates a new random UUID.

Safe to call from any thread.

Returns
A valid UUID, never equal to 0.

◆ GetValue()

std::uint64_t Quasar::UUID::GetValue ( ) const
inlineconstexpr

Returns the raw value, to save the UUID in a file.

Returns
The 64-bit value of the UUID.

◆ IsValid()

bool Quasar::UUID::IsValid ( ) const
inlineconstexpr

Returns true if the UUID is not the reserved value 0.

Returns
False for a default-constructed UUID, true for a generated one.

◆ ToString()

std::string Quasar::UUID::ToString ( ) const

Returns the UUID as text, to save it in a file: 16 lowercase hexadecimal digits.

Returns
For example "00ab3f9c12e45d07". An invalid UUID gives "0000000000000000".

◆ FromString()

std::optional< UUID > Quasar::UUID::FromString ( std::string_view text)
static

Reads a UUID from the text written by ToString().

Nothing is logged when the text is invalid: the caller knows which file or field it came from, so it can report a clearer error.

Parameters
textExactly 16 hexadecimal digits, in lowercase or uppercase, with nothing before or after.
Returns
The UUID, or no value if the text has another form.

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