Live Cells C++
Reactive Programming for C++
|
Base class for a cell with a state. More...
#include <stateful_cell.hpp>
Public Member Functions | |
template<typename... Args> | |
stateful_cell (key_ref k, Args... args) | |
Create a stateful cell and associate it with a state. | |
key_ref | key () const |
Get the key identifying the cell. | |
void | add_observer (observer::ref o) const |
Add an observer to the cell. | |
void | remove_observer (observer::ref o) const |
Remove an observer from the cell. | |
Protected Attributes | |
const key_ref | key_ |
Key identifying the cell. | |
std::shared_ptr< S > | state |
Reference to the cell's state. | |
Base class for a cell with a state.
The state is associated with the cell by its key. The cell holds a shared_ptr
to the state. This allows cell objects to be freely copied, and even recreated using the same key, while still pointing to the same shared state.
S is the class which will be used to hold the cell's state.
|
inline |
Create a stateful cell and associate it with a state.
If there is a state associated with key k, it is associated with the constructed cell. Otherwise:
k | The key identifying the cell |
args | Additional arguments to pass to the state constructor. |
|
inline |
Add an observer to the cell.
o | The observer to add. |
|
inline |
Get the key identifying the cell.
|
inline |
Remove an observer from the cell.
o | The observer to remove. |