Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells::stateful_cell< S > Class Template Reference

Base class for a cell with a state. More...

#include <stateful_cell.hpp>

Inheritance diagram for live_cells::stateful_cell< S >:
Collaboration diagram for live_cells::stateful_cell< S >:

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< Sstate
 Reference to the cell's state.
 

Detailed Description

template<typename S>
class live_cells::stateful_cell< S >

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.

Warning
This class may be inherited but it is not meant to be used polymorphically.

Constructor & Destructor Documentation

◆ stateful_cell()

template<typename S >
template<typename... Args>
live_cells::stateful_cell< S >::stateful_cell ( key_ref k,
Args... args )
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:

  1. A new state is created by calling the constructor of S, passing the key k followed by args.
  2. The state is associated with key k.
  3. The state is associated with the constructed cell.
Parameters
kThe key identifying the cell
argsAdditional arguments to pass to the state constructor.

Member Function Documentation

◆ add_observer()

template<typename S >
void live_cells::stateful_cell< S >::add_observer ( observer::ref o) const
inline

Add an observer to the cell.

Parameters
oThe observer to add.

◆ key()

template<typename S >
key_ref live_cells::stateful_cell< S >::key ( ) const
inline

Get the key identifying the cell.

Returns
The key identifying the cell

◆ remove_observer()

template<typename S >
void live_cells::stateful_cell< S >::remove_observer ( observer::ref o) const
inline

Remove an observer from the cell.

Parameters
oThe observer to remove.

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