vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::TypeRegistry< Base > Class Template Reference

One slot per type, indexed by typeId<T>() and filled on first use. More...

#include <type_registry.h>

Public Member Functions

template<typename T, typename Make>
Base & ensure (Make &&make)
 The slot for T, created by make the first time it is asked for.
template<typename T>
Base * find ()
 The slot for T without creating one.
template<typename T>
const Base * find () const
 The slot for T without creating one.
template<typename T>
std::unique_ptr< Base > & slot ()
 The owning pointer for T's slot, grown into existence but left empty.
void clear ()
 Drop every slot. Types are re-registered lazily on the next ask.
template<typename Pred>
void removeIf (Pred &&pred)
 Empty every slot pred accepts, keeping the rest where they are.
void swap (TypeRegistry &other) noexcept
 Exchange every slot with another registry.
std::size_t count () const
 How many types actually have a slot.
template<typename Fn>
void forEach (Fn &&fn)
 Invoke fn(Base&) for every filled slot, in type-id order.
template<typename Fn>
void forEach (Fn &&fn) const
 Invoke fn(Base&) for every filled slot, in type-id order.

Detailed Description

template<typename Base>
class Vkm::Engine::TypeRegistry< Base >

One slot per type, indexed by typeId<T>() and filled on first use.

Type ids are shared across registries, so slots for other registries' types sit empty.

Template Parameters
BaseWhat every slot holds: a polymorphic base or a per-type struct.

Member Function Documentation

◆ ensure()

template<typename Base>
template<typename T, typename Make>
Base & Vkm::Engine::TypeRegistry< Base >::ensure ( Make && make)
inline

The slot for T, created by make the first time it is asked for.

Template Parameters
TType the slot belongs to.
MakeCallable returning a std::unique_ptr<Base>.
Parameters
makeBuilds the slot; called at most once per type.
Returns
The slot, stable until clear() or swap().

◆ find() [1/2]

template<typename Base>
template<typename T>
Base * Vkm::Engine::TypeRegistry< Base >::find ( )
inline

The slot for T without creating one.

Template Parameters
TType the slot belongs to.
Returns
The slot, or null when nothing has asked for T's yet.

◆ find() [2/2]

template<typename Base>
template<typename T>
const Base * Vkm::Engine::TypeRegistry< Base >::find ( ) const
inline

The slot for T without creating one.

Template Parameters
TType the slot belongs to.
Returns
The slot, or null when nothing has asked for T's yet.

◆ slot()

template<typename Base>
template<typename T>
std::unique_ptr< Base > & Vkm::Engine::TypeRegistry< Base >::slot ( )
inline

The owning pointer for T's slot, grown into existence but left empty.

For a caller moving a slot rather than reading it.

Template Parameters
TType the slot belongs to.
Returns
The owning pointer; null unless something filled it.

◆ removeIf()

template<typename Base>
template<typename Pred>
void Vkm::Engine::TypeRegistry< Base >::removeIf ( Pred && pred)
inline

Empty every slot pred accepts, keeping the rest where they are.

Never erased: the index is the type id, so closing a gap would hand later types the wrong slot.

Template Parameters
PredCallable taking const Base& and returning bool.
Parameters
predTrue for a slot to drop.

◆ swap()

template<typename Base>
void Vkm::Engine::TypeRegistry< Base >::swap ( TypeRegistry< Base > & other)
inlinenoexcept

Exchange every slot with another registry.

Parameters
otherRegistry to trade with.

◆ count()

template<typename Base>
std::size_t Vkm::Engine::TypeRegistry< Base >::count ( ) const
inline

How many types actually have a slot.

Not the vector's length, which includes other registries' empty slots.

Returns
The number of filled slots.

◆ forEach() [1/2]

template<typename Base>
template<typename Fn>
void Vkm::Engine::TypeRegistry< Base >::forEach ( Fn && fn)
inline

Invoke fn(Base&) for every filled slot, in type-id order.

Template Parameters
FnCallable taking Base&.
Parameters
fnCalled once per filled slot.

◆ forEach() [2/2]

template<typename Base>
template<typename Fn>
void Vkm::Engine::TypeRegistry< Base >::forEach ( Fn && fn) const
inline

Invoke fn(Base&) for every filled slot, in type-id order.

Template Parameters
FnCallable taking Base&.
Parameters
fnCalled once per filled slot.

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