Skip to main content

ConceptModelRegistry Class Template

Generic type-indexed registry for type-erased wrapper instances. More...

Declaration

template <typename AnyT, typename IdProvider> class helios::engine::core::container::ConceptModelRegistry<AnyT, IdProvider> { ... }

Public Member Functions Index

template <typename AnyT, typename IdProvider>
auto items () const noexcept -> std::span< AnyT *const >

Returns a read-only span of registered items in insertion order. More...

template <typename AnyT, typename IdProvider>
auto items () noexcept -> std::span< AnyT * >

Returns a mutable span of registered items in insertion order. More...

template <typename T, typename... Args>
T &add (Args &&... args)

Registers and wraps a concrete instance of type T. More...

template <typename T>
T &add (AnyT &&wrapper)

Registers a pre-built wrapper instance for concrete type T. More...

template <typename T>
boolhas () const

Checks whether a concrete type T is registered. More...

template <typename T>
T *item () const

Returns a pointer to the registered instance of type T. More...

Private Member Functions Index

template <typename AnyT, typename IdProvider>
voidupdate () const

Rebuilds the insertion-ordered view if dirty. More...

Private Member Attributes Index

template <typename AnyT, typename IdProvider>
std::vector< AnyT >items_

Owning storage for wrapped AnyT instances, indexed by type ID. More...

template <typename AnyT, typename IdProvider>
std::vector< void * >underlyingAnyT_

Cached raw pointers to the underlying concrete instances. More...

template <typename AnyT, typename IdProvider>
std::vector< size_t >insertionOrder_

Records insertion order for deterministic iteration. More...

template <typename AnyT, typename IdProvider>
std::vector< AnyT * >itemView_

Lazily-built view of AnyT pointers in insertion order. More...

template <typename AnyT, typename IdProvider>
boolneedsUpdate_ = false

Dirty flag indicating itemView_ needs rebuilding. More...

Description

Generic type-indexed registry for type-erased wrapper instances.

ConceptModelRegistry stores instances of a type-erased wrapper AnyT (e.g. System, Manager) and indexes them by a compile-time IdProvider (e.g. SystemTypeId, ResourceTypeId). This provides:

  • O(1) lookup by concrete type via item<T>()
  • Insertion-order iteration via items() for deterministic processing
  • Type-safe registration via add<T>(args...) or add<T>(AnyT&&) returning a reference to the underlying concrete instance

The registry is used as the backend for SystemRegistry and ManagerRegistry.

Definition at line 51 of file ConceptModelRegistry.ixx.

Public Member Functions

add()

template <typename T, typename... Args>
T & helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::add (Args &&... args)
inline

Registers and wraps a concrete instance of type T.

Constructs T in-place from the forwarded arguments, wraps it in an AnyT, and stores it at the index determined by IdProvider::id<T>(). Returns a reference to the underlying concrete T instance.

Template Parameters
T

The concrete type to register.

Args

Constructor argument types for T.

Parameters
args

Arguments forwarded to the T constructor.

Returns

Reference to the registered T instance.

Precondition

T must not already be registered.

Definition at line 139 of file ConceptModelRegistry.ixx.

139 T& add(Args&&... args) {
140
141 assert(!has<T>() && "AnyT already registered.");
142
143 AnyT wrapper{T{std::forward<Args>(args)...}};
144
145 const auto idx = IdProvider::template id<T>().value();
146
147 if (items_.size() <= idx) {
148 items_.resize(idx + 1);
149 }
150 if (underlyingAnyT_.size() <= idx) {
151 underlyingAnyT_.resize(idx + 1);
152 }
153
154 items_[idx] = std::move(wrapper);
155 void* rawUnderlying = items_[idx].underlying();
156 underlyingAnyT_[idx] = rawUnderlying;
157
158
159 insertionOrder_.push_back(idx);
160
161 needsUpdate_ = true;
162 return *static_cast<T*>(rawUnderlying);
163 }

Reference helios::registerComponents.

add()

template <typename T>
T & helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::add (AnyT && wrapper)
inline

Registers a pre-built wrapper instance for concrete type T.

Stores an already-constructed AnyT at the slot determined by IdProvider::id<T>() and returns the underlying T reference.

This overload is useful when wrapper construction needs custom arguments that are not expressed as T{args...} (for example, pre-wrapped systems with injected dependencies).

Template Parameters
T

The concrete type represented by wrapper.

Parameters
wrapper

Pre-built type-erased wrapper owning a T instance.

Returns

Reference to the registered T instance.

Precondition

wrapper must contain a concrete T instance.

Precondition

T should not already be registered.

Definition at line 185 of file ConceptModelRegistry.ixx.

