GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::execution::ComponentPool< Component > Class Template Reference

Reference to an EntityRegistry's pool of instances of a specific component type. More...

#include <GREM/execution/EntityRegistry.hpp>

Public Types

using iterator = detail::SingleComponentIterator<Component>
using sentinel = detail::SingleComponentSentinel
using value_type = typename iterator::value_type
using reference = typename iterator::reference
using size_type = size_t
using difference_type = typename iterator::difference_type
using component_type = Component

Public Member Functions

GREM_ALWAYS_INLINE constexpr ComponentPool () noexcept=default
 Construct an invalid component pool reference.
GREM_ALWAYS_INLINE operator ComponentPool< const Component > () const noexcept
 Convert a non-const component pool reference to a const component pool reference.
GREM_ALWAYS_INLINE constexpr iterator begin () const noexcept
GREM_ALWAYS_INLINE constexpr sentinel end () const noexcept
GREM_ALWAYS_INLINE constexpr reference operator[] (EntityID id) const
GREM_ALWAYS_INLINE constexpr bool has (EntityID id) const
 Check if the referenced pool has a component instance associated with a specific entity.
GREM_ALWAYS_INLINE Component & get (EntityID id) const
 Get the component instance associated with a specific entity.
template<typename U>
GREM_ALWAYS_INLINE Component getOr (EntityID id, U &&defaultValue) const
 Get the component instance associated with a specific entity, or a default value in case the entity doesn't exist or doesn't have an associated component instance.
GREM_ALWAYS_INLINE Component * find (EntityID id) const
 Try to get the component instance associated with a specific entity.
template<typename... Args>
requires (!std::is_const_v<Component>)
GREM_ALWAYS_INLINE Component & add (EntityID id, Args &&... args)
 Add a component instance associated with a specific entity.
template<typename... Args>
requires (!std::is_const_v<Component>)
GREM_ALWAYS_INLINE Component * addIfMissing (EntityID id, Args &&... args)
 Add a component instance associated with a specific entity if it doesn't already have one.
GREM_ALWAYS_INLINE Component & addOrAssign (EntityID id, Component &&value)
 Add a component instance associated with a specific entity, or assign to it if it already has one.
GREM_ALWAYS_INLINE Component & addOrAssign (EntityID id, const Component &value)
 Add a component instance associated with a specific entity, or assign to it if it already has one.
GREM_ALWAYS_INLINE bool remove (EntityID id) noexcept
 Erase the component instance associated with a specific entity.
GREM_ALWAYS_INLINE size_type removeFromAllEntities () noexcept
 Erase all associated component instances.

Friends

template<typename... KnownComponents>
class EntityRegistry
 Entity registry used by a Simulation.
template<typename U>
class ComponentPool

Detailed Description

template<typename Component>
class grem::execution::ComponentPool< Component >

Reference to an EntityRegistry's pool of instances of a specific component type.

Template Parameters
Componentcomponent type stored in the referenced pool, potentially const-qualified to indicate read-only access.

Member Typedef Documentation

◆ iterator

template<typename Component>
using grem::execution::ComponentPool< Component >::iterator = detail::SingleComponentIterator<Component>

◆ sentinel

template<typename Component>
using grem::execution::ComponentPool< Component >::sentinel = detail::SingleComponentSentinel

◆ value_type

template<typename Component>
using grem::execution::ComponentPool< Component >::value_type = typename iterator::value_type

◆ reference

template<typename Component>
using grem::execution::ComponentPool< Component >::reference = typename iterator::reference

◆ size_type

template<typename Component>
using grem::execution::ComponentPool< Component >::size_type = size_t

◆ difference_type

template<typename Component>
using grem::execution::ComponentPool< Component >::difference_type = typename iterator::difference_type

◆ component_type

template<typename Component>
using grem::execution::ComponentPool< Component >::component_type = Component

Constructor & Destructor Documentation

◆ ComponentPool()

template<typename Component>
GREM_ALWAYS_INLINE constexpr grem::execution::ComponentPool< Component >::ComponentPool ( )
constexprdefaultnoexcept

Construct an invalid component pool reference.

Member Function Documentation

◆ operator ComponentPool< const Component >()

template<typename Component>
GREM_ALWAYS_INLINE grem::execution::ComponentPool< Component >::operator ComponentPool< const Component > ( ) const
inlinenoexcept

Convert a non-const component pool reference to a const component pool reference.

Returns
a const-qualified view over the referenced component pool.

◆ begin()

template<typename Component>
GREM_ALWAYS_INLINE constexpr iterator grem::execution::ComponentPool< Component >::begin ( ) const
inlinenodiscardconstexprnoexcept

◆ end()

template<typename Component>
GREM_ALWAYS_INLINE constexpr sentinel grem::execution::ComponentPool< Component >::end ( ) const
inlinenodiscardconstexprnoexcept

◆ operator[]()

template<typename Component>
GREM_ALWAYS_INLINE constexpr reference grem::execution::ComponentPool< Component >::operator[] ( EntityID id) const
inlinenodiscardconstexpr

◆ has()

