OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
node_executors.hpp
1#pragma once
3#include <ossia/dataflow/graph/graph_utils.hpp>
4
5namespace ossia
6{
7struct node_exec
8{
9 execution_state*& g;
10
11 void operator()(graph_node& node)
12 try
13 {
14 if(node.enabled())
15 {
16 assert(graph_util::can_execute(node, *g));
17 graph_util::exec_node(node, *g);
18 }
19 }
20 catch(...)
21 {
22 ossia::logger().error("Error while executing a node");
23 }
24};
25struct node_exec_bench
26{
27 execution_state*& g;
28 bench_map& perf;
29
30 void operator()(graph_node& node)
31 try
32 {
33 if(perf.measure)
34 {
35 if(node.enabled())
36 {
37 assert(graph_util::can_execute(node, *g));
38
39 auto t0 = std::chrono::steady_clock::now();
40 graph_util::exec_node(node, *g);
41 auto t1 = std::chrono::steady_clock::now();
42 perf[&node]
43 = std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0).count();
44 }
45 else
46 {
47 perf[&node] = 0;
48 }
49 }
50 }
51 catch(...)
52 {
53 ossia::logger().error("Error while executing a node");
54 }
55};
56
57struct node_exec_logger
58{
59 execution_state*& g;
60 ossia::logger_type& logger;
61
62 void operator()(graph_node& node)
63 try
64 {
65 if(node.enabled())
66 {
67 assert(graph_util::can_execute(node, *g));
68 if(!node.logged())
69 graph_util::exec_node(node, *g);
70 else
71 graph_util::exec_node(node, *g, logger);
72 }
73 }
74 catch(...)
75 {
76 ossia::logger().error("Error while executing a node");
77 }
78};
79
80struct node_exec_logger_bench
81{
82 execution_state*& g;
83 bench_map& perf;
84 ossia::logger_type& logger;
85
86 void operator()(graph_node& node)
87 try
88 {
89 if(perf.measure)
90 {
91 if(node.enabled())
92 {
93 assert(graph_util::can_execute(node, *g));
94
95 auto t0 = std::chrono::steady_clock::now();
96 if(!node.logged())
97 graph_util::exec_node(node, *g);
98 else
99 graph_util::exec_node(node, *g, logger);
100 auto t1 = std::chrono::steady_clock::now();
101 perf[&node]
102 = std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0).count();
103 }
104 else
105 {
106 perf[&node] = 0;
107 }
108 }
109 else
110 {
111 if(!node.logged())
112 graph_util::exec_node(node, *g);
113 else
114 graph_util::exec_node(node, *g, logger);
115 }
116 }
117 catch(...)
118 {
119 ossia::logger().error("Error while executing a node");
120 }
121};
122
123struct static_exec
124{
125 template <typename Graph_T>
126 static_exec(Graph_T&)
127 {
128 }
129
130 template <typename T>
131 void set_logger(const T&)
132 {
133 }
134 template <typename T>
135 void set_bench(const T&)
136 {
137 }
138
139 template <typename Graph_T, typename Impl_T>
140 void operator()(
141 Graph_T& g, Impl_T& impl, execution_state& e,
142 std::vector<graph_node*>& active_nodes)
143 try
144 {
145 for(auto node : active_nodes)
146 {
147 if(node->enabled())
148 {
149 assert(graph_util::can_execute(*node, e));
150 graph_util::exec_node(*node, e);
151 }
152 }
153 }
154 catch(...)
155 {
156 ossia::logger().error("Error while executing a node");
157 }
158};
159
160struct static_exec_bench
161{
162 std::shared_ptr<bench_map> perf;
163 template <typename Graph_T>
164 static_exec_bench(Graph_T&)
165 {
166 }
167
168 template <typename T>
169 void set_logger(const T&)
170 {
171 }
172 template <typename T>
173 void set_bench(const T& t)
174 {
175 perf = t;
176 }
177
178 template <typename Graph_T, typename Impl_T>
179 void operator()(
180 Graph_T& g, Impl_T& impl, execution_state& e,
181 std::vector<graph_node*>& active_nodes)
182 try
183 {
184 auto& p = *perf;
185 if(p.measure)
186 {
187 for(auto node : active_nodes)
188 {
189 if(node->enabled())
190 {
191 assert(graph_util::can_execute(*node, e));
192 auto t0 = std::chrono::steady_clock::now();
193 graph_util::exec_node(*node, e);
194 auto t1 = std::chrono::steady_clock::now();
195 p[node]
196 = std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0).count();
197 }
198 else
199 {
200 p[node] = 0;
201 }
202 }
203 }
204 else
205 {
206 for(auto node : active_nodes)
207 {
208 if(node->enabled())
209 {
210 assert(graph_util::can_execute(*node, e));
211 graph_util::exec_node(*node, e);
212 }
213 }
214 }
215 }
216 catch(...)
217 {
218 ossia::logger().error("Error while executing a node");
219 }
220};
221
222struct static_exec_logger
223{
224 template <typename Graph_T>
225 static_exec_logger(Graph_T&)
226 {
227 }
228 template <typename T>
229 void set_logger(const T& t)
230 {
231 logger = t;
232 }
233 template <typename T>
234 void set_bench(const T& t)
235 {
236 }
237
238 std::shared_ptr<bench_map> perf;
239 std::shared_ptr<ossia::logger_type> logger;
240 template <typename Graph_T, typename Impl_T>
241 void operator()(
242 Graph_T& g, Impl_T& impl, execution_state& e,
243 std::vector<graph_node*>& active_nodes)
244 try
245 {
246 for(auto node : active_nodes)
247 {
248 if(node->enabled())
249 {
250 assert(graph_util::can_execute(*node, e));
251 if(!node->logged())
252 graph_util::exec_node(*node, e);
253 else
254 graph_util::exec_node(*node, e, *logger);
255 }
256 }
257 }
258 catch(...)
259 {
260 ossia::logger().error("Error while executing a node");
261 }
262};
263
264struct static_exec_logger_bench
265{
266 template <typename T>
267 void set_logger(const T& t)
268 {
269 logger = t;
270 }
271 template <typename T>
272 void set_bench(const T& t)
273 {
274 perf = t;
275 }
276
277 std::shared_ptr<bench_map> perf;
278 std::shared_ptr<ossia::logger_type> logger;
279
280 template <typename Graph_T>
281 static_exec_logger_bench(Graph_T&)
282 {
283 }
284 template <typename Graph_T, typename Impl_T>
285 void operator()(
286 Graph_T& g, Impl_T& impl, execution_state& e,
287 std::vector<graph_node*>& active_nodes)
288 try
289 {
290 auto& p = *perf;
291 if(p.measure)
292 {
293 for(auto node : active_nodes)
294 {
295 if(node->enabled())
296 {
297 assert(graph_util::can_execute(*node, e));
298 auto t0 = std::chrono::steady_clock::now();
299 if(!node->logged())
300 graph_util::exec_node(*node, e);
301 else
302 graph_util::exec_node(*node, e, *logger);
303 auto t1 = std::chrono::steady_clock::now();
304 p[node]
305 = std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0).count();
306 }
307 else
308 {
309 p[node] = 0;
310 }
311 }
312 }
313 else
314 {
315 for(auto node : active_nodes)
316 {
317 if(node->enabled())
318 {
319 assert(graph_util::can_execute(*node, e));
320 if(!node->logged())
321 graph_util::exec_node(*node, e);
322 else
323 graph_util::exec_node(*node, e, *logger);
324 }
325 }
326 }
327 }
328 catch(...)
329 {
330 ossia::logger().error("Error while executing a node");
331 }
332};
333}
Definition git_info.h:7
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition context.cpp:118