TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_id.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <memory>
5
6namespace tachyon
7{
10
12 enum class IDMode : uint64_t
13 {
14 Static = 0,
15 Dynamic = 1,
16 Ranged = 2,
18 };
19
22 struct ID
23 {
25 static constexpr uint64_t MODE_BITS = 2;
26
27 static constexpr uint64_t MAX_STATIC_INDEX_BITS = 32;
28 static constexpr uint64_t MAX_STATIC_GEN_BITS = (64 - MODE_BITS - MAX_STATIC_INDEX_BITS);
29 static constexpr uint64_t MAX_STATIC_INDEX_MASK = (1ull << MAX_STATIC_INDEX_BITS) - 1;
30 static constexpr uint64_t MAX_STATIC_GEN_MASK = (1ull << MAX_STATIC_GEN_BITS) - 1;
31
32 static constexpr uint64_t MAX_RANGED_SIZE_BITS = 25;
33 static constexpr uint64_t MAX_RANGED_HASH_BITS = (64 - MODE_BITS - MAX_RANGED_SIZE_BITS);
34 static constexpr uint64_t MAX_RANGED_SIZE_MASK = (1ull << MAX_RANGED_SIZE_BITS) - 1;
35 static constexpr uint64_t MAX_RANGED_HASH_MASK = (1ull << MAX_RANGED_HASH_BITS) - 1;
36
66 static constexpr ID Invalid() { return { 0 }; }
67
69 inline IDMode GetMode() const { return static_cast<IDMode>(value.staticParts.mode); }
70
72 inline uint64_t Value() const { return value.integer; }
73
74 constexpr bool operator==(const ID& other) const noexcept { return value.integer == other.value.integer; }
75 constexpr bool operator!=(const ID& other) const noexcept { return value.integer != other.value.integer; }
76 constexpr bool operator<(const ID& other) const noexcept { return value.integer < other.value.integer; }
77 constexpr bool operator>(const ID& other) const noexcept { return value.integer > other.value.integer; }
78 constexpr bool operator<=(const ID& other) const noexcept { return value.integer <= other.value.integer; }
79 constexpr bool operator>=(const ID& other) const noexcept { return value.integer >= other.value.integer; }
80 };
81 static_assert(sizeof(ID) == sizeof(uint64_t), "ID size must be 64 bits");
82 static_assert(sizeof(ID::Value::StaticParts) == sizeof(uint64_t), "ID size must be 64 bits");
83 static_assert(sizeof(ID::Value::DynamicParts) == sizeof(uint64_t), "ID size must be 64 bits");
84 static_assert(sizeof(ID::Value::RangedParts) == sizeof(uint64_t), "ID size must be 64 bits");
85 static_assert(sizeof(ID::Value::SubRangeParts) == sizeof(uint64_t), "ID size must be 64 bits");
86
88} // namespace tachyon
89
90namespace std
91{
92 template<>
93 struct hash<tachyon::ID>
94 {
95 inline size_t operator()(const tachyon::ID& id) const noexcept
96 {
97 return static_cast<size_t>(id.value.integer);
98 }
99 };
100}
IDMode
How an ID was made; stored in 2 bits of the ID.
Definition gui_id.h:13
@ Static
persistent; created and released through IDManager, checked by generation
Definition gui_id.h:14
@ Dynamic
remade each frame from the call site or a hint and the parent stack
Definition gui_id.h:15
@ Ranged
remade each frame; a block of sub-IDs for indexed content (IDManager::GetSubID)
Definition gui_id.h:16
@ SubRange
one item of a Ranged ID: the range's hash plus an index
Definition gui_id.h:17
Definition gui_id.h:91
Definition gui_logging.h:24
size_t operator()(const tachyon::ID &id) const noexcept
Definition gui_id.h:95
Definition gui_id.h:48
uint64_t hashValue
Definition gui_id.h:50
IDMode mode
Definition gui_id.h:49
Definition gui_id.h:53
uint64_t rangedSize
Definition gui_id.h:55
IDMode mode
Definition gui_id.h:54
uint64_t hashValue
Definition gui_id.h:56
Definition gui_id.h:42
IDMode mode
Definition gui_id.h:43
uint64_t slotIndex
Definition gui_id.h:44
uint64_t generation
Definition gui_id.h:45
Definition gui_id.h:59
uint64_t index
Definition gui_id.h:61
uint64_t parentHashValue
Definition gui_id.h:62
IDMode mode
Definition gui_id.h:60
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
constexpr bool operator<=(const ID &other) const noexcept
Definition gui_id.h:78
static constexpr uint64_t MAX_STATIC_GEN_BITS
Definition gui_id.h:28
constexpr bool operator!=(const ID &other) const noexcept
Definition gui_id.h:75
uint64_t Value() const
The raw 64 bits, e.g. as a hash or map key; not stable across runs.
Definition gui_id.h:72
static constexpr uint64_t MODE_BITS
Bit layout sizes; internal.
Definition gui_id.h:25
constexpr bool operator>(const ID &other) const noexcept
Definition gui_id.h:77
static constexpr uint64_t MAX_STATIC_GEN_MASK
Definition gui_id.h:30
IDMode GetMode() const
How the ID was made.
Definition gui_id.h:69
static constexpr uint64_t MAX_STATIC_INDEX_BITS
Definition gui_id.h:27
static constexpr uint64_t MAX_STATIC_INDEX_MASK
Definition gui_id.h:29
static constexpr uint64_t MAX_RANGED_HASH_MASK
Definition gui_id.h:35
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
union tachyon::ID::Value value
constexpr bool operator>=(const ID &other) const noexcept
Definition gui_id.h:79
constexpr bool operator<(const ID &other) const noexcept
Definition gui_id.h:76
static constexpr uint64_t MAX_RANGED_SIZE_MASK
Definition gui_id.h:34
static constexpr uint64_t MAX_RANGED_SIZE_BITS
Definition gui_id.h:32
constexpr bool operator==(const ID &other) const noexcept
Definition gui_id.h:74
static constexpr uint64_t MAX_RANGED_HASH_BITS
Definition gui_id.h:33
The packed bits, viewed per mode; internal (use GetMode / Value / IDManager).
Definition gui_id.h:39
struct tachyon::ID::Value::RangedParts rangedParts
struct tachyon::ID::Value::StaticParts staticParts
struct tachyon::ID::Value::DynamicParts dynamicParts
struct tachyon::ID::Value::SubRangeParts subRangeParts
uint64_t integer
Definition gui_id.h:40