TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::IDManager Class Reference

Makes element IDs: per-frame dynamic / ranged IDs (hashed from the call site or a hint and the parent stack) and persistent static IDs. More...

#include <gui_core/gui_id_manager.h>

Public Member Functions

 IDManager ()
bool BeginFrame ()
 Resets the parent stack and dynamic/ranged counters.
void EndFrame ()
 Clears the parent stack; reports misuse when a PushParent was left unpopped.
bool IsInsideFrame () const
 True between BeginFrame and EndFrame.
bool PushParent (ID parent_id)
 Makes parent_id the parent: dynamic and ranged IDs created under it inherit its hash.
bool PopParent ()
 Pops the last PushParent. Never pops the root; false on underflow or outside a frame.
ID CreateStaticID ()
 A persistent ID tracked by slot and generation; release it with ReleaseStaticID.
bool ReleaseStaticID (ID id)
 Frees the slot and bumps its generation, invalidating copies of id.
bool IsStaticIDValid (ID id) const
 True if the slot is active and the generation matches.
ID AllocateDynamicID (std::string_view file, int line)
 A dynamic ID from file and line (FILE, LINE) and the parent stack; different per call site.
ID AllocateDynamicID (std::string_view hint)
 A dynamic ID from hint and the parent stack; different per hint.
bool IsDynamicIDValid (ID id) const
 Debug: checks the tracking list (slow). Release: true for any non-Invalid Dynamic ID.
ID AllocateRangedID (uint32_t size, std::string_view file, int line)
 A ranged ID of size sub-IDs from file and line (FILE, LINE) and the parent stack.
ID AllocateRangedID (uint32_t size, std::string_view hint)
 A ranged ID of size sub-IDs from hint and the parent stack; different per hint.
uint32_t GetRangeSize (ID ranged_id) const
 The number of sub-IDs in a ranged ID; 0 (and a misuse report) for other modes.
bool IsRangedIDValid (ID id) const
 Debug: checks stored ranges (slow). Release: true for any non-Invalid Ranged ID.
ID GetSubID (ID ranged_id, uint32_t index) const
 The ID of item index (< range size) in a ranged ID, for indexed content such as list rows.
bool IsSubRangeIDValid (ID id) const
 Debug: checks stored ranges (slow). Release: true for any non-Invalid SubRange ID.
bool IsInParentStack (ID id) const
 True when id is anywhere on the parent stack. Slow: linear search.
ID GetStackParent () const
 The innermost parent; Invalid at the root or outside a frame.
bool IsIDValid (ID id) const
 True when id is valid for its mode (see the Is*IDValid functions); slow in debug builds.

Friends

struct IDManagerTestAccess
size_t GetStaticIDCount () const
 Live static IDs, and dynamic / ranged IDs made so far this frame.
size_t GetDynamicIDCount () const
 Live static IDs, and dynamic / ranged IDs made so far this frame.
size_t GetRangedIDCount () const
 Live static IDs, and dynamic / ranged IDs made so far this frame.

Detailed Description

Makes element IDs: per-frame dynamic / ranged IDs (hashed from the call site or a hint and the parent stack) and persistent static IDs.

windowID = idManager.CreateStaticID();              // once: windows, panels, docks
Button("OK", onOK);                                 // the call site is the ID
BeginTabBar(idManager.AllocateDynamicID("tabs"), &selectedTab, nullptr);   // a hint 

Constructor & Destructor Documentation

◆ IDManager()

tachyon::IDManager::IDManager ( )
inline

Member Function Documentation

◆ BeginFrame()

bool tachyon::IDManager::BeginFrame ( )
nodiscard

Resets the parent stack and dynamic/ranged counters.

Call before creating any IDs. False (misuse) when the previous frame was not ended.

◆ EndFrame()

void tachyon::IDManager::EndFrame ( )

Clears the parent stack; reports misuse when a PushParent was left unpopped.

◆ IsInsideFrame()

bool tachyon::IDManager::IsInsideFrame ( ) const
inlinenodiscard

True between BeginFrame and EndFrame.

◆ PushParent()

bool tachyon::IDManager::PushParent ( ID parent_id)
nodiscard

