Manages dynamic component state with type-safe storage.
More...
#include <state.hpp>
|
void | setState (const std::map< std::string, std::any > &newState) |
| Replace the entire state with new values.
|
|
template<typename T > |
T | get (const std::string &key) const |
| Get a state value by key with type casting.
|
|
template<typename T > |
void | set (const std::string &key, const T &value) |
| Set a state value by key.
|
|
void | setOnStateChange (std::function< void()> callback) |
| Register a callback to be called when state changes.
|
|
const std::map< std::string, std::any > & | getData (void) const |
| Get the entire state data map.
|
|
Manages dynamic component state with type-safe storage.
The State class provides a key-value store for component data that can change over time. It supports type-safe getters/setters and callbacks for state changes.
◆ get()
template<typename T >
T State::get |
( |
const std::string & |
key | ) |
const |
|
inline |
Get a state value by key with type casting.
- Template Parameters
-
T | The type to cast the value to |
- Parameters
-
- Returns
- The value cast to type T, or default-constructed T if key doesn't exist
◆ getData()
const std::map< std::string, std::any > & State::getData |
( |
void |
| ) |
const |
|
inline |
Get the entire state data map.
- Returns
- Const reference to the map containing all state key-value pairs
◆ set()
template<typename T >
void State::set |
( |
const std::string & |
key, |
|
|
const T & |
value |
|
) |
| |
|
inline |
Set a state value by key.
- Template Parameters
-
T | The type of the value to store |
- Parameters
-
key | The key to set |
value | The value to store |
◆ setOnStateChange()
void State::setOnStateChange |
( |
std::function< void()> |
callback | ) |
|
|
inline |
Register a callback to be called when state changes.
- Parameters
-
callback | Function to call on state changes |
◆ setState()
void State::setState |
( |
const std::map< std::string, std::any > & |
newState | ) |
|
|
inline |
Replace the entire state with new values.
- Parameters
-
newState | Map of key-value pairs to set as the new state |
The documentation for this class was generated from the following file: