Skip to main content

ComponentOpsRegistry Class Template

Global registry for component lifecycle function pointers. More...

Declaration

template <typename THandle> class helios::ecs::ComponentOpsRegistry<THandle> { ... }

Public Member Typedefs Index

template <typename THandle>
usingComponentTypeId_type = ComponentTypeId< THandle >

Public Static Functions Index

template <typename THandle>
static voidsetOps (const ComponentTypeId_type typeId, const ComponentOps &ops)

Registers ComponentOps for a component type. More...

template <typename THandle>
static const ComponentOps &ops (const ComponentTypeId_type typeId)

Retrieves ComponentOps for a component type. More...

Private Static Attributes Index

template <typename THandle>
static std::vector< ComponentOps >operations_

Type-indexed storage for ComponentOps. More...

template <typename THandle>
static constexpr ComponentOpsemptyOps_ {}

Empty ops returned for unregistered types. More...

Description

Global registry for component lifecycle function pointers.

`ComponentOpsRegistry` provides O(1) lookup of `ComponentOps` by `ComponentTypeId`. It uses a type-indexed vector where the index corresponds to the component type's unique identifier.

## Domain Scoping

The registry is templated on `THandle` so that each domain (identified by its `EntityHandle<TStrongId>` specialisation) has its own independent, `inline static` ops storage. This prevents lifecycle hooks registered for one domain from interfering with another.

## Usage

```cpp // Registration (done by ComponentReflector<THandle, TEM>) ComponentOpsRegistry<GameHandle>::setOps(typeId, ops);

// Lookup at runtime const auto& ops = ComponentOpsRegistry<GameHandle>::ops(typeId); if (ops.onAcquire) { ops.onAcquire(rawComponent); } ```

info

Not thread-safe. All registration must complete before concurrent access.

Template Parameters
THandle

The concrete `EntityHandle<TStrongId>` specialisation scoping this registry instance.

See Also

ComponentOps

See Also

ComponentReflector

Definition at line 54 of file ComponentOpsRegistry.ixx.

Public Member Typedefs

ComponentTypeId_type

template <typename THandle>
using helios::ecs::ComponentOpsRegistry< THandle >::ComponentTypeId_type = ComponentTypeId<THandle>

Public Static Functions

ops()

template <typename THandle>
const ComponentOps & helios::ecs::ComponentOpsRegistry< THandle >::ops (const ComponentTypeId_type typeId)
inline static

Retrieves ComponentOps for a component type.

Parameters
typeId

The unique identifier for the component type.

Returns

Reference to the registered ComponentOps, or empty ops if not registered.

Definition at line 95 of file ComponentOpsRegistry.ixx.

95 static const ComponentOps& ops(const ComponentTypeId_type typeId) {
96
97 if (typeId.value() >= operations_.size()) {
98 return emptyOps_;
99 }
100
101 return operations_[typeId.value()];
102 }

setOps()

template <typename THandle>
void helios::ecs::ComponentOpsRegistry< THandle >::setOps (const ComponentTypeId_type typeId, const ComponentOps & ops)
inline static

Registers ComponentOps for a component type.

Auto-resizes the internal vector if necessary.

Parameters
typeId

The unique identifier for the component type.

ops

The lifecycle function pointers to register.

Definition at line 79 of file ComponentOpsRegistry.ixx.

79 static void setOps(const ComponentTypeId_type typeId, const ComponentOps& ops) {
80
81 if (typeId.value() >= operations_.size()) {
82 operations_.resize(typeId.value() + 1);
83 }
84
85 operations_[typeId.value()] = ops;
86 }

Referenced by helios::ecs::ComponentReflector< TEntityManager >::registerType.

Private Static Attributes

emptyOps_

template <typename THandle>
ComponentOps helios::ecs::ComponentOpsRegistry< THandle >::emptyOps_ {}
constexpr static

Empty ops returned for unregistered types.

Definition at line 64 of file ComponentOpsRegistry.ixx.

64 inline static constexpr ComponentOps emptyOps_{};

operations_

template <typename THandle>
std::vector<ComponentOps> helios::ecs::ComponentOpsRegistry< THandle >::operations_
static

Type-indexed storage for ComponentOps.

Definition at line 59 of file ComponentOpsRegistry.ixx.

59 inline static std::vector<ComponentOps> operations_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.