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

A mutable computed cell with arguments determined at compile-time. More...

#include <static_mutable_compute_cell.hpp>

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

Public Types

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

Public Member Functions

template<typename T , typename U , typename... Args>
 static_mutable_compute_cell (key_ref k, T &&compute, U &&reverse, Args &&... args)
 Create a static mutable computed cell.
 
template<typename T , typename U , typename... Args>
 static_mutable_compute_cell (T &&compute, U &&reverse, Args &&... args)
 Create a static mutable computed cell.
 
value_type value () const
 Get the value of the cell.
 
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
 Get the value of the cell and track it as a dependency.
 
- 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 = static_mutable_compute_cell_state<F,R>>
class live_cells::static_mutable_compute_cell< F, R, State >

A mutable computed cell with arguments determined at compile-time.

Constructor & Destructor Documentation

◆ static_mutable_compute_cell() [1/2]

template<std::invocable F, typename R , typename State = static_mutable_compute_cell_state<F,R>>
template<typename T , typename U , typename... Args>
live_cells::static_mutable_compute_cell< F, R, State >::static_mutable_compute_cell ( key_ref k,
T && compute,
U && reverse,
Args &&... args )
inline

Create a static mutable computed cell.

Parameters
kKey identifying cell
computeCompute value function.
This function is called with no arguments to compute the value of the cell.
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.
argsArguments to compute

◆ static_mutable_compute_cell() [2/2]

template<std::invocable F, typename R , typename State = static_mutable_compute_cell_state<F,R>>
template<typename T , typename U , typename... Args>
live_cells::static_mutable_compute_cell< F, R, State >::static_mutable_compute_cell ( T && compute,
U && reverse,
Args &&... args )
inline

Create a static mutable computed cell.

Parameters
computeCompute value function.
This function is called with no arguments to compute the value of the cell.
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.
argsArguments to compute

Member Function Documentation

◆ operator()()

template<std::invocable F, typename R , typename State = static_mutable_compute_cell_state<F,R>>
value_type live_cells::static_mutable_compute_cell< F, R, State >::operator() ( ) const
inline

Get the value of the cell and track it as a dependency.

Returns
The value.

◆ operator=() [1/2]

template<std::invocable F, typename R , typename State = static_mutable_compute_cell_state<F,R>>
value_type live_cells::static_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 = static_mutable_compute_cell_state<F,R>>
value_type live_cells::static_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() [1/2]

template<std::invocable F, typename R , typename State = static_mutable_compute_cell_state<F,R>>
value_type live_cells::static_mutable_compute_cell< F, R, State >::value ( ) const
inline

Get the value of the cell.

Returns
The value.

◆ value() [2/2]

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

Set the value of the cell.

This method triggers 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.
Parameters
valueThe new value

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