186 const auto idx = IdProvider::template id<T>().value();
187
188 if (items_.size() <= idx) {
189 items_.resize(idx + 1);
190 }
191 if (underlyingAnyT_.size() <= idx) {
192 underlyingAnyT_.resize(idx + 1);
193 }
194
195 items_[idx] = std::move(wrapper);
196
197 void* rawUnderlying = items_[idx].underlying();
198 underlyingAnyT_[idx] = rawUnderlying;
199
200 insertionOrder_.push_back(idx);
201 needsUpdate_ = true;
202
203 return *static_cast<T*>(rawUnderlying);
204 }

Reference helios::registerComponents.

has()

template <typename T>
bool helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::has ()
inline

Checks whether a concrete type T is registered.

Template Parameters
T

The type to check.

Returns

True if T has been added.

Definition at line 215 of file ConceptModelRegistry.ixx.

215 [[nodiscard]] bool has() const {
216 return item<T>() != nullptr;
217 }

Reference helios::registerComponents.

Referenced by helios::engine::runtime::world::ResourceRegistry::has.

item()

template <typename T>
T * helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::item ()
inline

Returns a pointer to the registered instance of type T.

Template Parameters
T

The concrete type to look up.

Returns

Pointer to T, or nullptr if not registered.

Definition at line 227 of file ConceptModelRegistry.ixx.

227 [[nodiscard]] T* item() const {
228
229 const auto idx = IdProvider::template id<T>().value();
230 if (items_.size() <= idx || underlyingAnyT_.size() <= idx) {
231 return nullptr;
232 }
233
234 return underlyingAnyT_[idx] ? static_cast<T*>(underlyingAnyT_[idx]) : nullptr;
235 }

Reference helios::registerComponents.

Referenced by helios::engine::runtime::world::ResourceRegistry::get and helios::engine::runtime::world::ResourceRegistry::tryGet.

items()

template <typename AnyT, typename IdProvider>
std::span< AnyT *const > helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::items ()
inline noexcept

Returns a read-only span of registered items in insertion order.

Returns

Span of const AnyT pointers.

Definition at line 106 of file ConceptModelRegistry.ixx.

106 [[nodiscard]] std::span<AnyT* const> items() const noexcept {
107 update();
108 return itemView_;
109 }

Referenced by helios::engine::runtime::world::ResourceRegistry::commandBuffers, helios::engine::runtime::world::ResourceRegistry::commandBuffers, helios::engine::runtime::world::ResourceRegistry::managers and helios::engine::runtime::world::ResourceRegistry::managers.

items()

template <typename AnyT, typename IdProvider>
std::span< AnyT * > helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::items ()
inline noexcept

Returns a mutable span of registered items in insertion order.

Returns

Span of AnyT pointers.

Definition at line 116 of file ConceptModelRegistry.ixx.

116 [[nodiscard]] std::span<AnyT*> items() noexcept {
117 update();
118 return itemView_;
119 }

Private Member Functions

update()

template <typename AnyT, typename IdProvider>
void helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::update ()
inline

Rebuilds the insertion-ordered view if dirty.

Definition at line 81 of file ConceptModelRegistry.ixx.

81 void update() const {
82
83 if (!needsUpdate_) {
84 return;
85 }
86
87 itemView_.clear();
88 itemView_.reserve(insertionOrder_.size());
89
90 for (const auto insertionIndex : insertionOrder_) {
91 itemView_.push_back(const_cast<AnyT*>(&items_[insertionIndex]));
92 }
93
94 needsUpdate_ = false;
95
96 }

Private Member Attributes

insertionOrder_

template <typename AnyT, typename IdProvider>
std::vector<size_t> helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::insertionOrder_

Records insertion order for deterministic iteration.

Definition at line 66 of file ConceptModelRegistry.ixx.

66 std::vector<size_t> insertionOrder_;

items_

template <typename AnyT, typename IdProvider>
std::vector<AnyT> helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::items_
mutable

Owning storage for wrapped AnyT instances, indexed by type ID.

Definition at line 56 of file ConceptModelRegistry.ixx.

56 mutable std::vector<AnyT> items_;

itemView_

template <typename AnyT, typename IdProvider>
std::vector<AnyT*> helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::itemView_
mutable

Lazily-built view of AnyT pointers in insertion order.

Definition at line 71 of file ConceptModelRegistry.ixx.

71 mutable std::vector<AnyT*> itemView_;

needsUpdate_

template <typename AnyT, typename IdProvider>
bool helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::needsUpdate_ = false
mutable

Dirty flag indicating itemView_ needs rebuilding.

Definition at line 76 of file ConceptModelRegistry.ixx.

76 mutable bool needsUpdate_ = false;

underlyingAnyT_

template <typename AnyT, typename IdProvider>
std::vector<void*> helios::engine::core::container::ConceptModelRegistry< AnyT, IdProvider >::underlyingAnyT_

Cached raw pointers to the underlying concrete instances.

Definition at line 61 of file ConceptModelRegistry.ixx.

61 std::vector<void*> underlyingAnyT_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.