Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
stateful_cell.hpp
1/*
2 * live_cells_cpp
3 * Copyright (C) 2024 Alexander Gutev <alex.gutev@gmail.com>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you
6 * may not use this file except in compliance with the License. You
7 * may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 */
17
18#ifndef LIVE_CELLS_STATEFUL_CELL_HPP
19#define LIVE_CELLS_STATEFUL_CELL_HPP
20
21#include <memory>
22
23#include "observable.hpp"
24#include "cell_state.hpp"
25
26namespace live_cells {
27
41 template <typename S>
43 public:
63 template <typename... Args>
65 key_(k),
66 state(state_manager::global().get<S>(k, args...)) {
67 }
68
74 key_ref key() const {
75 return key_;
76 }
77
85 }
86
95
96 protected:
101
105 std::shared_ptr<S> state;
106 };
107
108} // live_cells
109
110#endif /* LIVE_CELLS_STATEFUL_CELL_HPP */
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
Dynamically type key container.
Definition keys.hpp:76
std::shared_ptr< observer > ref
Shared pointer to an observer.
Definition types.hpp:37
Maintains the association between keys and cell states.
Definition cell_state.hpp:164
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
void add_observer(observer::ref o) const
Add an observer to the cell.
Definition stateful_cell.hpp:83
key_ref key() const
Get the key identifying the cell.
Definition stateful_cell.hpp:74
stateful_cell(key_ref k, Args... args)
Create a stateful cell and associate it with a state.
Definition stateful_cell.hpp:64
const key_ref key_
Key identifying the cell.
Definition stateful_cell.hpp:100
void remove_observer(observer::ref o) const
Remove an observer from the cell.
Definition stateful_cell.hpp:92
Definition boolean.hpp:26