ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::AStorage< C > Class Template Referenceabstract

Abstract class for all components storage. More...

#include <AStorage.hpp>

Inheritance diagram for ecstasy::AStorage< C >:
Collaboration diagram for ecstasy::AStorage< C >:

Public Types

using Component = C
 IsStorage constraint.
 
using QueryData = C &
 QueryableObject constraint.
 
using ConstQueryData = const C &
 ConstQueryableObject constraint.
 

Public Member Functions

virtual bool erase (Entity::Index index)=0
 Erase the Component instance associated to the given entity.
 
void erase (std::span< Entity > entities) override final
 Erase multiple Component instances associated to the given entities.
 
bool contains (Entity::Index index) const noexcept override final
 Test if the entity index match a Component instance.
 
Componentat (Entity::Index index)
 Retrieve the Component instance associated to the given entity and perform bound checking.
 
const Componentat (Entity::Index index) const
 Retrieve the Component instance associated to the given entity and perform bound checking.
 
virtual Componentoperator[] (Entity::Index index)=0
 Retrieve the Component instance associated to the given entity.
 
QueryData getQueryData (Entity::Index index)
 Retrieve the Component instance associated to the given entity.
 
virtual const Componentoperator[] (Entity::Index index) const =0
 Retrieve the const Component instance associated to the given entity.
 
ConstQueryData getQueryData (Entity::Index index) const
 Retrieve the Component instance associated to the given entity.
 
const std::type_infogetComponentTypeInfos () const noexcept override final
 Get the Component stored type infos.
 
virtual Componentinsert (Entity::Index index, Component &&c)=0
 Insert a new Component instance associated to the given entity.
 
- Public Member Functions inherited from ecstasy::IStorage
virtual ~IStorage ()=default
 
virtual constexpr const util::BitSetgetMask () const noexcept=0
 Get the Component Mask.
 
virtual void erase (std::span< Entity > entities)=0
 Erase the components attached to the given entities.
 
virtual bool contains (size_t index) const noexcept=0
 Test if the entity index match a Component instance.
 
virtual const std::type_infogetComponentTypeInfos () const noexcept=0
 Get the Component stored type infos.
 

Detailed Description

template<typename C>
class ecstasy::AStorage< C >

Abstract class for all components storage.

Template Parameters
CComponent type.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-23)

Definition at line 34 of file AStorage.hpp.

Member Typedef Documentation

◆ Component

template<typename C >
using ecstasy::AStorage< C >::Component = C

IsStorage constraint.

Definition at line 37 of file AStorage.hpp.

◆ ConstQueryData

template<typename C >
using ecstasy::AStorage< C >::ConstQueryData = const C &

ConstQueryableObject constraint.

Definition at line 42 of file AStorage.hpp.

◆ QueryData

template<typename C >
using ecstasy::AStorage< C >::QueryData = C &

QueryableObject constraint.

Definition at line 40 of file AStorage.hpp.

Member Function Documentation

◆ at() [1/2]

template<typename C >
Component & ecstasy::AStorage< C >::at ( Entity::Index  index)
inline

Retrieve the Component instance associated to the given entity and perform bound checking.

Parameters
[in]indexIndex of the entity.
Returns
QueryData Reference to the associated component.
Exceptions
std::out_of_rangeIf the entity doesn't have the component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-23)

Definition at line 94 of file AStorage.hpp.

95 {
96 if (!contains(index)) [[unlikely]]
97 throw std::out_of_range("Entity doesn't have the component");
98 return (*this)[index];
99 }
bool contains(Entity::Index index) const noexcept override final
Test if the entity index match a Component instance.
Definition AStorage.hpp:77

◆ at() [2/2]

template<typename C >
const Component & ecstasy::AStorage< C >::at ( Entity::Index  index) const
inline

Retrieve the Component instance associated to the given entity and perform bound checking.

Parameters
[in]indexIndex of the entity.
Returns
QueryData Reference to the associated component.
Exceptions
std::out_of_rangeIf the entity doesn't have the component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-23)

Definition at line 113 of file AStorage.hpp.

114 {
115 if (!contains(index)) [[unlikely]]
116 throw std::out_of_range("Entity doesn't have the component");
117 return (*this)[index];
118 }

◆ contains()

template<typename C >
bool ecstasy::AStorage< C >::contains ( Entity::Index  index) const
inlinefinaloverridevirtualnoexcept

Test if the entity index match a Component instance.

Parameters
[in]indexIndex of the entity.
Returns
bool True if the entity has a component, false otherwise.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Implements ecstasy::IStorage.

