11
11
#define UREACT_DETAIL_GRAPH_IMPL_INL
12
12
13
13
#include < cassert>
14
- #include < cstddef>
15
- #include < cstdint>
16
14
#include < limits>
17
15
#include < memory>
18
- #include < tuple>
19
- #include < type_traits>
20
- #include < utility>
21
16
#include < vector>
22
17
23
18
#include < ureact/detail/algorithm.hpp>
@@ -31,86 +26,46 @@ UREACT_BEGIN_NAMESPACE
31
26
namespace detail
32
27
{
33
28
34
- #if !defined( NDEBUG )
35
- // / Utility class to check if callbacks passed in lift(), process() etc
36
- // / are used properly
37
- class callback_sanitizer
29
+ class react_graph_impl : public react_graph
38
30
{
39
- public:
40
- // / Return if external callback is in progress
41
- UREACT_WARN_UNUSED_RESULT bool is_locked () const
31
+ #if !defined( NDEBUG )
32
+ bool m_is_locked = false ;
33
+
34
+ bool is_locked () const override
42
35
{
43
36
return m_is_locked;
44
37
}
45
38
46
- // / Marks begin of an external callback
47
- void begin_external_callback ()
39
+ void begin_external_callback () override
48
40
{
49
41
assert ( !m_is_locked );
50
42
m_is_locked = true ;
51
43
}
52
44
53
- // / Marks end of an external callback
54
- void end_external_callback ()
45
+ void end_external_callback () override
55
46
{
56
47
assert ( m_is_locked );
57
48
m_is_locked = false ;
58
49
}
59
-
60
- // / Marks a place where an external callback is called
61
- struct guard
62
- {
63
- callback_sanitizer& self;
64
-
65
- explicit guard ( callback_sanitizer& self )
66
- : self( self )
67
- {
68
- self.begin_external_callback ();
69
- }
70
-
71
- ~guard ()
72
- {
73
- self.end_external_callback ();
74
- }
75
-
76
- UREACT_MAKE_NONCOPYABLE ( guard );
77
- UREACT_MAKE_NONMOVABLE ( guard );
78
- };
79
-
80
- private:
81
- bool m_is_locked = false ;
82
- };
83
-
84
- # define UREACT_CALLBACK_GUARD ( _SELF_ ) callback_sanitizer::guard _ ( _SELF_ )
85
- #else
86
- # define UREACT_CALLBACK_GUARD ( _SELF_ ) \
87
- do \
88
- { \
89
- } while ( false )
90
- #endif
91
-
92
- class react_graph
93
- #if !defined( NDEBUG )
94
- : public callback_sanitizer
95
50
#endif
96
- {
97
51
public:
98
- react_graph () = default ;
99
- ~react_graph () ;
52
+ react_graph_impl () = default ;
53
+ ~react_graph_impl () override ;
100
54
101
- node_id register_node ();
102
- void register_node_ptr ( node_id nodeId, const std::weak_ptr<reactive_node_interface>& nodePtr );
103
- void unregister_node ( node_id nodeId );
55
+ node_id register_node () override ;
56
+ void register_node_ptr (
57
+ node_id nodeId, const std::weak_ptr<reactive_node_interface>& nodePtr ) override ;
58
+ void unregister_node ( node_id nodeId ) override ;
104
59
105
- void attach_node ( node_id nodeId, node_id parentId );
106
- void detach_node ( node_id nodeId, node_id parentId );
60
+ void attach_node ( node_id nodeId, node_id parentId ) override ;
61
+ void detach_node ( node_id nodeId, node_id parentId ) override ;
107
62
108
- void push_input ( node_id nodeId );
63
+ void push_input ( node_id nodeId ) override ;
109
64
110
- void start_transaction ();
111
- void finish_transaction ();
65
+ void start_transaction () override ;
66
+ void finish_transaction () override ;
112
67
113
- [[nodiscard]] bool is_propagation_in_progress () const
68
+ [[nodiscard]] bool is_propagation_in_progress () const override
114
69
{
115
70
return m_propagation_is_in_progress;
116
71
}
@@ -199,7 +154,7 @@ private:
199
154
node_id_vector m_nodes_queued_for_unregister;
200
155
};
201
156
202
- inline react_graph ::~react_graph ()
157
+ UREACT_FUNC react_graph_impl ::~react_graph_impl ()
203
158
{
204
159
assert ( m_node_data.empty () );
205
160
assert ( m_scheduled_nodes.empty () );
@@ -209,12 +164,12 @@ inline react_graph::~react_graph()
209
164
assert ( m_nodes_queued_for_unregister.empty () );
210
165
}
211
166
212
- inline node_id react_graph ::register_node ()
167
+ UREACT_FUNC node_id react_graph_impl ::register_node ()
213
168
{
214
169
return node_id{ m_id, m_node_data.emplace () };
215
170
}
216
171
217
- inline void react_graph ::register_node_ptr (
172
+ UREACT_FUNC void react_graph_impl ::register_node_ptr (
218
173
const node_id nodeId, const std::weak_ptr<reactive_node_interface>& nodePtr )
219
174
{
220
175
assert ( nodeId.context_id () == m_id );
@@ -224,7 +179,7 @@ inline void react_graph::register_node_ptr(
224
179
node.node_ptr = nodePtr;
225
180
}
226
181
227
- inline void react_graph ::unregister_node ( const node_id nodeId )
182
+ UREACT_FUNC void react_graph_impl ::unregister_node ( const node_id nodeId )
228
183
{
229
184
assert ( nodeId.context_id () == m_id );
230
185
assert ( m_node_data[nodeId].successors .empty () );
@@ -235,7 +190,7 @@ inline void react_graph::unregister_node( const node_id nodeId )
235
190
m_nodes_queued_for_unregister.add ( nodeId );
236
191
}
237
192
238
- inline void react_graph ::attach_node ( const node_id nodeId, const node_id parentId )
193
+ UREACT_FUNC void react_graph_impl ::attach_node ( const node_id nodeId, const node_id parentId )
239
194
{
240
195
assert ( nodeId.context_id () == m_id );
241
196
assert ( parentId.context_id () == m_id );
@@ -248,7 +203,7 @@ inline void react_graph::attach_node( const node_id nodeId, const node_id parent
248
203
node.level = std::max ( node.level , parent.level + 1 );
249
204
}
250
205
251
- inline void react_graph ::detach_node ( const node_id nodeId, const node_id parentId )
206
+ UREACT_FUNC void react_graph_impl ::detach_node ( const node_id nodeId, const node_id parentId )
252
207
{
253
208
assert ( nodeId.context_id () == m_id );
254
209
assert ( parentId.context_id () == m_id );
@@ -259,7 +214,7 @@ inline void react_graph::detach_node( const node_id nodeId, const node_id parent
259
214
successors.remove ( nodeId );
260
215
}
261
216
262
- inline void react_graph ::push_input ( const node_id nodeId )
217
+ UREACT_FUNC void react_graph_impl ::push_input ( const node_id nodeId )
263
218
{
264
219
assert ( !m_propagation_is_in_progress );
265
220
@@ -269,14 +224,14 @@ inline void react_graph::push_input( const node_id nodeId )
269
224
propagate ();
270
225
}
271
226
272
- inline void react_graph ::start_transaction ()
227
+ UREACT_FUNC void react_graph_impl ::start_transaction ()
273
228
{
274
229
assert ( !m_propagation_is_in_progress );
275
230
276
231
++m_transaction_level;
277
232
}
278
233
279
- inline void react_graph ::finish_transaction ()
234
+ UREACT_FUNC void react_graph_impl ::finish_transaction ()
280
235
{
281
236
assert ( !m_propagation_is_in_progress );
282
237
assert ( m_transaction_level > 0 );
@@ -287,18 +242,18 @@ inline void react_graph::finish_transaction()
287
242
propagate ();
288
243
}
289
244
290
- inline node_id::context_id_type react_graph ::create_context_id ()
245
+ UREACT_FUNC node_id::context_id_type react_graph_impl ::create_context_id ()
291
246
{
292
247
static node_id::context_id_type s_next_id = 1u ;
293
248
return s_next_id++;
294
249
}
295
250
296
- UREACT_WARN_UNUSED_RESULT inline bool react_graph ::can_unregister_node () const
251
+ UREACT_FUNC bool react_graph_impl ::can_unregister_node () const
297
252
{
298
253
return m_transaction_level == 0 && !m_propagation_is_in_progress;
299
254
}
300
255
301
- inline void react_graph ::propagate ()
256
+ UREACT_FUNC void react_graph_impl ::propagate ()
302
257
{
303
258
m_propagation_is_in_progress = true ;
304
259
@@ -313,7 +268,7 @@ inline void react_graph::propagate()
313
268
unregister_queued_nodes ();
314
269
}
315
270
316
- inline void react_graph ::recalculate_successor_levels ( node_data& parentNode )
271
+ UREACT_FUNC void react_graph_impl ::recalculate_successor_levels ( node_data& parentNode )
317
272
{
318
273
for ( const node_id successorId : parentNode.successors )
319
274
{
@@ -322,7 +277,7 @@ inline void react_graph::recalculate_successor_levels( node_data& parentNode )
322
277
}
323
278
}
324
279
325
- inline void react_graph ::schedule_node ( const node_id nodeId )
280
+ UREACT_FUNC void react_graph_impl ::schedule_node ( const node_id nodeId )
326
281
{
327
282
node_data& node = m_node_data[nodeId];
328
283
@@ -333,20 +288,20 @@ inline void react_graph::schedule_node( const node_id nodeId )
333
288
}
334
289
}
335
290
336
- inline void react_graph ::re_schedule_node ( const node_id nodeId )
291
+ UREACT_FUNC void react_graph_impl ::re_schedule_node ( const node_id nodeId )
337
292
{
338
293
node_data& node = m_node_data[nodeId];
339
294
recalculate_successor_levels ( node );
340
295
m_scheduled_nodes.push ( nodeId, node.level );
341
296
}
342
297
343
- inline void react_graph ::schedule_successors ( node_data& parentNode )
298
+ UREACT_FUNC void react_graph_impl ::schedule_successors ( node_data& parentNode )
344
299
{
345
300
for ( const node_id successorId : parentNode.successors )
346
301
schedule_node ( successorId );
347
302
}
348
303
349
- inline void react_graph ::propagate_node_change ( const node_id nodeId )
304
+ UREACT_FUNC void react_graph_impl ::propagate_node_change ( const node_id nodeId )
350
305
{
351
306
node_data& node = m_node_data[nodeId];
352
307
if ( std::shared_ptr<reactive_node_interface> nodePtr = node.node_ptr .lock () )
@@ -378,7 +333,7 @@ inline void react_graph::propagate_node_change( const node_id nodeId )
378
333
node.queued = false ;
379
334
}
380
335
381
- inline void react_graph ::finalize_changed_nodes ()
336
+ UREACT_FUNC void react_graph_impl ::finalize_changed_nodes ()
382
337
{
383
338
// Cleanup buffers in changed nodes etc
384
339
for ( const node_id nodeId : m_changed_nodes )
@@ -392,7 +347,7 @@ inline void react_graph::finalize_changed_nodes()
392
347
m_changed_nodes.clear ();
393
348
}
394
349
395
- inline void react_graph ::unregister_queued_nodes ()
350
+ UREACT_FUNC void react_graph_impl ::unregister_queued_nodes ()
396
351
{
397
352
assert ( !m_propagation_is_in_progress );
398
353
@@ -401,7 +356,7 @@ inline void react_graph::unregister_queued_nodes()
401
356
m_nodes_queued_for_unregister.clear ();
402
357
}
403
358
404
- UREACT_WARN_UNUSED_RESULT inline bool react_graph ::topological_queue::fetch_next ()
359
+ UREACT_FUNC bool react_graph_impl ::topological_queue::fetch_next ()
405
360
{
406
361
// Throw away previous values
407
362
m_next_data.clear ();
@@ -431,9 +386,9 @@ UREACT_WARN_UNUSED_RESULT inline bool react_graph::topological_queue::fetch_next
431
386
return !m_next_data.empty ();
432
387
}
433
388
434
- inline std::shared_ptr<react_graph> make_react_graph ()
389
+ UREACT_FUNC std::shared_ptr<react_graph> make_react_graph ()
435
390
{
436
- return std::make_shared<react_graph >();
391
+ return std::make_shared<react_graph_impl >();
437
392
}
438
393
439
394
} // namespace detail
0 commit comments