TailorMade 2.0
Tailor Made is a high-performance C++20 ECS library with on-the-fly entity creation and JSON-based definitions for entities, components, and their relationships.
 
Loading...
Searching...
No Matches
ComponentManager Class Reference

#include <ComponentManager.h>

Public Member Functions

 ComponentManager (const std::string &filename)
 The main constructor of the ComponentManager, created the components based of the file's description.
 
 ComponentManager (std::shared_ptr< Component > component)
 Create a ComponentManager with a reference component.
 
const std::string & getName ()
 Return the name of the component managed by this instance.
 
const std::string & getType (const std::string &data)
 Return a string which give the type of the data.
 
void subscribe (int entity)
 Subscribe an entity to this component.
 
void subscribe (int entity, dataVector data)
 Subscribe an entity to this component with specific values.
 
void unsubscribe (int entity)
 Remove the link between an entity and its component.
 
std::vector< int > getEntities (bool checkState)
 Return the list of entities linked in this component's manager.
 
std::shared_ptr< ComponentgetComponent (int entity)
 Return the component of a specific entity.
 
bool hasEntity (int entity)
 Return true if the given entity possess this component, false otherwise.
 
bool getState (int entity)
 Return the actual state of the given entity's component, true or false.
 
void setState (int entity, bool newState)
 Set the state of the given entity's component.
 
void give (int giver, int receiver, bool copy)
 Give the ownership, or make a copy, of an entity's component to another component.
 
void toString (std::ostream &stream)
 Add to the given buffer, the serialized version of this ComponentManager, which will consist of the list of entities' ID + their components data.
 

Constructor & Destructor Documentation

◆ ComponentManager() [1/2]

ComponentManager::ComponentManager ( const std::string & filename)

The main constructor of the ComponentManager, created the components based of the file's description.

Parameters
filenameFull path towards the component's file.

◆ ComponentManager() [2/2]

ComponentManager::ComponentManager ( std::shared_ptr< Component > component)

Create a ComponentManager with a reference component.

The resulting file will be named after the component's name.

Useful when you making on-the-fly components creation.

Parameters
componentThe reference component of this manager, a copy will be created.

Member Function Documentation

◆ getComponent()

std::shared_ptr< Component > ComponentManager::getComponent ( int entity)

Return the component of a specific entity.

Parameters
entityThe ID of the entity.

◆ getEntities()

std::vector< int > ComponentManager::getEntities ( bool checkState)

Return the list of entities linked in this component's manager.

checkState will tell this method if you want the state of the entities' components to be verify, entities with a state at "false" will not be returned.

Parameters
intcheckState

◆ getName()

const std::string & ComponentManager::getName ( )

Return the name of the component managed by this instance.

◆ getState()

bool ComponentManager::getState ( int entity)

Return the actual state of the given entity's component, true or false.

Parameters
entityThe ID of the entity.

◆ getType()

const std::string & ComponentManager::getType ( const std::string & data)

Return a string which give the type of the data.

Wrapper of the component's method for the save action.

Parameters
dataData's name.

◆ give()

void ComponentManager::give ( int giver,
int receiver,
bool copy )

Give the ownership, or make a copy, of an entity's component to another component.

Parameters
giverThe ID of the entity which give its component.
receiverThe ID of the entity which take the component.
copyIf true the component is just copied, otherwise the giver doesn't have the component anymore.

◆ hasEntity()

bool ComponentManager::hasEntity ( int entity)

Return true if the given entity possess this component, false otherwise.

Parameters
entityThe ID of the entity.

◆ setState()

void ComponentManager::setState ( int entity,
bool newState )

Set the state of the given entity's component.

Parameters
entityThe ID of the entity.
newStateThe entity's component new state.

◆ subscribe() [1/2]

void ComponentManager::subscribe ( int entity)

Subscribe an entity to this component.

Will give this entity's component the default values of its data's types.

Parameters
entityThe ID of the entity to subscribe.

◆ subscribe() [2/2]

void ComponentManager::subscribe ( int entity,
dataVector data )

Subscribe an entity to this component with specific values.

Parameters
entityThe ID of the entity to subscribe.
dataA vector with the data's names and values.
See also
dataVector

◆ toString()

void ComponentManager::toString ( std::ostream & stream)

Add to the given buffer, the serialized version of this ComponentManager, which will consist of the list of entities' ID + their components data.

Parameters
streamThe stream on which the serialized version of the ComponentManager is append to.

◆ unsubscribe()

void ComponentManager::unsubscribe ( int entity)

Remove the link between an entity and its component.

Parameters
entityThe ID of the entity to unsubscribe.

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