Toast Engine
Loading...
Searching...
No Matches
uid.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <format>
12#include <toast/export.hpp>
13
14namespace assets {
15class Prefab;
16}
17
18namespace toast {
19
20struct TOAST_API UID {
21 friend class Engine;
22 friend class INodeOwner;
23 friend class assets::Prefab;
24
25 UID();
26
27 UID(uint64_t val) : value(val) { }
28
33 operator std::string() const noexcept;
34 auto operator<=>(const UID& other) const noexcept -> std::strong_ordering;
35 auto operator==(const UID& other) const noexcept -> bool;
36
41 [[nodiscard]]
42 auto get() const noexcept -> std::string;
43
45 [[nodiscard]]
46 auto data() const noexcept -> uint64_t;
47
49 static auto toString(uint64_t uid) -> std::string;
50
52 static auto fromString(std::string_view b64) -> uint64_t;
53
55 static auto make() -> UID;
56
57private:
58 void generate();
60 void assign(
61 std::string_view b64
62 );
63 uint64_t value;
64};
65
66}
67
69template<>
70struct std::formatter<toast::UID> : std::formatter<std::string> {
71 auto format(const toast::UID& uid, std::format_context& ctx) const {
72 return std::formatter<std::string>::format(uid.get(), ctx);
73 }
74};
Definition prefab.hpp:54
Definition uid.hpp:20
static auto fromString(std::string_view b64) -> uint64_t
Decodes an 11-character base64url string produced by toString(); inverse of toString().
Definition uid.cpp:46
auto get() const noexcept -> std::string
Encodes the 64-bit value as an 11-character base64url string.
Definition uid.cpp:132
auto data() const noexcept -> uint64_t
Returns the raw 64-bit integer; useful for hashing or serialization that owns the encoding.
Definition uid.cpp:136
static auto make() -> UID
Generates and returns a fresh unique UID using the same algorithm as the node registry.
Definition uid.cpp:110
static auto toString(uint64_t uid) -> std::string
Encodes any 64-bit value as an 11-character base64url string; same encoding as get().
Definition uid.cpp:17