QuasarEngine
Cross-platform 3D engine and editor
Toggle main menu visibility
Loading...
Searching...
No Matches
UUID.h
Go to the documentation of this file.
1
#pragma once
2
7
8
#include <compare>
9
#include <cstddef>
10
#include <cstdint>
11
#include <functional>
12
#include <optional>
13
#include <string>
14
#include <string_view>
15
16
namespace
Quasar
17
{
24
class
UUID
25
{
26
public
:
28
constexpr
UUID
() =
default
;
29
32
constexpr
explicit
UUID
(std::uint64_t value) : m_Value(value) {}
33
36
static
UUID
Generate
();
37
40
constexpr
std::uint64_t
GetValue
()
const
{
return
m_Value; }
41
44
constexpr
bool
IsValid
()
const
{
return
m_Value != 0; }
45
48
std::string
ToString
()
const
;
49
56
static
std::optional<UUID>
FromString
(std::string_view text);
57
59
constexpr
auto
operator<=>
(
const
UUID
&)
const
=
default
;
60
61
private
:
62
std::uint64_t m_Value = 0;
63
};
64
66
inline
std::string
format_as
(
UUID
uuid)
67
{
68
return
uuid.
ToString
();
69
}
70
}
71
72
namespace
std
73
{
74
template
<>
75
struct
hash<Quasar::UUID>
76
{
77
std::size_t operator()(
const
Quasar::UUID& uuid)
const
noexcept
{
return
std::hash<std::uint64_t>{}(uuid.GetValue()); }
78
};
79
}
Quasar::UUID
Permanent identifier for entities, assets and any object that must keep the same identity across sess...
Definition
UUID.h:25
Quasar::UUID::ToString
std::string ToString() const
Returns the UUID as text, to save it in a file: 16 lowercase hexadecimal digits.
Quasar::UUID::operator<=>
constexpr auto operator<=>(const UUID &) const =default
Compares two UUIDs by their value, so they can be sorted and used as map keys.
Quasar::UUID::UUID
constexpr UUID()=default
Creates an invalid UUID, with the value 0.
Quasar::UUID::Generate
static UUID Generate()
Creates a new random UUID.
Quasar::UUID::UUID
constexpr UUID(std::uint64_t value)
Creates a UUID from a saved value, for example when a scene is loaded.
Definition
UUID.h:32
Quasar::UUID::GetValue
constexpr std::uint64_t GetValue() const
Returns the raw value, to save the UUID in a file.
Definition
UUID.h:40
Quasar::UUID::IsValid
constexpr bool IsValid() const
Returns true if the UUID is not the reserved value 0.
Definition
UUID.h:44
Quasar::UUID::FromString
static std::optional< UUID > FromString(std::string_view text)
Reads a UUID from the text written by ToString().
Quasar
Contains all the engine code.
Quasar::format_as
std::string format_as(UUID uuid)
Lets the log macros print a UUID with {}, using UUID::ToString().
Definition
UUID.h:66
quasar
core
UUID.h
Generated by
1.18.0