1#ifndef LIVE_CELLS_PREVIOUS_VALUE_CELL_HPP
2#define LIVE_CELLS_PREVIOUS_VALUE_CELL_HPP
5#include "stateful_cell.hpp"
6#include "cell_state.hpp"
7#include "observer_cell_state.hpp"
9#include "exceptions.hpp"
29 typedef typename C::value_type value_type;
42 current_value(
maybe<value_type>::wrap([
cell] {
56 update_current_value();
59 return prev_value.
unwrap();
97 update_current_value();
127 std::shared_ptr<observer> observer_ptr() {
137 void update_current_value() {
142 if (current_value == next_value) {
147 prev_value = current_value;
148 current_value = next_value;
196 return this->
state->value();
static argument_tracker & global()
Definition tracker.hpp:99
Maintains the state of a stateful cell.
Definition cell_state.hpp:43
virtual void notify_will_update()
Notify the observers that the cell's value will change.
Definition live_cells.cpp:76
virtual void notify_update(bool did_change=true)
Notify the observers that the cell's value has changed.
Definition live_cells.cpp:92
virtual void init()
Called before the first observer is added.
Definition cell_state.hpp:68
virtual void pause()
Called after the last observer is removed.
Definition cell_state.hpp:79
Dynamically typed Cell container.
Definition observable.hpp:133
T value() const
Get the value held by the underlying Cell.
Definition observable.hpp:197
void remove_observer(observer::ref obs)
Remove an observer from the underlying Cell.
Definition observable.hpp:172
void add_observer(observer::ref obs)
Add an observer to the underlying Cell.
Definition observable.hpp:159
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
Dynamically type key container.
Definition keys.hpp:76
Defines the interface for a key which uniquely identifies a cell.
Definition keys.hpp:33
Container holding a cell value or an exception that occurred while computing a value.
Definition maybe.hpp:17
static maybe< T > wrap(const std::invocable auto &f)
Create a maybe holding the result of calling f.
Definition maybe.hpp:81
T unwrap() const
Get the value or throw the exception stored in this container.
Definition maybe.hpp:96
Provides functionality for observing a cell from a cell_state.
Definition observer_cell_state.hpp:21
void init_observer_state()
Initialize the cell observation state.
Definition observer_cell_state.hpp:40
void handle_will_update(const std::invocable auto ¬ify_will_update)
Handle a observer::will_update call.
Definition observer_cell_state.hpp:66
void pause_observer_state()
Pause the cell observation state.
Definition observer_cell_state.hpp:50
bool stale
Does the value have to be recomputed?
Definition observer_cell_state.hpp:26
void handle_update(bool changed, const std::invocable< bool > auto ¬ify_update)
Handle an observer::update call.
Definition observer_cell_state.hpp:120
Defines the interface for observing changes to the value of a Cell.
Definition types.hpp:32
Maintains the state of a previous_value_cell.
Definition previous_value_cell.hpp:25
previous_value_cell_state(key_ref k, C cell)
Create a previous_value_cell state.
Definition previous_value_cell.hpp:38
void pause() override
Called after the last observer is removed.
Definition previous_value_cell.hpp:74
void init() override
Called before the first observer is added.
Definition previous_value_cell.hpp:63
void will_update(const key_ref &k) override
Notifies this observer that the value of the Cell identified by k is going to change.
Definition previous_value_cell.hpp:84
value_type value()
Get the stored previous value.
Definition previous_value_cell.hpp:54
void update(const key_ref &k, bool changed) override
Notifies this observer that the value of the Cell identified by k has changed.
Definition previous_value_cell.hpp:90
A Cell that evaluates to the previous value of another Cell.
Definition previous_value_cell.hpp:162
value_type value() const
Get the value of the cell.
Definition previous_value_cell.hpp:195
previous_value_cell(const C &cell)
Create a cell that evaluates to the previous value of cell.
Definition previous_value_cell.hpp:186
value_type operator()() const
Get the value of the cell and track it as a dependency.
Definition previous_value_cell.hpp:205
C::value_type value_type
The cell's value type.
Definition previous_value_cell.hpp:178
Base class for a cell with a state.
Definition stateful_cell.hpp:42
std::shared_ptr< previous_value_cell_state< C > > state
Reference to the cell's state.
Definition stateful_cell.hpp:105
Base class for a key distinguished from other keys by one or more values.
Definition keys.hpp:147
Defines the cell protocol.
Definition types.hpp:128
constexpr auto previous
Operator for creating a cell that evaluates to the previous value of another cell.
Definition previous_value_cell.hpp:247
Definition boolean.hpp:26
auto previous(const C &cell)
Create a Cell that evaluates to the previous value of cell.
Definition previous_value_cell.hpp:232
Key identifying a previous_value_cell.
Definition previous_value_cell.hpp:17