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
Component Class Reference

#include <Component.h>

Public Member Functions

 Component ()=default
 
 Component (const std::string &filename)
 Constructor of the component from a file.
 
 Component (const std::string &name, dataUnMap dataDump)
 Constructor of the component from its name and data.
 
void copy (std::shared_ptr< Component > component)
 Copy the information of the given component in the current one.
 
const std::string & getName ()
 Return the component's name.
 
const std::string & getType (const std::string &name)
 Return a string with the type of the given data (or "" if the data doesn't exist).
 
std::vector< std::string > getNames ()
 Return a vector with the names of every data from this component.
 
const dataUnMapgetRawData ()
 Return a const reference of the component's data structure.
 
void toString (std::ostream &stream)
 Append to the given stream a serialized version of the data.
 
template<typename Type>
Type get (const std::string &name)
 Return the value of the data from its name and type.
 
template<typename Type>
void set (const std::string &name, Type value)
 Set the value of the desired data with the given value.
 
void add (const std::string &name, const std::string &type)
 Add a new data to the component.
 

Protected Attributes

std::string componentName
 The name of the component.
 
dataUnMap dataMap
 Link the data's name to the pair <type, value> in an unordered_map.
 
std::mutex mtx
 Lock used by the components, let them the possibility to be used in thread.
 

Constructor & Destructor Documentation

◆ Component() [1/3]

Component::Component ( )
default

◆ Component() [2/3]

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

Constructor of the component from a file.

Parameters
filenameFull path towards the component's file.

◆ Component() [3/3]

Component::Component ( const std::string & name,
dataUnMap dataDump )

Constructor of the component from its name and data.

Parameters
nameName of the component.
dataData of the component.
See also
dataUnMap

Member Function Documentation

◆ add()

void Component::add ( const std::string & name,
const std::string & type )

Add a new data to the component.

Convert automatically the serialized type to the real data.

The data is set with the default value of the given type.

Parameters
nameData's name.
typeSerialized version of the data's type.

◆ copy()

void Component::copy ( std::shared_ptr< Component > component)

Copy the information of the given component in the current one.

Easy way to clone a component's data towards a new one.

Parameters
componentA shared_ptr towards the component you want as the model.

◆ get()

template<typename Type>
Type Component::get ( const std::string & name)
inline

Return the value of the data from its name and type.

That's a generic function.

Warning
It's on you to give the right type when you call this method.
Parameters
nameData's name.

◆ getName()

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

Return the component's name.

◆ getNames()

std::vector< std::string > Component::getNames ( )

Return a vector with the names of every data from this component.

◆ getRawData()

const dataUnMap & Component::getRawData ( )

Return a const reference of the component's data structure.

Can be used for serialization of the data or to make a copy of the component.

◆ getType()

const std::string & Component::getType ( const std::string & name)

Return a string with the type of the given data (or "" if the data doesn't exist).

Parameters
nameData's name.

◆ set()

template<typename Type>
void Component::set ( const std::string & name,
Type value )
inline

Set the value of the desired data with the given value.

That's a generic function.

Parameters
nameData's name.
valueData's value.

◆ toString()

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

Append to the given stream a serialized version of the data.

Useful for debugging or logging.

Parameters
streamThe stream on which the informations should be append.

Member Data Documentation

◆ componentName

std::string Component::componentName
protected

The name of the component.

◆ dataMap

dataUnMap Component::dataMap
protected

Link the data's name to the pair <type, value> in an unordered_map.

◆ mtx

std::mutex Component::mtx
protected

Lock used by the components, let them the possibility to be used in thread.


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