XII Release 0.1.0
Loading...
Searching...
No Matches
xiiGenericId< InstanceIndexBits, GenerationBits > Struct Template Reference

#include <Id.h>

Public Types

enum  { STORAGE_SIZE = ((InstanceIndexBits + GenerationBits - 1) / 8) + 1 }
 Number of bytes requested for the underlying integral storage type.
using StorageType = typename xiiSizeToType<STORAGE_SIZE>::Type
 Integral type used to store the packed identifier.

Public Member Functions

 XII_DECLARE_ID_TYPE (xiiGenericId, InstanceIndexBits, GenerationBits)
XII_ALWAYS_INLINE xiiGenericId (StorageType instanceIndex, StorageType generation)

Public Attributes

union { 
   StorageType   m_Data 
 Packed representation containing both identifier components.
   struct { 
      StorageType   m_InstanceIndex: InstanceIndexBits 
 Index of the referenced instance.
      StorageType   m_Generation: GenerationBits 
 Generation associated with the instance.
   } 
}; 

Detailed Description

template<xiiUInt32 InstanceIndexBits, xiiUInt32 GenerationBits>
struct xiiGenericId< InstanceIndexBits, GenerationBits >

A compact generational identifier that combines an instance index and a generation counter. A generational identifier uniquely identifies an instance within an indexed collection while providing a mechanism for detecting stale references when instance indices are reused.

The identifier consists of two components:

  • Instance Index: Identifies the slot occupied by an instance within a collection.
  • Generation: Distinguishes successive instances that occupy the same slot.

When an instance is removed, its index may be reused for a new instance. By incrementing the generation counter associated with that slot, previously issued identifiers can be distinguished from identifiers referring to the newly allocated instance.

Both components are packed into a single integral storage type, allowing the identifier to be stored, copied, and compared efficiently.

Template Parameters
InstanceIndexBitsNumber of bits reserved for the instance index.
GenerationBitsNumber of bits reserved for the generation counter.
Note
The generation counter provides stale-identifier detection only when the owning collection maintains and validates generation values. Generation counter wraparound may eventually cause an old identifier to become valid again.
The bit-field layout is implementation-defined. The packed representation should not be assumed to have a portable binary layout across different compilers or platforms.
See also
XII_DECLARE_ID_TYPE

Constructor & Destructor Documentation

◆ xiiGenericId()

template<xiiUInt32 InstanceIndexBits, xiiUInt32 GenerationBits>
XII_ALWAYS_INLINE xiiGenericId< InstanceIndexBits, GenerationBits >::xiiGenericId ( StorageType instanceIndex,
StorageType generation )
inline

Constructs an identifier from an instance index and generation counter.

Parameters
instanceIndexThe index of the instance within its owning collection.
generationThe generation associated with the instance.
Note
Both values must fit within their respective bit widths. Values exceeding the allocated widths may be truncated when assigned to the bit fields.

The documentation for this struct was generated from the following file:
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Types/Id.h