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

Provides functionality for observing a cell from a cell_state. More...

#include <observer_cell_state.hpp>

Inheritance diagram for live_cells::observer_cell_state:

Protected Member Functions

void init_observer_state ()
 Initialize the cell observation state.
 
void pause_observer_state ()
 Pause the cell observation state.
 
void handle_will_update (const std::invocable auto &notify_will_update)
 Handle a observer::will_update call.
 
void handle_will_update (const std::invocable auto &pre_update, const std::invocable auto &notify_will_update)
 Handle a observer::will_update call.
 
void handle_update (bool changed, const std::invocable< bool > auto &notify_update)
 Handle an observer::update call.
 
void handle_update (bool changed, const std::invocable auto &did_change, const std::invocable< bool > auto &notify_update, const std::invocable auto &post_update)
 Handle an observer::update call.
 

Protected Attributes

bool stale = true
 Does the value have to be recomputed?
 
bool updating = false
 Are the argument cells in the process of updating their values?
 

Detailed Description

Provides functionality for observing a cell from a cell_state.

This class provides implementations of observer::will_update and observer::update, namely handle_will_update and handle_update, which determine when the cell's value should be recomputed, and notify the observers of the cell.

Subclasses should check the state member variable. If it is true, the cell's value should be recomputed.

Member Function Documentation

◆ handle_update() [1/2]

void live_cells::observer_cell_state::handle_update ( bool changed,
const std::invocable auto & did_change,
const std::invocable< bool > auto & notify_update,
const std::invocable auto & post_update )
inlineprotected

Handle an observer::update call.

This method notifies the observers of this cell, by calling notify_update.

Attention
This method should be called from observer::update.
Parameters
changedHas the value of the dependency cell changed?
did_changeFunction called with no arguments, to determine whether the value of the cell has changed.

This function should return true if the value of the cell may have changed, false if it is know that the cell value has not changed.
notify_will_updateFunction that notifies the observers of the cell.
The argument passed to this cell is true if the cell's value may have changed or false if it has not changed.
post_updateA function of no arguments that is called after the update cycle ends.

This function is only called if this method is being called for the last dependency cell during this update cycle and the value of this cell has changed.

◆ handle_update() [2/2]

void live_cells::observer_cell_state::handle_update ( bool changed,
const std::invocable< bool > auto & notify_update )
inlineprotected

Handle an observer::update call.

This method notifies the observers of this cell, by calling notify_update.

Attention
This method should be called from observer::update.
Parameters
changedHas the value of the dependency cell changed?
notify_will_updateFunction that notifies the observers of the cell.
The argument passed to this cell is true if the cell's value may have changed or false if it has not changed.

◆ handle_will_update() [1/2]

void live_cells::observer_cell_state::handle_will_update ( const std::invocable auto & notify_will_update)
inlineprotected

Handle a observer::will_update call.

This method notifies the observers of this cell, by calling notify_will_update.

Attention
This method should be called from observer::will_update.
Parameters
notify_will_updateFunction that notifies the observers of the cell.

◆ handle_will_update() [2/2]

void live_cells::observer_cell_state::handle_will_update ( const std::invocable auto & pre_update,
const std::invocable auto & notify_will_update )
inlineprotected

Handle a observer::will_update call.

This method notifies the observers of this cell, by calling notify_will_update.

Attention
This method should be called from observer::will_update.
Parameters
pre_updateA function of no arguments that is called before the update cycle begins.

This function is only called if this method is being called for the first time during the current update cycle.
notify_will_updateFunction that notifies the observers of the cell.

◆ init_observer_state()

void live_cells::observer_cell_state::init_observer_state ( )
inlineprotected

Initialize the cell observation state.

Attention
This should be called from cell_state::init().

◆ pause_observer_state()

void live_cells::observer_cell_state::pause_observer_state ( )
inlineprotected

Pause the cell observation state.

Attention
This should be called from cell_state::pause().

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