Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells::mutable_compute_cell_state< T > Class Template Referenceabstract

Maintains the state of a mutable computed cell. More...

#include <mutable_compute_cell_state.hpp>

Inheritance diagram for live_cells::mutable_compute_cell_state< T >:
Collaboration diagram for live_cells::mutable_compute_cell_state< T >:

Public Member Functions

 mutable_compute_cell_state (key_ref key, const std::unordered_set< cell > &arguments)
 Create the state for a mutable computed cell.
 
value ()
 Get the value of the cell.
 
void value (T value)
 Set the value of the cell.
 
void will_update (const key_ref &k) override
 Notifies this observer that the value of the Cell identified by k is going to change.
 
void update (const key_ref &k, bool changed) override
 Notifies this observer that the value of the Cell identified by k has changed.
 
void init () override
 Add this state as an observer to the compute function arguments.
 
void pause () override
 Remove this state from the observers of the compute function arguments.
 
- Public Member Functions inherited from live_cells::mutable_cell_state< T >
 mutable_cell_state (key_ref key, T value)
 Create a mutable cell state with the value initialized to value.
 
value ()
 Get the value of the cell.
 
void value (T value)
 Set the value of the cell and notify its observers.
 
 cell_state (key_ref k)
 Create a cell state with a given key.
 
- Public Member Functions inherited from live_cells::cell_state
 cell_state (key_ref k)
 Create a cell state with a given key.
 
cell_stateoperator= (const cell_state &other)=delete
 
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

virtualcompute ()=0
 Compute the value of the cell as a function of its argument cells.
 
virtual void reverse_compute (T value)=0
 Perform the reverse computation.
 
std::shared_ptr< observerobserver_ptr ()
 Get an observer::ref for this, that can be passed to add_observer() and remove_observer() of the Cell concept.
 
- Protected Member Functions inherited from live_cells::mutable_cell_state< T >
void silent_set (T value)
 Set the cell's value without notifying observers.
 
void add_to_batch ()
 Add this state to the list of mutable cells that were updating during the current batch update.
 
- Protected Member Functions inherited from live_cells::cell_state
bool is_active () const
 Does the cell have at least one observer?
 
- Protected Member Functions inherited from live_cells::observer_cell_state
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

std::unordered_set< cellarguments
 Set of argument cells referenced by the value computation function.
 
bool reverse = false
 Is the value of the cell being set, and hence a reverse computation being performed?
 
bool computed = true
 Is the cell's value the computed value (true) or a value that was set (false).
 
- Protected Attributes inherited from live_cells::cell_state
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.
 
- Protected Attributes inherited from live_cells::observer_cell_state
bool stale = true
 Does the value have to be recomputed?
 
bool updating = false
 Are the argument cells in the process of updating their values?
 

Additional Inherited Members

- Public Types inherited from live_cells::cell_state
typedef std::shared_ptr< cell_stateref
 Shared pointer to a cell_state.
 
- Public Types inherited from live_cells::observer
typedef std::shared_ptr< observerref
 Shared pointer to an observer.
 
- Static Protected Member Functions inherited from live_cells::mutable_cell_state< T >
static bool is_batch_update ()
 Is a batch update of mutable cells currently in effect?
 

Detailed Description

template<typename T>
class live_cells::mutable_compute_cell_state< T >

Maintains the state of a mutable computed cell.

Constructor & Destructor Documentation

◆ mutable_compute_cell_state()

template<typename T >
live_cells::mutable_compute_cell_state< T >::mutable_compute_cell_state ( key_ref key,
const std::unordered_set< cell > & arguments )
inline

Create the state for a mutable computed cell.

Parameters
keyKey identifying the cell.
argumentsSet of argument cells referenced in value computation function.

Member Function Documentation

◆ compute()

template<typename T >
virtual T live_cells::mutable_compute_cell_state< T >::compute ( )
protectedpure virtual

Compute the value of the cell as a function of its argument cells.

Subclasses should override this method with a method that performs the computation logic for the cell.

Returns
The computed value

Implemented in live_cells::dynamic_mutable_compute_cell_state< F, R, ValueType >, and live_cells::static_mutable_compute_cell_state< F, R >.

◆ init()

template<typename T >
void live_cells::mutable_compute_cell_state< T >::init ( )
inlineoverridevirtual

Add this state as an observer to the compute function arguments.

Reimplemented from live_cells::cell_state.

◆ observer_ptr()

template<typename T >
std::shared_ptr< observer > live_cells::mutable_compute_cell_state< T >::observer_ptr ( )
inlineprotected

Get an observer::ref for this, that can be passed to add_observer() and remove_observer() of the Cell concept.

Returns
Shared pointer to this state

◆ pause()

template<typename T >
void live_cells::mutable_compute_cell_state< T >::pause ( )
inlineoverridevirtual

Remove this state from the observers of the compute function arguments.

Reimplemented from live_cells::cell_state.

◆ reverse_compute()

template<typename T >
virtual void live_cells::mutable_compute_cell_state< T >::reverse_compute ( T value)
protectedpure virtual

Perform the reverse computation.

This method is called when the value of the cell is set explicitly.

Subclasses should override this method with a method that sets the values of the argument cells such that the value that is returned by compute() is equal to value.

Parameters
valueThe assigned cell value.

Implemented in live_cells::static_mutable_compute_cell_state< F, R >.

◆ update()

template<typename T >
void live_cells::mutable_compute_cell_state< T >::update ( const key_ref & k,
bool did_change )
inlineoverridevirtual

Notifies this observer that the value of the Cell identified by k has changed.

Parameters
kidentifying observable
did_changetrue if the value of the cell may have changed, false if it is know that it hasn't changed.

Implements live_cells::observer.

◆ value() [1/2]

template<typename T >
T live_cells::mutable_compute_cell_state< T >::value ( )
inline

Get the value of the cell.

Returns
The value of the cell.

◆ value() [2/2]

template<typename T >
void live_cells::mutable_compute_cell_state< T >::value ( T value)
inline

Set the value of the cell.

Parameters
valueThe new value.

◆ will_update()

template<typename T >
void live_cells::mutable_compute_cell_state< T >::will_update ( const key_ref & k)
inlineoverridevirtual

Notifies this observer that the value of the Cell identified by k is going to change.

Parameters
kidentifying observable

Implements live_cells::observer.


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