Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells::dynamic_mutable_compute_cell< F, R, State > Class Template Reference

A mutable computed cell with the argument cells determined dynamically. More...

#include <dynamic_mutable_compute_cell.hpp>

Inheritance diagram for live_cells::dynamic_mutable_compute_cell< F, R, State >:
Collaboration diagram for live_cells::dynamic_mutable_compute_cell< F, R, State >:

Public Types

typedef std::invoke_result_t< F > value_type
 Shorthand for the type of value held by this cell.
 

Public Member Functions

template<typename T , typename U >
 dynamic_mutable_compute_cell (key_ref k, T &&compute, U &&reverse)
 Create a dynamic mutable computed cell.
 
template<typename T , typename U >
 dynamic_mutable_compute_cell (T &&compute, U &&reverse)
 Create a dynamic mutable computed cell.
 
value_type value () const
 
void value (value_type value) const
 Set the value of the cell.
 
value_type operator= (const value_type &value)
 Set the value of the cell to value.
 
value_type operator= (const value_type &value) const
 Set the value of the cell.
 
value_type operator() () const
 
- Public Member Functions inherited from live_cells::stateful_cell< S >
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.
 

Additional Inherited Members

- Protected Attributes inherited from live_cells::stateful_cell< S >
const key_ref key_
 Key identifying the cell.
 
std::shared_ptr< Sstate
 Reference to the cell's state.
 

Detailed Description

template<std::invocable F, typename R, typename State = dynamic_mutable_compute_cell_state<F,R>>
class live_cells::dynamic_mutable_compute_cell< F, R, State >

A mutable computed cell with the argument cells determined dynamically.

Constructor & Destructor Documentation

◆ dynamic_mutable_compute_cell() [1/2]

template<std::invocable F, typename R , typename State = dynamic_mutable_compute_cell_state<F,R>>
template<typename T , typename U >
live_cells::dynamic_mutable_compute_cell< F, R, State >::dynamic_mutable_compute_cell ( key_ref k,
T && compute,
U && reverse )
inline

Create a dynamic mutable computed cell.

Parameters
kKey identifying cell
computeCompute value function.
This function should compute the cell's value as a function of the cells in args.
reverseReverse computation function.
This function should set the values of the cells in args, such that compute returns the same value as the value that was assigned to the cell, which is passed to this function.

◆ dynamic_mutable_compute_cell() [2/2]

template<std::invocable F, typename R , typename State = dynamic_mutable_compute_cell_state<F,R>>
template<typename T , typename U >
live_cells::dynamic_mutable_compute_cell< F, R, State >::dynamic_mutable_compute_cell ( T && compute,
U && reverse )
inline

Create a dynamic mutable computed cell.

Parameters
computeCompute value function.
This function should compute the cell's value as a function of the cells in args.
reverseReverse computation function.
This function should set the values of the cells in args, such that compute returns the same value as the value that was assigned to the cell, which is passed to this function.

Member Function Documentation

◆ operator=() [1/2]

template<std::invocable F, typename R , typename State = dynamic_mutable_compute_cell_state<F,R>>
value_type live_cells::dynamic_mutable_compute_cell< F, R, State >::operator= ( const value_type & value)
inline

Set the value of the cell to value.

Note
Implemented using C::value(value).

This method triggers the reverse computation function of the cell.

Parameters
valueThe new value of the cell
Returns
value

◆ operator=() [2/2]

template<std::invocable F, typename R , typename State = dynamic_mutable_compute_cell_state<F,R>>
value_type live_cells::dynamic_mutable_compute_cell< F, R, State >::operator= ( const value_type & value) const
inline

Set the value of the cell.

This is equivalent to \prop value(value).

This method triggers the reverse computation function of the cell.

Note
This const version is provided to allow setting the value of a mutable cell within a lambda provided for the reverse computation function of a mutable computed cell.
Parameters
valueThe new value
Returns
value

◆ value()

template<std::invocable F, typename R , typename State = dynamic_mutable_compute_cell_state<F,R>>
void live_cells::dynamic_mutable_compute_cell< F, R, State >::value ( value_type value) const
inline

Set the value of the cell.

This method calls the reverse computation function of the cell.

Note
This method is marked const to allow the value of the cell to be set when it is copy-captured by a lambda.

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