23 void setEntry(
const std::string& key,
const T& value) { dataMap.insert_or_assign(key, value); }
33 std::optional<T>
getEntry(std::string key)
const {
34 if (!this->dataMap.contains(key))
return std::nullopt;
35 const std::any& value = this->dataMap.at(key);
36 if (value.type() !=
typeid(T)) {
return std::nullopt; }
37 return std::any_cast<T>(value);
40 std::map<std::string, std::any> dataMap;
DataComponent class to centrally store data about an entity such as stats.
Definition DataComponent.h:11
DataComponent()
The data component only has a default constructor.
Definition DataComponent.h:14
void setEntry(const std::string &key, const T &value)
Set a key-value pair of any type in the data map.
Definition DataComponent.h:23
std::optional< T > getEntry(std::string key) const
Get a value of type T from the data map.
Definition DataComponent.h:33