Guillaume 1.0.0
Guillaume.
Loading...
Searching...
No Matches
State Class Reference

Manages dynamic component state with type-safe storage. More...

#include <state.hpp>

Public Member Functions

void setState (const std::map< std::string, std::any > &newState)
 Replace the entire state with new values.
 
template<typename 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.
 

Detailed Description

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.

Member Function Documentation

◆ get()

template<typename T >
T State::get ( const std::string &  key) const
inline

Get a state value by key with type casting.

Template Parameters
TThe type to cast the value to
Parameters
keyThe key to retrieve
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
TThe type of the value to store
Parameters
keyThe key to set
valueThe value to store

◆ setOnStateChange()

void State::setOnStateChange ( std::function< void()>  callback)
inline

Register a callback to be called when state changes.

Parameters
callbackFunction 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
newStateMap of key-value pairs to set as the new state

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