46 void copy(std::shared_ptr<Component> component);
57 const std::string&
getType(
const std::string& name);
83 template<
typename Type>
84 Type
get(
const std::string& name);
92 template<
typename Type>
93 void set(
const std::string& name, Type value);
102 void add(
const std::string& name,
const std::string& type);
124 std::string placeholder;
127template<
typename Type>
129 std::scoped_lock lock(
mtx);
133 throw std::runtime_error(
"Error : no data with the name \"" + name +
"\".");
136 std::variant<ECS_Types> data =
dataMap[name].second;
137 return std::get<Type>(data);
139 catch (std::exception& e) {
140 std::cerr <<
"Component : " << e.what() << std::endl;
144template<
typename Type>
146 std::scoped_lock lock(
mtx);
150 throw std::runtime_error(
"Error : no data with the name \"" + name +
"\".");
154 catch (std::exception& e) {
155 std::cerr <<
"Component : " << e.what() << std::endl;
void set(const std::string &name, Type value)
Set the value of the desired data with the given value.
Definition Component.h:145
std::vector< std::string > getNames()
Return a vector with the names of every data from this component.
Component(const std::string &name, dataUnMap dataDump)
Constructor of the component from its name and data.
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).
void toString(std::ostream &stream)
Append to the given stream a serialized version of the data.
const dataUnMap & getRawData()
Return a const reference of the component's data structure.
std::mutex mtx
Lock used by the components, let them the possibility to be used in thread.
Definition Component.h:118
dataUnMap dataMap
Link the data's name to the pair <type, value> in an unordered_map.
Definition Component.h:113
void add(const std::string &name, const std::string &type)
Add a new data to the component.
Component(const std::string &filename)
Constructor of the component from a file.
const std::string & getName()
Return the component's name.
void copy(std::shared_ptr< Component > component)
Copy the information of the given component in the current one.
Type get(const std::string &name)
Return the value of the data from its name and type.
Definition Component.h:128
std::string componentName
The name of the component.
Definition Component.h:108