VEGO-Engine  0.1
Loading...
Searching...
No Matches
DataComponent Class Reference

DataComponent class to centrally store data about an entity such as stats. More...

#include <DataComponent.h>

Public Member Functions

 DataComponent ()
 The data component only has a default constructor.
 
template<typename T>
void setEntry (const std::string &key, const T &value)
 Set a key-value pair of any type in the data map.
 
template<typename T>
std::optional< T > getEntry (std::string key) const
 Get a value of type T from the data map.
 

Detailed Description

DataComponent class to centrally store data about an entity such as stats.

Member Function Documentation

◆ getEntry()

template<typename T>
std::optional< T > DataComponent::getEntry ( std::string key) const
inline

Get a value of type T from the data map.

e.g.

getEntry<int>("speed").value();
std::optional< T > getEntry(std::string key) const
Get a value of type T from the data map.
Definition DataComponent.h:33

in this case the key is "speed" and the value is returned as an integer

the value() or value_or() is NEEDED to handle the optional return type

Parameters
keyThe name to retrieve the value from
Returns
An optional of type T containing the value if it exists and matches in typeid, otherwise std::nullopt

◆ setEntry()

template<typename T>
void DataComponent::setEntry ( const std::string & key,
const T & value )
inline

Set a key-value pair of any type in the data map.

e.g.

setEntry("speed", 180);
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

in this case the key is "speed" and the value is set to an integer of 180

Parameters
keyThe name to store the value under
valueThe value to store of type T

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