18#ifndef LIVE_CELLS_COMPUTE_STATE_HPP
19#define LIVE_CELLS_COMPUTE_STATE_HPP
26#include "observable.hpp"
27#include "cell_state.hpp"
28#include "exceptions.hpp"
29#include "observer_cell_state.hpp"
49 template <Computable C>
55 typedef std::invoke_result_t<C,observer::ref>
value_type;
64 template <
typename... Args>
65 requires std::constructible_from<C,Args...>
68 compute(std::forward<Args>(args)...) {}
102 return std::dynamic_pointer_cast<observer>(this->shared_from_this());
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
bool is_active() const
Does the cell have at least one observer?
Definition cell_state.hpp:136
Cell state for a cell which computes a value as a function of one or more argument cells.
Definition compute_state.hpp:50
void pause() override
Called after the last observer is removed.
Definition compute_state.hpp:122
C compute
Compute value function.
Definition compute_state.hpp:95
value_type value()
Retrieve the latest cached value.
Definition compute_state.hpp:76
std::shared_ptr< observer > observer_ptr()
Get an observer::ref for this, that can be passed to add_observer and remove_observer of Cell.
Definition compute_state.hpp:101
void update(const key_ref &k, bool changed) override
Notifies this observer that the value of the Cell identified by k has changed.
Definition compute_state.hpp:111
std::invoke_result_t< C, observer::ref > value_type
Shorthand for computed value type.
Definition compute_state.hpp:55
void init() override
Called before the first observer is added.
Definition compute_state.hpp:117
compute_cell_state(key_ref k, Args &&... args)
Create a computed cell state.
Definition compute_state.hpp:66
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 compute_state.hpp:105
Dynamically type key container.
Definition keys.hpp:76
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
Defines a type that computes a value when the call operator operator() is invoked.
Definition compute_state.hpp:41
Definition boolean.hpp:26
Exception indicating that the value of a cell should not be computed.
Definition exceptions.hpp:33