Skip to main content

TypeIndexer Class Template

Utility class to generate unique type indices at runtime. More...

Declaration

template <typename Group> class helios::ecs::TypeIndexer<Group> { ... }

Public Static Functions Index

template <typename T>
static size_ttypeIndex ()

Generates and returns a unique type index for a specific type. More...

Private Static Attributes Index

template <typename Group>
static std::atomic< size_t >counter_ {0}

A static atomic counter used for generating unique type indices. More...

Description

Utility class to generate unique type indices at runtime.

This class provides a mechanism to generate and retrieve unique indices for different types. It ensures that each type gets a distinct index which remains constant throughout the program's execution.

The indices are generated in a thread-safe manner using atomic operations.

Template Parameters
Group

A tag type used to create separate index spaces. Different Group types maintain independent counters, allowing the same type T to have different indices in different contexts.

Example usage:

 class EventBus {
 
  struct EventTypeGroup {};
 
  using EventTypeIndexer = helios::ecs::TypeIndexer<EventTypeGroup>;
 
 public:
 
  template<typename T>
  EventBuffer<T>& getOrAddBuffer() {
  const size_t index = EventTypeIndexer::typeIndex<T>();
  auto& buffer = lookupBufferAt(index);
  // ...
  }
 };

Definition at line 48 of file TypeIndexer.ixx.

Public Static Functions

typeIndex()

template <typename T>
size_t helios::ecs::TypeIndexer< Group >::typeIndex ()
inline static

Generates and returns a unique type index for a specific type.

This method assigns a unique index to each type within the scope of the associated TypeIndexer.

Template Parameters
T

The type for which to retrieve the unique index.

Returns

A unique index representing the specific type T within this Group.

Definition at line 68 of file TypeIndexer.ixx.

68 static size_t typeIndex() {
69 static const size_t typeIndex = counter_.fetch_add(1, std::memory_order::relaxed);
70 return typeIndex;
71 }

Reference helios::ecs::TypeIndexer< Group >::typeIndex.

Referenced by helios::ecs::TypeIndexer< Group >::typeIndex.

Private Static Attributes

counter_

template <typename Group>
std::atomic<size_t> helios::ecs::TypeIndexer< Group >::counter_ {0}
static

A static atomic counter used for generating unique type indices.

Definition at line 53 of file TypeIndexer.ixx.

53 static inline std::atomic<size_t> counter_{0};

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.