Definition at line 77 of file AStorage.hpp.

78 {
79 return (index < getMask().size()) && getMask()[index];
80 }
virtual constexpr const util::BitSet & getMask() const noexcept=0
Get the Component Mask.
T size(T... args)

◆ erase() [1/2]

template<typename C >
virtual bool ecstasy::AStorage< C >::erase ( Entity::Index  index)
pure virtual

Erase the Component instance associated to the given entity.

Note
Does nothing if the index doesn't match with any component (ie if the entity doesn't have a component Component)
Parameters
[in]indexIndex of the entity.
Returns
bool True if the component was erased, false otherwise.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Implemented in ecstasy::MapStorage< C >, ecstasy::MarkerStorage< C >, and ecstasy::VectorStorage< C >.

◆ erase() [2/2]

template<typename C >
void ecstasy::AStorage< C >::erase ( std::span< Entity entities)
inlinefinaloverridevirtual

Erase multiple Component instances associated to the given entities.

Note
Does nothing for entity without attached component (ie if the entity doesn't have a component Component)
Parameters
[in]entitiestarget entities.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-21)

Implements ecstasy::IStorage.

Definition at line 70 of file AStorage.hpp.

71 {
72 for (Entity entity : entities)
73 erase(entity.getIndex());
74 }
virtual bool erase(Entity::Index index)=0
Erase the Component instance associated to the given entity.

◆ getComponentTypeInfos()

template<typename C >
const std::type_info & ecstasy::AStorage< C >::getComponentTypeInfos ( ) const
inlinefinaloverridevirtualnoexcept

Get the Component stored type infos.

Returns
const std::type_info& Type informations of the component stored in the storage.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-06-11)

Implements ecstasy::IStorage.

Definition at line 167 of file AStorage.hpp.

168 {
169 return typeid(Component);
170 }
C Component
IsStorage constraint.
Definition AStorage.hpp:37

◆ getQueryData() [1/2]

template<typename C >
QueryData ecstasy::AStorage< C >::getQueryData ( Entity::Index  index)
inline

Retrieve the Component instance associated to the given entity.

Warning
This function may not perform bound checking. For VectorStorage or MarkerStorage it is noexcept but not for MapStorage for example.
Parameters
[in]indexIndex of the entity.
Returns
Component& Reference to the associated component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)
Note
QueryableObject constraint.

Definition at line 138 of file AStorage.hpp.

139 {
140 return (*this)[index];
141 };

◆ getQueryData() [2/2]

template<typename C >
ConstQueryData ecstasy::AStorage< C >::getQueryData ( Entity::Index  index) const
inline

Retrieve the Component instance associated to the given entity.

Warning
This function may not perform bound checking. For VectorStorage or MarkerStorage it is noexcept but not for MapStorage for example.
Parameters
[in]indexIndex of the entity.
Returns
Component& Reference to the associated component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)
Note
ConstQueryableObject constraint.

Definition at line 161 of file AStorage.hpp.

162 {
163 return (*this)[index];
164 };

◆ insert()

template<typename C >
virtual Component & ecstasy::AStorage< C >::insert ( Entity::Index  index,
Component &&  c 
)
pure virtual

Insert a new Component instance associated to the given entity.

Parameters
[in]indexIndex of the entity.
[in]cComponent instance to insert.
Returns
Component& Reference to the inserted component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-06-25)

Implemented in ecstasy::MapStorage< C >, ecstasy::MarkerStorage< C >, and ecstasy::VectorStorage< C >.

◆ operator[]() [1/2]

template<typename C >
virtual const Component & ecstasy::AStorage< C >::operator[] ( Entity::Index  index) const
pure virtual

Retrieve the const Component instance associated to the given entity.

Warning
This function may not perform bound checking. For VectorStorage or MarkerStorage it is noexcept but not for MapStorage for example.
Parameters
[in]indexIndex of the entity.
Returns
const Component& Const reference to the associated component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Implemented in ecstasy::MarkerStorage< C >, ecstasy::VectorStorage< C >, and ecstasy::MapStorage< C >.

◆ operator[]() [2/2]

template<typename C >
virtual Component & ecstasy::AStorage< C >::operator[] ( Entity::Index  index)
pure virtual

Retrieve the Component instance associated to the given entity.

Warning
This function may not perform bound checking. For VectorStorage or MarkerStorage it is noexcept but not for MapStorage for example.
Parameters
[in]indexIndex of the entity.
Returns
Component& Reference to the associated component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Implemented in ecstasy::MarkerStorage< C >, ecstasy::VectorStorage< C >, and ecstasy::MapStorage< C >.


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