Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells::cell_state Class Reference

Maintains the state of a stateful cell. More...

#include <cell_state.hpp>

Inheritance diagram for live_cells::cell_state:
Collaboration diagram for live_cells::cell_state:

Public Types

typedef std::shared_ptr< cell_stateref
 Shared pointer to a cell_state.
 

Public Member Functions

 cell_state (key_ref k)
 Create a cell state with a given key.
 
cell_stateoperator= (const cell_state &other)=delete
 
virtual void init ()
 Called before the first observer is added.
 
virtual void pause ()
 Called after the last observer is removed.
 
virtual void add_observer (observer::ref o)
 Add an observer to the cell's set of observers.
 
virtual void remove_observer (observer::ref o)
 Remove an observer from the cell's set of observers.
 
virtual void notify_will_update ()
 Notify the observers that the cell's value will change.
 
virtual void notify_update (bool did_change=true)
 Notify the observers that the cell's value has changed.
 

Protected Member Functions

bool is_active () const
 Does the cell have at least one observer?
 

Protected Attributes

key_ref key_
 Key identifying the cell corresponding to this state.
 
std::unordered_map< observer::ref, std::size_t > observers
 The set of observers observing changes to the values in the cell corresponding to this state.
 

Detailed Description

Maintains the state of a stateful cell.

The state consists of the cell's observers and its value. The base class provides functionality for keeping track of observers added to the cell.

This object is intended to be held in an std::shared_ptr with a single instance per unique cell key. Multiple cell objects with same key reference the same cell_state.

A state is created when the first stateful cell with a given key is created, and is destroyed when the last cell with the given key is destroyed.

Constructor & Destructor Documentation

◆ cell_state()

live_cells::cell_state::cell_state ( key_ref k)
inline

Create a cell state with a given key.

Parameters
kThe key

Member Function Documentation

◆ add_observer()

void live_cells::cell_state::add_observer ( observer::ref o)
virtual

Add an observer to the cell's set of observers.

Parameters
oThe observer to add

◆ init()

virtual void live_cells::cell_state::init ( )
inlinevirtual

◆ is_active()

bool live_cells::cell_state::is_active ( ) const
inlineprotected

Does the cell have at least one observer?

Returns
true if the cell has at least one observer.

◆ notify_update()

void live_cells::cell_state::notify_update ( bool did_change = true)
virtual

Notify the observers that the cell's value has changed.

This should be called after the value has been changed.

Parameters
did_changeTrue if the value of the cell may have changed, false if it is known that the value of the cell has not changed.

◆ notify_will_update()

void live_cells::cell_state::notify_will_update ( )
virtual

Notify the observers that the cell's value will change.

This should be called before the value is changed.

◆ pause()

◆ remove_observer()

void live_cells::cell_state::remove_observer ( observer::ref o)
virtual

Remove an observer from the cell's set of observers.

Like the remove_observer method of the Cell concept, this method should be called the same number of times, for a given observer o, as add_observer() was called, before the observer is actually removed.

Parameters
oThe observer to remove

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