Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
merged_observable.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_MERGED_OBSERVABLE_HPP
19#define LIVE_CELLS_MERGED_OBSERVABLE_HPP
20
21namespace live_cells {
22
30 template <Cell T, Cell... Ts>
32 public:
33
44 merged_observable(T first, Ts... rest) :
45 first(first),
46 rest(rest...) {}
47
54 first.add_observer(o);
55 rest.add_observer(o);
56 }
57
64 first.remove_observer(o);
65 rest.remove_observer(o);
66 }
67
68 private:
69 T first;
70 merged_observable<Ts...> rest;
71 };
72
73 template <Cell T>
75 public:
76
77 merged_observable(T o) : first(o) {}
78
79 void add_observer(observer::ref o) const {
80 first.add_observer(o);
81 }
82
83 void remove_observer(observer::ref o) const {
84 first.remove_observer(o);
85 }
86
87 private:
88 T first;
89 };
90
91
92} // live_cells
93
94#endif /* LIVE_CELLS_MERGED_OBSERVABLE_HPP */
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
Allows multiple cells to be observed at once.
Definition merged_observable.hpp:31
merged_observable(T first, Ts... rest)
Create a merged_observable that adds observers to the cells first and rest... into.
Definition merged_observable.hpp:44
void remove_observer(observer::ref o) const
Definition merged_observable.hpp:63
void add_observer(observer::ref o) const
Definition merged_observable.hpp:53
std::shared_ptr< observer > ref
Shared pointer to an observer.
Definition types.hpp:37
Definition boolean.hpp:26