Saga
Saga Game Engine
Loading...
Searching...
No Matches
Saga::ComponentContainer< Component > Class Template Reference

Container for a specific Component type. More...

#include <componentContainer.h>

Inheritance diagram for Saga::ComponentContainer< Component >:
Collaboration diagram for Saga::ComponentContainer< Component >:

Public Member Functions

virtual ~ComponentContainer ()
 Destroy the Component Container object.
 
template<typename... Args>
Component * emplace (const Entity entity, Args &&...args)
 Emplace a component onto an entity. This created.
 
std::vector< Component >::iterator begin ()
 
std::vector< Component >::iterator end ()
 
std::vector< Component >::const_iterator begin () const
 
std::vector< Component >::const_iterator end () const
 
Component * getComponent (const Entity entity)
 Get a pointer to a Component attached to an entity.
 
bool hasComponent (const Entity entity)
 Determine if an entity has this type of Component attached.
 
Entity getEntity (Component *component)
 Get an Entity with this specific component.
 
void removeComponent (const Entity entity)
 Remove a component from an entity. This also allows the slot used for the component to be free to used for when new components gets added.
 
int getActiveCnt ()
 
int getLastReallocated () override
 Get the last time the component container resize the vector containing all the components.
 
- Public Member Functions inherited from Saga::IComponentContainer
virtual ~IComponentContainer ()=default
 Destroy the IComponentContainer object.
 
virtual void onEntityDestroyed (Entity entity)=0
 Handler for when an entity is deleted. This should remove the entity from the Container, as well as the associated component if it exists.
 
virtual int getLastReallocated ()=0
 Get the last time the container was changed. Useful for cacheing references from the container.
 

Detailed Description

template<typename Component>
class Saga::ComponentContainer< Component >

Container for a specific Component type.

Template Parameters
Componentthe component this container manages.

Constructor & Destructor Documentation

◆ ~ComponentContainer()

template<typename Component >
virtual Saga::ComponentContainer< Component >::~ComponentContainer ( )
inlinevirtual

Destroy the Component Container object.

Member Function Documentation

◆ begin() [1/2]

template<typename Component >
std::vector< Component >::iterator Saga::ComponentContainer< Component >::begin

◆ begin() [2/2]

template<typename Component >
std::vector< Component >::const_iterator Saga::ComponentContainer< Component >::begin

◆ emplace()

template<typename Component >
template<typename... Args>
Component * Saga::ComponentContainer< Component >::emplace ( const Entity  entity,
Args &&...  args 
)

Emplace a component onto an entity. This created.

Template Parameters
Argsthe argument types that the component's constructor accepts.
Parameters
entitythe entity to add the component into.
argsthe arguments used to construct the component.
Returns
Component* a pointer to the component.
Exceptions
std::invalid_argumentif the entity already has this component attached.

◆ end() [1/2]

template<typename Component >
std::vector< Component >::iterator Saga::ComponentContainer< Component >::end

◆ end() [2/2]

template<typename Component >
std::vector< Component >::const_iterator Saga::ComponentContainer< Component >::end

◆ getActiveCnt()

template<typename Component >
int Saga::ComponentContainer< Component >::getActiveCnt ( )
inline
Returns
int number of active components in this container.

◆ getComponent()

template<typename Component >
Component * Saga::ComponentContainer< Component >::getComponent ( const Entity  entity)

Get a pointer to a Component attached to an entity.

Parameters
entity
Returns
Component* the Component attached to the entity. nullptr if none exists.

◆ getEntity()

template<typename Component >
Entity Saga::ComponentContainer< Component >::getEntity ( Component *  component)

Get an Entity with this specific component.

Warning
runs in O(n).
Parameters
component
Returns
Entity the entity the component belongs to, or -1 if none exists.

◆ getLastReallocated()

template<typename Component >
int Saga::ComponentContainer< Component >::getLastReallocated ( )
inlineoverridevirtual

Get the last time the component container resize the vector containing all the components.

Returns
int an increment value that shows when the last reallocated time is. It starts at 0 and increase by 1 every time a rellocation happens. When reallocation happens, all pointers to previous components drop.

Implements Saga::IComponentContainer.

◆ hasComponent()

template<typename Component >
bool Saga::ComponentContainer< Component >::hasComponent ( const Entity  entity)

Determine if an entity has this type of Component attached.

Parameters
entity
Returns
true if the entity has the component.
false otherwise.

◆ removeComponent()

template<typename Component >
void Saga::ComponentContainer< Component >::removeComponent ( const Entity  entity)

Remove a component from an entity. This also allows the slot used for the component to be free to used for when new components gets added.

Parameters
entity

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