Makes parent_id the parent: dynamic and ranged IDs created under it inherit its hash.

Any ID mode can be a parent; returns false for an Invalid ID or outside a frame.

◆ PopParent()

bool tachyon::IDManager::PopParent ( )
nodiscard

Pops the last PushParent. Never pops the root; false on underflow or outside a frame.

◆ CreateStaticID()

ID tachyon::IDManager::CreateStaticID ( )
nodiscard

A persistent ID tracked by slot and generation; release it with ReleaseStaticID.

◆ ReleaseStaticID()

bool tachyon::IDManager::ReleaseStaticID ( ID id)

Frees the slot and bumps its generation, invalidating copies of id.

False when id is not the slot's current generation.

◆ IsStaticIDValid()

bool tachyon::IDManager::IsStaticIDValid ( ID id) const

True if the slot is active and the generation matches.

◆ AllocateDynamicID() [1/2]

ID tachyon::IDManager::AllocateDynamicID ( std::string_view file,
int line )
nodiscard

A dynamic ID from file and line (FILE, LINE) and the parent stack; different per call site.

Repeated calls from one site under one parent are numbered in call order.

◆ AllocateDynamicID() [2/2]

ID tachyon::IDManager::AllocateDynamicID ( std::string_view hint)
nodiscard

A dynamic ID from hint and the parent stack; different per hint.

Repeated calls with one hint under one parent are numbered in call order.

◆ IsDynamicIDValid()

bool tachyon::IDManager::IsDynamicIDValid ( ID id) const
nodiscard

Debug: checks the tracking list (slow). Release: true for any non-Invalid Dynamic ID.

◆ AllocateRangedID() [1/2]

ID tachyon::IDManager::AllocateRangedID ( uint32_t size,
std::string_view file,
int line )
nodiscard

A ranged ID of size sub-IDs from file and line (FILE, LINE) and the parent stack.

Repeated calls from one site under one parent return the same ID.

◆ AllocateRangedID() [2/2]

ID tachyon::IDManager::AllocateRangedID ( uint32_t size,
std::string_view hint )
nodiscard

A ranged ID of size sub-IDs from hint and the parent stack; different per hint.

◆ GetRangeSize()

uint32_t tachyon::IDManager::GetRangeSize ( ID ranged_id) const

The number of sub-IDs in a ranged ID; 0 (and a misuse report) for other modes.

◆ IsRangedIDValid()

bool tachyon::IDManager::IsRangedIDValid ( ID id) const

Debug: checks stored ranges (slow). Release: true for any non-Invalid Ranged ID.

◆ GetSubID()

ID tachyon::IDManager::GetSubID ( ID ranged_id,
uint32_t index ) const
nodiscard

The ID of item index (< range size) in a ranged ID, for indexed content such as list rows.

Invalid when index is out of range.

◆ IsSubRangeIDValid()

bool tachyon::IDManager::IsSubRangeIDValid ( ID id) const

Debug: checks stored ranges (slow). Release: true for any non-Invalid SubRange ID.

◆ IsInParentStack()

bool tachyon::IDManager::IsInParentStack ( ID id) const

True when id is anywhere on the parent stack. Slow: linear search.

◆ GetStackParent()

ID tachyon::IDManager::GetStackParent ( ) const

The innermost parent; Invalid at the root or outside a frame.

◆ IsIDValid()

bool tachyon::IDManager::IsIDValid ( ID id) const

True when id is valid for its mode (see the Is*IDValid functions); slow in debug builds.

◆ GetStaticIDCount()

size_t tachyon::IDManager::GetStaticIDCount ( ) const
inline

Live static IDs, and dynamic / ranged IDs made so far this frame.

◆ GetDynamicIDCount()

size_t tachyon::IDManager::GetDynamicIDCount ( ) const
inline

Live static IDs, and dynamic / ranged IDs made so far this frame.

◆ GetRangedIDCount()

size_t tachyon::IDManager::GetRangedIDCount ( ) const
inline

Live static IDs, and dynamic / ranged IDs made so far this frame.

◆ IDManagerTestAccess

friend struct IDManagerTestAccess
friend

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