1414#include < memory>
1515#include < utility>
1616
17- #include " react/detail/IReactiveEngine .h"
17+ #include " react/detail/DomainBase .h"
1818#include " react/detail/ReactiveInput.h"
19+
1920#include " react/detail/graph/ContinuationNodes.h"
2021
2122#ifdef REACT_ENABLE_LOGGING
2223 #include " react/logging/EventLog.h"
2324 #include " react/logging/EventRecords.h"
2425#endif // REACT_ENABLE_LOGGING
2526
26- // Include all engines for convenience
27- #include " react/engine/PulsecountEngine.h"
28- #include " react/engine/SubtreeEngine.h"
29- #include " react/engine/ToposortEngine.h"
30-
3127/* ****************************************/ REACT_BEGIN /* ****************************************/
3228
3329// /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -79,18 +75,18 @@ using REACT_IMPL::allow_merging;
7975#endif // REACT_ENABLE_LOGGING
8076
8177// Domain modes
82- enum EDomainMode
83- {
84- sequential,
85- sequential_concurrent,
86- parallel,
87- parallel_concurrent
88- };
78+ using REACT_IMPL::EDomainMode;
79+ using REACT_IMPL::sequential;
80+ using REACT_IMPL::sequential_concurrent;
81+ using REACT_IMPL::parallel;
82+ using REACT_IMPL::parallel_concurrent;
8983
9084// Expose enum type so aliases for engines can be declared, but don't
9185// expose the actual enum values as they are reserved for internal use.
9286using REACT_IMPL::EPropagationMode;
9387
88+ using REACT_IMPL::WeightHint;
89+
9490// /////////////////////////////////////////////////////////////////////////////////////////////////
9591// / TransactionStatus
9692// /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -139,101 +135,38 @@ class TransactionStatus
139135 friend void AsyncTransaction (TransactionFlagsT flags, TransactionStatus& status, F&& func);
140136};
141137
142- // /////////////////////////////////////////////////////////////////////////////////////////////////
143- // / DomainBase
144- // /////////////////////////////////////////////////////////////////////////////////////////////////
145- template <typename D, typename TPolicy>
146- class DomainBase
147- {
148- public:
149- using TurnT = typename TPolicy::Engine::TurnT;
150-
151- DomainBase () = delete ;
152-
153- using Policy = TPolicy;
154- using Engine = REACT_IMPL::EngineInterface<D, typename Policy::Engine>;
155-
156- // /////////////////////////////////////////////////////////////////////////////////////////////
157- // / Domain traits
158- // /////////////////////////////////////////////////////////////////////////////////////////////
159- static const bool uses_node_update_timer =
160- REACT_IMPL::NodeUpdateTimerEnabled<typename Policy::Engine>::value;
161-
162- static const bool is_concurrent =
163- Policy::input_mode == REACT_IMPL::concurrent_input;
164-
165- static const bool is_parallel =
166- Policy::propagation_mode == REACT_IMPL::parallel_propagation;
167-
168- // /////////////////////////////////////////////////////////////////////////////////////////////
169- // / Aliases for reactives of this domain
170- // /////////////////////////////////////////////////////////////////////////////////////////////
171- template <typename S>
172- using SignalT = Signal<D,S>;
173-
174- template <typename S>
175- using VarSignalT = VarSignal<D,S>;
176-
177- template <typename E = Token>
178- using EventsT = Events<D,E>;
179-
180- template <typename E = Token>
181- using EventSourceT = EventSource<D,E>;
182-
183- using ObserverT = Observer<D>;
184-
185- using ScopedObserverT = ScopedObserver<D>;
186-
187- using ReactorT = Reactor<D>;
188-
189- #ifdef REACT_ENABLE_LOGGING
190- // /////////////////////////////////////////////////////////////////////////////////////////////
191- // / Log
192- // /////////////////////////////////////////////////////////////////////////////////////////////
193- static EventLog& Log ()
194- {
195- static EventLog instance;
196- return instance;
197- }
198- #endif // REACT_ENABLE_LOGGING
199- };
200-
201138// /////////////////////////////////////////////////////////////////////////////////////////////////
202139// / Continuation
203140// /////////////////////////////////////////////////////////////////////////////////////////////////
204141template
205142<
206- typename TSourceDomain ,
207- typename TTargetDomain
143+ typename D ,
144+ typename D2
208145>
209- class Continuation
146+ class Continuation : public REACT_IMPL ::ContinuationBase<D,D2>
210147{
211- using NodePtrT = REACT_IMPL::NodeBasePtrT<TSourceDomain>;
148+ private:
149+ using NodePtrT = REACT_IMPL::NodeBasePtrT<D>;
212150
213151public:
214- using SourceDomainT = TSourceDomain ;
215- using TargetDomainT = TTargetDomain ;
152+ using SourceDomainT = D ;
153+ using TargetDomainT = D2 ;
216154
217155 Continuation () = default ;
218- Continuation (const Continuation&) = delete ;
219- Continuation& operator =(const Continuation&) = delete ;
220156
221157 Continuation (Continuation&& other) :
222- nodePtr_ ( std::move(other.nodePtr_ ) )
158+ Continuation::ContinuationBase ( std::move(other) )
223159 {}
224160
225161 explicit Continuation (NodePtrT&& nodePtr) :
226- nodePtr_ ( std::move(nodePtr) )
227- {}
162+ Continuation::ContinuationBase ( std::move(nodePtr) )
163+ {}
228164
229165 Continuation& operator =(Continuation&& other)
230166 {
231- nodePtr_ = std::move (other. nodePtr_ );
167+ Continuation::ContinuationBase:: operator =( std::move (other) );
232168 return *this ;
233169 }
234-
235- private:
236- NodePtrT nodePtr_;
237170};
238171
239172// /////////////////////////////////////////////////////////////////////////////////////////////////
@@ -257,7 +190,7 @@ auto MakeContinuation(TransactionFlagsT flags, const Signal<D,S>& trigger, FIn&&
257190
258191 return Continuation<D,DOut>(
259192 std::make_shared<SignalContinuationNode<D,DOut,S,F>>(
260- flags, trigger. NodePtr ( ), std::forward<FIn>(func)));
193+ flags, GetNodePtr (trigger ), std::forward<FIn>(func)));
261194}
262195
263196template
@@ -294,7 +227,7 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger, FIn&&
294227
295228 return Continuation<D,DOut>(
296229 std::make_shared<EventContinuationNode<D,DOut,E,F>>(
297- flags, trigger. NodePtr ( ), std::forward<FIn>(func)));
230+ flags, GetNodePtr (trigger ), std::forward<FIn>(func)));
298231}
299232
300233template
@@ -345,11 +278,11 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger,
345278 return Continuation<D,DOut>(
346279 std::make_shared<SyncedContinuationNode<D,DOut,E,F,TDepValues...>>(
347280 MyFlags,
348- MyTrigger. NodePtr ( ),
349- std::forward<FIn>(MyFunc), deps. NodePtr ( ) ...));
281+ GetNodePtr (MyTrigger ),
282+ std::forward<FIn>(MyFunc), GetNodePtr (deps ) ...));
350283 }
351284
352- TransactionFlagsT MyFlags;
285+ TransactionFlagsT MyFlags;
353286 const Events<D,E>& MyTrigger;
354287 FIn MyFunc;
355288 };
@@ -437,130 +370,12 @@ void AsyncTransaction(TransactionFlagsT flags, TransactionStatus& status, F&& fu
437370
438371/* *****************************************/ REACT_END /* *****************************************/
439372
440- /* **************************************/ REACT_IMPL_BEGIN /* *************************************/
441-
442- // /////////////////////////////////////////////////////////////////////////////////////////////////
443- // / ModeSelector - Translate domain mode to individual propagation and input modes
444- // /////////////////////////////////////////////////////////////////////////////////////////////////
445- template <EDomainMode>
446- struct ModeSelector ;
447-
448- template <>
449- struct ModeSelector <sequential>
450- {
451- static const EInputMode input = consecutive_input;
452- static const EPropagationMode propagation = sequential_propagation;
453- };
454-
455- template <>
456- struct ModeSelector <sequential_concurrent>
457- {
458- static const EInputMode input = concurrent_input;
459- static const EPropagationMode propagation = sequential_propagation;
460- };
461-
462- template <>
463- struct ModeSelector <parallel>
464- {
465- static const EInputMode input = consecutive_input;
466- static const EPropagationMode propagation = parallel_propagation;
467- };
468-
469- template <>
470- struct ModeSelector <parallel_concurrent>
471- {
472- static const EInputMode input = concurrent_input;
473- static const EPropagationMode propagation = parallel_propagation;
474- };
475-
476- // /////////////////////////////////////////////////////////////////////////////////////////////////
477- // / GetDefaultEngine - Get default engine type for given propagation mode
478- // /////////////////////////////////////////////////////////////////////////////////////////////////
479- template <EPropagationMode>
480- struct GetDefaultEngine ;
481-
482- template <>
483- struct GetDefaultEngine <sequential_propagation>
484- {
485- using Type = ToposortEngine<sequential_propagation>;
486- };
487-
488- template <>
489- struct GetDefaultEngine <parallel_propagation>
490- {
491- using Type = SubtreeEngine<parallel_propagation>;
492- };
493-
494- // /////////////////////////////////////////////////////////////////////////////////////////////////
495- // / EngineTypeBuilder - Instantiate the given template engine type with mode.
496- // /////////////////////////////////////////////////////////////////////////////////////////////////
497- template <EPropagationMode>
498- struct DefaultEnginePlaceholder ;
499-
500- // Concrete engine template type
501- template
502- <
503- EPropagationMode mode,
504- template <EPropagationMode> class TTEngine
505- >
506- struct EngineTypeBuilder
507- {
508- using Type = TTEngine<mode>;
509- };
510-
511- // Placeholder engine type - use default engine for given mode
512- template
513- <
514- EPropagationMode mode
515- >
516- struct EngineTypeBuilder <mode,DefaultEnginePlaceholder>
517- {
518- using Type = typename GetDefaultEngine<mode>::Type;
519- };
520-
521- // /////////////////////////////////////////////////////////////////////////////////////////////////
522- // / DomainPolicy
523- // /////////////////////////////////////////////////////////////////////////////////////////////////
524- template
525- <
526- EDomainMode mode,
527- template <EPropagationMode> class TTEngine = DefaultEnginePlaceholder
528- >
529- struct DomainPolicy
530- {
531- static const EInputMode input_mode = ModeSelector<mode>::input;
532- static const EPropagationMode propagation_mode = ModeSelector<mode>::propagation;
533-
534- using Engine = typename EngineTypeBuilder<propagation_mode,TTEngine>::Type;
535- };
536-
537- // /////////////////////////////////////////////////////////////////////////////////////////////////
538- // / Ensure singletons are created immediately after domain declaration (TODO hax)
539- // /////////////////////////////////////////////////////////////////////////////////////////////////
540- template <typename D>
541- class DomainInitializer
542- {
543- public:
544- DomainInitializer ()
545- {
546- #ifdef REACT_ENABLE_LOGGING
547- D::Log ();
548- #endif // REACT_ENABLE_LOGGING
549-
550- D::Engine::Instance ();
551- DomainSpecificObserverRegistry<D>::Instance ();
552- DomainSpecificInputManager<D>::Instance ();
553- }
554- };
555-
556- /* ***************************************/ REACT_IMPL_END /* **************************************/
557-
558373// /////////////////////////////////////////////////////////////////////////////////////////////////
559374// / Domain definition macro
560375// /////////////////////////////////////////////////////////////////////////////////////////////////
561376#define REACTIVE_DOMAIN (name, ...) \
562377 struct name : \
563- public REACT ::DomainBase<name, REACT_IMPL::DomainPolicy< __VA_ARGS__ >> {}; \
378+ public REACT_IMPL ::DomainBase<name, REACT_IMPL::DomainPolicy< __VA_ARGS__ >> {}; \
564379 REACT_IMPL::DomainInitializer<name> name ## _initializer_;
565380
566381// /////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments