KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
id.hpp
1/*
2 KTech, Kaup's C++ 2D terminal game engine library.
3 Copyright (C) 2023-2025 Ethan Kaufman (AKA Kaup)
4
5 This file is part of KTech.
6
7 KTech is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 any later version.
11
12 KTech is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with KTech. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21#pragma once
22
23#define KTECH_DEFINITION
24#include "../ktech.hpp"
25#undef KTECH_DEFINITION
26
27#include <cstddef>
28
36template<typename T>
38{
40 explicit constexpr ID()
41 : m_uuid(0) {};
42
48 constexpr auto operator==(ID id) const -> bool
49 {
50 return id.m_uuid == m_uuid;
51 }
52
53private:
54 mutable size_t m_i = 0; // Local cached index
55 uint64_t m_uuid; // Universally unique identifier
56
57 explicit constexpr ID(uint64_t uuid)
58 : m_uuid(uuid) {}
59
60 // Generate a unique `ID`; can only be used by world structures.
61 static auto Unique() -> ID
62 {
63 static uint64_t uuid = 0;
64 uuid++;
65 return ID(uuid);
66 }
67
68 friend T; // Allow only world structures to call `Unique()`.
69 friend class CachingRegistry<T>;
70};
Serializable world structure identifier.
Definition id.hpp:38
constexpr auto operator==(ID id) const -> bool
Compare 2 IDs.
Definition id.hpp:48
constexpr ID()
Construct a null ID.
Definition id.hpp:40