18#ifndef LIVE_CELLS_MUTABLE_DEPENDENT_CELL_HPP
19#define LIVE_CELLS_MUTABLE_DEPENDENT_CELL_HPP
23#include <unordered_set>
25#include "observable.hpp"
26#include "mutable_cell.hpp"
27#include "exceptions.hpp"
28#include "observer_cell_state.hpp"
77 return parent::value();
104 if (parent::is_batch_update()) {
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
bool is_active() const
Does the cell have at least one observer?
Definition cell_state.hpp:136
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
Maintains the state of a mutable_cell.
Definition mutable_cell.hpp:78
void add_to_batch()
Add this state to the list of mutable cells that were updating during the current batch update.
Definition mutable_cell.hpp:145
void silent_set(T value)
Set the cell's value without notifying observers.
Definition mutable_cell.hpp:128
Maintains the state of a mutable computed cell.
Definition mutable_compute_cell_state.hpp:39
void value(T value)
Set the value of the cell.
Definition mutable_compute_cell_state.hpp:85
std::unordered_set< cell > arguments
Set of argument cells referenced by the value computation function.
Definition mutable_compute_cell_state.hpp:166
std::shared_ptr< observer > observer_ptr()
Get an observer::ref for this, that can be passed to add_observer() and remove_observer() of the Cell...
Definition mutable_compute_cell_state.hpp:212
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 mutable_compute_cell_state.hpp:114
bool reverse
Is the value of the cell being set, and hence a reverse computation being performed?
Definition mutable_compute_cell_state.hpp:172
void init() override
Add this state as an observer to the compute function arguments.
Definition mutable_compute_cell_state.hpp:132
virtual T compute()=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.
bool computed
Is the cell's value the computed value (true) or a value that was set (false).
Definition mutable_compute_cell_state.hpp:178
void update(const key_ref &k, bool changed) override
Notifies this observer that the value of the Cell identified by k has changed.
Definition mutable_compute_cell_state.hpp:122
void pause() override
Remove this state from the observers of the compute function arguments.
Definition mutable_compute_cell_state.hpp:152
T value()
Get the value of the cell.
Definition mutable_compute_cell_state.hpp:63
mutable_compute_cell_state(key_ref key, const std::unordered_set< cell > &arguments)
Create the state for a mutable computed cell.
Definition mutable_compute_cell_state.hpp:54
Provides functionality for observing a cell from a cell_state.
Definition observer_cell_state.hpp:21
bool updating
Are the argument cells in the process of updating their values?
Definition observer_cell_state.hpp:32
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
Definition boolean.hpp:26
void batch(F fn)
Batch changes to the values of mutable cells.
Definition mutable_cell.hpp:307
Exception indicating that the value of a cell should not be computed.
Definition exceptions.hpp:33