template<typename Component>
GREM_ALWAYS_INLINE constexpr bool grem::execution::ComponentPool< Component >::has ( EntityID id) const
inlinenodiscardconstexpr

Check if the referenced pool has a component instance associated with a specific entity.

Parameters
identity handle to check.
Returns
true if the given handle corresponds to a valid entity that has a component instance stored in the pool, false otherwise.

◆ get()

template<typename Component>
GREM_ALWAYS_INLINE Component & grem::execution::ComponentPool< Component >::get ( EntityID id) const
inline

Get the component instance associated with a specific entity.

Parameters
identity handle of the entity to get the component from.
Returns
a reference to the component instance associated with the specified entity.
Exceptions
std::out_of_rangeif the given handle does not correspond to a valid entity that has a component instance stored in the pool.

◆ getOr()

template<typename Component>
template<typename U>
GREM_ALWAYS_INLINE Component grem::execution::ComponentPool< Component >::getOr ( EntityID id,
U && defaultValue ) const
inline

Get the component instance associated with a specific entity, or a default value in case the entity doesn't exist or doesn't have an associated component instance.

Parameters
identity handle of the entity to get the component from.
defaultValuedefault value to return in case the given handle does not correspond to a valid entity with an associated component instance.
Returns
a copy of the component instance associated with the specified entity, or the specified default value if the given handle does not correspond to a valid entity that has a component instance stored in the pool.

◆ find()

template<typename Component>
GREM_ALWAYS_INLINE Component * grem::execution::ComponentPool< Component >::find ( EntityID id) const
inlinenodiscard

Try to get the component instance associated with a specific entity.

Parameters
identity handle of the entity to get the component from.
Returns
a pointer to the associated component of the specified entity, or nullptr if the given handle does not correspond to a valid entity that has a component instance stored in the pool.

◆ add()

template<typename Component>
template<typename... Args>
requires (!std::is_const_v<Component>)
GREM_ALWAYS_INLINE Component & grem::execution::ComponentPool< Component >::add ( EntityID id,
Args &&... args )
inline

Add a component instance associated with a specific entity.

Parameters
identity handle of the entity to add the component to.
argsarguments to forward to the component constructor.
Returns
a reference to the newly created component instance.
Exceptions
std::logic_errorif this component pool reference is invalid, or if the pool already contains a component instance associated with the specified entity.
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the component constructor.

◆ addIfMissing()

template<typename Component>
template<typename... Args>
requires (!std::is_const_v<Component>)
GREM_ALWAYS_INLINE Component * grem::execution::ComponentPool< Component >::addIfMissing ( EntityID id,
Args &&... args )
inline

Add a component instance associated with a specific entity if it doesn't already have one.

Parameters
identity handle of the entity to add the component to.
argsarguments to forward to the component constructor.
Returns
a pointer to the newly created component instance, or nullptr if the pool already contains a component instance associated with the specified entity.
Exceptions
std::logic_errorif this component pool reference is invalid.
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the component constructor.

◆ addOrAssign() [1/2]

template<typename Component>
GREM_ALWAYS_INLINE Component & grem::execution::ComponentPool< Component >::addOrAssign ( EntityID id,
Component && value )
inline

Add a component instance associated with a specific entity, or assign to it if it already has one.

Parameters
identity handle of the entity to assign the component to.
valuecomponent value to add or assign.
Returns
a reference to the newly created component instance, or to the existing component instance associated with the specified entity if it already had one.
Exceptions
std::logic_errorif this component pool reference is invalid.
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the move constructor or move assignment operator of the component type.

◆ addOrAssign() [2/2]

template<typename Component>
GREM_ALWAYS_INLINE Component & grem::execution::ComponentPool< Component >::addOrAssign ( EntityID id,
const Component & value )
inline

Add a component instance associated with a specific entity, or assign to it if it already has one.

Parameters
identity handle of the entity to assign the component to.
valuecomponent value to add or assign.
Returns
a reference to the newly created component instance, or to the existing component instance associated with the specified entity if it already had one.
Exceptions
std::logic_errorif this component pool reference is invalid.
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the copy constructor or copy assignment operator of the component type.

◆ remove()

template<typename Component>
GREM_ALWAYS_INLINE bool grem::execution::ComponentPool< Component >::remove ( EntityID id)
inlinenoexcept

Erase the component instance associated with a specific entity.

Parameters
identity handle of the entity to remove the component from.
Returns
true if the entity handle corresponded to a valid entity with an associated component instance in the referenced pool that was successfully removed, false otherwise.

◆ removeFromAllEntities()

template<typename Component>
GREM_ALWAYS_INLINE size_type grem::execution::ComponentPool< Component >::removeFromAllEntities ( )
inlinenoexcept

Erase all associated component instances.

Returns
the number of component instances in the referenced pool that were successfully removed.

◆ EntityRegistry

template<typename Component>
template<typename... KnownComponents>
friend class EntityRegistry
friend

Entity registry used by a Simulation.

Template Parameters
Nnumber of dimensions of the world space (must be 2 or 3).

◆ ComponentPool

template<typename Component>
template<typename U>
friend class ComponentPool
friend

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