| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aeb7c84 commit 3ca6720
21 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,7 +55,7 @@ auto Hold(const Events<D,T>& events, V&& init) | |||
| 55 | 55 | ||
| 56 | 56 | return Signal<D,T>( | |
| 57 | 57 | std::make_shared<HoldNode<D,T>>( | |
| 58 | - std::forward<V>(init), events.NodePtr())); | ||
| 58 | + std::forward<V>(init), GetNodePtr(events))); | ||
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | 61 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -73,7 +73,7 @@ auto Monitor(const Signal<D,S>& target) | |||
| 73 | 73 | ||
| 74 | 74 | return Events<D,S>( | |
| 75 | 75 | std::make_shared<MonitorNode<D, S>>( | |
| 76 | - target.NodePtr())); | ||
| 76 | + GetNodePtr(target))); | ||
| 77 | 77 | } | |
| 78 | 78 | ||
| 79 | 79 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -103,7 +103,7 @@ auto Iterate(const Events<D,E>& events, V&& init, FIn&& func) | |||
| 103 | 103 | ||
| 104 | 104 | return Signal<D,S>( | |
| 105 | 105 | std::make_shared<TNode>( | |
| 106 | - std::forward<V>(init), events.NodePtr(), std::forward<FIn>(func))); | ||
| 106 | + std::forward<V>(init), GetNodePtr(events), std::forward<FIn>(func))); | ||
| 107 | 107 | } | |
| 108 | 108 | ||
| 109 | 109 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -146,8 +146,8 @@ auto Iterate(const Events<D,E>& events, V&& init, | |||
| 146 | 146 | { | |
| 147 | 147 | return Signal<D,S>( | |
| 148 | 148 | std::make_shared<TNode>( | |
| 149 | - std::forward<V>(MyInit), MySource.NodePtr(), | ||
| 150 | - std::forward<FIn>(MyFunc), deps.NodePtr() ...)); | ||
| 149 | + std::forward<V>(MyInit), GetNodePtr(MySource), | ||
| 150 | + std::forward<FIn>(MyFunc), GetNodePtr(deps) ...)); | ||
| 151 | 151 | } | |
| 152 | 152 | ||
| 153 | 153 | const Events<D,E>& MySource; | |
@@ -176,7 +176,7 @@ auto Snapshot(const Events<D,E>& trigger, const Signal<D,S>& target) | |||
| 176 | 176 | ||
| 177 | 177 | return Signal<D,S>( | |
| 178 | 178 | std::make_shared<SnapshotNode<D,S,E>>( | |
| 179 | - target.NodePtr(), trigger.NodePtr())); | ||
| 179 | + GetNodePtr(target), GetNodePtr(trigger))); | ||
| 180 | 180 | } | |
| 181 | 181 | ||
| 182 | 182 | ||
@@ -197,7 +197,7 @@ auto Pulse(const Events<D,E>& trigger, const Signal<D,S>& target) | |||
| 197 | 197 | ||
| 198 | 198 | return Events<D,S>( | |
| 199 | 199 | std::make_shared<PulseNode<D,S,E>>( | |
| 200 | - target.NodePtr(), trigger.NodePtr())); | ||
| 200 | + GetNodePtr(target), GetNodePtr(trigger))); | ||
| 201 | 201 | } | |
| 202 | 202 | ||
| 203 | 203 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,20 +14,16 @@ | |||
| 14 | 14 | #include <memory> | |
| 15 | 15 | #include <utility> | |
| 16 | 16 | ||
| 17 | - #include "react/detail/IReactiveEngine.h" | ||
| 17 | + #include "react/detail/DomainBase.h" | ||
| 18 | 18 | #include "react/detail/ReactiveInput.h" | |
| 19 | + | ||
| 19 | 20 | #include "react/detail/graph/ContinuationNodes.h" | |
| 20 | 21 | ||
| 21 | 22 | #ifdef REACT_ENABLE_LOGGING | |
| 22 | 23 | #include "react/logging/EventLog.h" | |
| 23 | 24 | #include "react/logging/EventRecords.h" | |
| 24 | 25 | #endif //REACT_ENABLE_LOGGING | |
| 25 | 26 | ||
| 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 | - | ||
| 31 | 27 | /*****************************************/ REACT_BEGIN /*****************************************/ | |
| 32 | 28 | ||
| 33 | 29 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -79,18 +75,18 @@ using REACT_IMPL::allow_merging; | |||
| 79 | 75 | #endif //REACT_ENABLE_LOGGING | |
| 80 | 76 | ||
| 81 | 77 | // 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; | ||
| 89 | 83 | ||
| 90 | 84 | // Expose enum type so aliases for engines can be declared, but don't | |
| 91 | 85 | // expose the actual enum values as they are reserved for internal use. | |
| 92 | 86 | using REACT_IMPL::EPropagationMode; | |
| 93 | 87 | ||
| 88 | + using REACT_IMPL::WeightHint; | ||
| 89 | + | ||
| 94 | 90 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 95 | 91 | /// TransactionStatus | |
| 96 | 92 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -139,101 +135,38 @@ class TransactionStatus | |||
| 139 | 135 | friend void AsyncTransaction(TransactionFlagsT flags, TransactionStatus& status, F&& func); | |
| 140 | 136 | }; | |
| 141 | 137 | ||
| 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 | - | ||
| 201 | 138 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 202 | 139 | /// Continuation | |
| 203 | 140 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 204 | 141 | template | |
| 205 | 142 | < | |
| 206 | - typename TSourceDomain, | ||
| 207 | - typename TTargetDomain | ||
| 143 | + typename D, | ||
| 144 | + typename D2 | ||
| 208 | 145 | > | |
| 209 | - class Continuation | ||
| 146 | + class Continuation : public REACT_IMPL::ContinuationBase<D,D2> | ||
| 210 | 147 | { | |
| 211 | - using NodePtrT = REACT_IMPL::NodeBasePtrT<TSourceDomain>; | ||
| 148 | + private: | ||
| 149 | + using NodePtrT = REACT_IMPL::NodeBasePtrT<D>; | ||
| 212 | 150 | ||
| 213 | 151 | public: | |
| 214 | - using SourceDomainT = TSourceDomain; | ||
| 215 | - using TargetDomainT = TTargetDomain; | ||
| 152 | + using SourceDomainT = D; | ||
| 153 | + using TargetDomainT = D2; | ||
| 216 | 154 | ||
| 217 | 155 | Continuation() = default; | |
| 218 | - Continuation(const Continuation&) = delete; | ||
| 219 | - Continuation& operator=(const Continuation&) = delete; | ||
| 220 | 156 | ||
| 221 | 157 | Continuation(Continuation&& other) : | |
| 222 | - nodePtr_( std::move(other.nodePtr_) ) | ||
| 158 | + Continuation::ContinuationBase( std::move(other) ) | ||
| 223 | 159 | {} | |
| 224 | 160 | ||
| 225 | 161 | explicit Continuation(NodePtrT&& nodePtr) : | |
| 226 | - nodePtr_( std::move(nodePtr) ) | ||
| 227 | - {} | ||
| 162 | + Continuation::ContinuationBase( std::move(nodePtr) ) | ||
| 163 | + {} | ||
| 228 | 164 | ||
| 229 | 165 | Continuation& operator=(Continuation&& other) | |
| 230 | 166 | { | |
| 231 | - nodePtr_ = std::move(other.nodePtr_); | ||
| 167 | + Continuation::ContinuationBase::operator=( std::move(other) ); | ||
| 232 | 168 | return *this; | |
| 233 | 169 | } | |
| 234 | - | ||
| 235 | - private: | ||
| 236 | - NodePtrT nodePtr_; | ||
| 237 | 170 | }; | |
| 238 | 171 | ||
| 239 | 172 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -257,7 +190,7 @@ auto MakeContinuation(TransactionFlagsT flags, const Signal<D,S>& trigger, FIn&& | |||
| 257 | 190 | ||
| 258 | 191 | return Continuation<D,DOut>( | |
| 259 | 192 | std::make_shared<SignalContinuationNode<D,DOut,S,F>>( | |
| 260 | - flags, trigger.NodePtr(), std::forward<FIn>(func))); | ||
| 193 | + flags, GetNodePtr(trigger), std::forward<FIn>(func))); | ||
| 261 | 194 | } | |
| 262 | 195 | ||
| 263 | 196 | template | |
@@ -294,7 +227,7 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger, FIn&& | |||
| 294 | 227 | ||
| 295 | 228 | return Continuation<D,DOut>( | |
| 296 | 229 | std::make_shared<EventContinuationNode<D,DOut,E,F>>( | |
| 297 | - flags, trigger.NodePtr(), std::forward<FIn>(func))); | ||
| 230 | + flags, GetNodePtr(trigger), std::forward<FIn>(func))); | ||
| 298 | 231 | } | |
| 299 | 232 | ||
| 300 | 233 | template | |
@@ -345,11 +278,11 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger, | |||
| 345 | 278 | return Continuation<D,DOut>( | |
| 346 | 279 | std::make_shared<SyncedContinuationNode<D,DOut,E,F,TDepValues...>>( | |
| 347 | 280 | MyFlags, | |
| 348 | - MyTrigger.NodePtr(), | ||
| 349 | - std::forward<FIn>(MyFunc), deps.NodePtr() ...)); | ||
| 281 | + GetNodePtr(MyTrigger), | ||
| 282 | + std::forward<FIn>(MyFunc), GetNodePtr(deps) ...)); | ||
| 350 | 283 | } | |
| 351 | 284 | ||
| 352 | - TransactionFlagsT MyFlags; | ||
| 285 | + TransactionFlagsT MyFlags; | ||
| 353 | 286 | const Events<D,E>& MyTrigger; | |
| 354 | 287 | FIn MyFunc; | |
| 355 | 288 | }; | |
@@ -437,130 +370,12 @@ void AsyncTransaction(TransactionFlagsT flags, TransactionStatus& status, F&& fu | |||
| 437 | 370 | ||
| 438 | 371 | /******************************************/ REACT_END /******************************************/ | |
| 439 | 372 | ||
| 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 | - | ||
| 558 | 373 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 559 | 374 | /// Domain definition macro | |
| 560 | 375 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 561 | 376 | #define REACTIVE_DOMAIN(name, ...) \ | |
| 562 | 377 | struct name : \ | |
| 563 | - public REACT::DomainBase<name, REACT_IMPL::DomainPolicy< __VA_ARGS__ >> {}; \ | ||
| 378 | + public REACT_IMPL::DomainBase<name, REACT_IMPL::DomainPolicy< __VA_ARGS__ >> {}; \ | ||
| 564 | 379 | REACT_IMPL::DomainInitializer<name> name ## _initializer_; | |
| 565 | 380 | ||
| 566 | 381 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| Back | FazBrowse Home | New Git URL |
0 commit comments