ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::RegistryEntity Class Reference

Entity containing a reference to the registry. More...

#include <RegistryEntity.hpp>

Inheritance diagram for ecstasy::RegistryEntity:
Collaboration diagram for ecstasy::RegistryEntity:

Public Member Functions

constexpr RegistryEntity (Entity entity, Registry &registry) noexcept
 Construct a new RegistryEntity by binding an Entity to a Registry reference.
 
template<typename C , typename... Args>
C & add (Args &&...args)
 Add a component to the entity.
 
template<typename C >
const C & get () const
 Try to fetch the instance of component C associated to the current entity.
 
template<typename C >
C & get ()
 Try to fetch the instance of component C associated to the current entity.
 
template<typename C >
bool has () const
 Test if the entity has an associated component in the storage S.
 
constexpr RegistrygetRegistry () noexcept
 Get the entity owning registry.
 
- Public Member Functions inherited from ecstasy::Entity
constexpr Index getIndex () const noexcept
 Get the entity identifier,.
 
constexpr Generation getGeneration () const noexcept
 Get the Generation of the entity.
 
constexpr auto operator<=> (Entity const &other) const noexcept
 Compare two entities using only their identifier.
 
constexpr bool operator== (Entity const &other) const noexcept
 Compare two entities using only their identifier.
 
template<IsStorage S, typename... Args>
S::Component & add (S &storage, Args &&...args)
 Add a component to the entity.
 
template<IsStorage S>
S::Component & operator[] (S &storage)
 If the entity already has an instance of component C, returns it.
 
template<IsStorage S>
const S::Component & operator[] (S &storage) const
 Try to fetch the instance of component C associated to the current entity.
 
template<IsStorage S>
const S::Component & get (S &storage) const
 Try to fetch the instance of component C associated to the current entity.
 
template<IsStorage S>
S::Component & get (S &storage)
 Try to fetch the instance of component C associated to the current entity.
 
template<IsStorage S>
bool has (S &storage) const
 Test if the entity has an associated component in the storage S.
 

Private Attributes

Registry_registry
 Reference to the registry.
 

Additional Inherited Members

- Public Types inherited from ecstasy::Entity
using Index = size_t
 The entity identifier type.
 
using Generation = size_t
 The entity generation type.
 
- Protected Member Functions inherited from ecstasy::Entity
constexpr Entity (Index index, Generation generation) noexcept
 The entity structure may only be constructed by builders.
 
- Protected Attributes inherited from ecstasy::Entity
Index _index
 The entity identifier.
 
Generation _generation
 The entity generation.
 

Detailed Description

Entity containing a reference to the registry.

Allows to find storage implicitly.

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)

Definition at line 26 of file RegistryEntity.hpp.

Constructor & Destructor Documentation

◆ RegistryEntity()

constexpr ecstasy::RegistryEntity::RegistryEntity ( Entity  entity,
Registry registry 
)
inlineconstexprnoexcept

Construct a new RegistryEntity by binding an Entity to a Registry reference.

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)

Definition at line 34 of file RegistryEntity.hpp.

35 : Entity(entity.getIndex(), entity.getGeneration()), _registry(registry)
36 {
37 }
constexpr Entity(Index index, Generation generation) noexcept
The entity structure may only be constructed by builders.
Definition Entity.hpp:236
Registry & _registry
Reference to the registry.

Member Function Documentation

◆ add()

template<typename C , typename... Args>
C & ecstasy::RegistryEntity::add ( Args &&...  args)
inline

Add a component to the entity.

Template Parameters
CComponent type.
ArgsType of the arguments to forward to the component constructor.
Parameters
[in]argsArguments to forward to the component constructor.
Returns
C& Reference to the newly created component.
Exceptions
std::logic_errorIf the component was already present.
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)

Definition at line 55 of file RegistryEntity.hpp.

56 {
57 return Entity::add(_registry.getStorageSafe<C>(), std::forward<Args>(args)...);
58 }
S::Component & add(S &storage, Args &&...args)
Add a component to the entity.
Definition Entity.hpp:111
getStorageType< C > & getStorageSafe() noexcept
Get the Storage of a component and create it if not found.

◆ get() [1/2]

template<typename C >
C & ecstasy::RegistryEntity::get ( )
inline

Try to fetch the instance of component C associated to the current entity.

Template Parameters
CType of the component to retrieve.
Returns
C& Reference to the entity instance of C associated to the entity.
Exceptions
std::out_of_rangeIf no associated instance found.
std::logic_errorIf the storage is not registered.
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)

Definition at line 93 of file RegistryEntity.hpp.

94 {
95 return _registry.getStorage<C>()[_index];
96 }
Index _index
The entity identifier.
Definition Entity.hpp:223
const getStorageType< C > & getStorage() const
Get the Storage for the component type C.
Definition Registry.hpp:973

◆ get() [2/2]

template<typename C >
const C & ecstasy::RegistryEntity::get ( ) const
inline

Try to fetch the instance of component C associated to the current entity.

Template Parameters
CType of the component to retrieve.
Returns
const C& Const reference to the entity instance of C associated to the entity.
Exceptions
std::out_of_rangeIf no associated instance found.
std::logic_errorIf the storage is not registered.
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)

Definition at line 74 of file RegistryEntity.hpp.

75 {
76 return _registry.getStorage<C>()[_index];
77 }

◆ getRegistry()

constexpr Registry & ecstasy::RegistryEntity::getRegistry ( )
inlineconstexprnoexcept

Get the entity owning registry.

Returns
Registry& Reference to the entity owning registry.
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-11-06)

Definition at line 122 of file RegistryEntity.hpp.

123 {
124 return _registry;
125 }

◆ has()

template<typename C >
bool ecstasy::RegistryEntity::has ( ) const
inline

Test if the entity has an associated component in the storage S.

Template Parameters
SStorage of a component.
Returns
bool True if the entity has an associated entry 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 (2022-10-19)

Definition at line 109 of file RegistryEntity.hpp.

110 {
112 }
constexpr bool contains
Checks if the type T exists in the types Ts.
Definition contains.hpp:29

Member Data Documentation

◆ _registry

Registry& ecstasy::RegistryEntity::_registry
private

Reference to the registry.

Definition at line 129 of file RegistryEntity.hpp.


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