18#ifndef LIVE_CELLS_DYNAMIC_COMPUTE_CELL_HPP
19#define LIVE_CELLS_DYNAMIC_COMPUTE_CELL_HPP
21#include <unordered_set>
27#include "compute_state.hpp"
28#include "stateful_cell.hpp"
29#include "changes_only_state.hpp"
34 template <std::invocable F>
35 class dynamic_compute_cell_state;
41 template <std::invocable F>
51 std::unordered_set<cell> arguments;
77 if (!arguments.count(
cell)) {
78 arguments.emplace(cell);
80 cell.add_observer(state);
91 template <std::invocable F>
122 for (
auto arg : this->
compute.arguments) {
126 this->
compute.arguments.clear();
135 template <std::invocable F>
152 template <std::invocable F,
typename State = dynamic_compute_cell_state<F>>
197 return this->
state->value();
200 value_type operator()()
const {
static argument_tracker & global()
Definition tracker.hpp:99
Dynamically typed Cell container.
Definition observable.hpp:133
Mixin that modifies a compute_cell_state subclass to only notify its observers if the new value of th...
Definition changes_only_state.hpp:24
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
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 init() override
Definition compute_state.hpp:117
Maintains the state of a dynamic_compute_cell.
Definition dynamic_compute_cell.hpp:92
void init() override
Called before the first observer is added.
Definition dynamic_compute_cell.hpp:107
void pause() override
Called after the last observer is removed.
Definition dynamic_compute_cell.hpp:119
dynamic_compute_cell_state(key_ref key, F compute)
Create a dynamic computed cell state, with a given value computation function.
Definition dynamic_compute_cell.hpp:103
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
dynamic_compute_cell(key_ref key, F compute)
Create a dynamic computed cell with a given value computation function.
Definition dynamic_compute_cell.hpp:193
dynamic_compute_cell(F compute)
Create a dynamic computed cell with a given value computation function.
Definition dynamic_compute_cell.hpp:177
std::invoke_result_t< F > value_type
Shorthand for the type of value held by this cell.
Definition dynamic_compute_cell.hpp:163
A dynamic_compute_cell_state that only notifies the observers of the cell if the new value of the cel...
Definition dynamic_compute_cell.hpp:137
Defines the computation function of the state of a dynamic_compute_cell.
Definition dynamic_compute_cell.hpp:42
dynamic_compute_state(F compute)
Definition dynamic_compute_cell.hpp:67
auto operator()(observer::ref state)
Compute the value of dynamic_compute_cell.
Definition dynamic_compute_cell.hpp:75
Dynamically type key container.
Definition keys.hpp:76
Defines the interface for a key which uniquely identifies a cell.
Definition keys.hpp:33
std::shared_ptr< observer > ref
Shared pointer to an observer.
Definition types.hpp:37
Base class for a cell with a state.
Definition stateful_cell.hpp:42
std::shared_ptr< S > state
Reference to the cell's state.
Definition stateful_cell.hpp:105
A key of uniquely identified by a single instance.
Definition keys.hpp:128
Definition boolean.hpp:26