|
14 | 14 | #include <memory> |
15 | 15 | #include <utility> |
16 | 16 |
|
| 17 | +#include "react/detail/IReactiveEngine.h" |
17 | 18 | #include "react/detail/ReactiveInput.h" |
| 19 | +#include "react/detail/graph/ContinuationNodes.h" |
18 | 20 |
|
19 | 21 | #ifdef REACT_ENABLE_LOGGING |
20 | 22 | #include "react/logging/EventLog.h" |
21 | 23 | #include "react/logging/EventRecords.h" |
22 | 24 | #endif //REACT_ENABLE_LOGGING |
23 | 25 |
|
24 | | -#include "react/detail/IReactiveEngine.h" |
25 | 26 | #include "react/engine/ToposortEngine.h" |
26 | 27 |
|
27 | 28 | /*****************************************/ REACT_BEGIN /*****************************************/ |
@@ -58,6 +59,9 @@ class ScopedObserver; |
58 | 59 | template <typename D> |
59 | 60 | class Reactor; |
60 | 61 |
|
| 62 | +template <typename D, typename ... TValues> |
| 63 | +class SignalPack; |
| 64 | + |
61 | 65 | using REACT_IMPL::TurnFlagsT; |
62 | 66 |
|
63 | 67 | //ETurnFlags |
@@ -124,13 +128,13 @@ class DomainBase |
124 | 128 | /// Domain traits |
125 | 129 | /////////////////////////////////////////////////////////////////////////////////////////////// |
126 | 130 | static const bool uses_node_update_timer = |
127 | | - REACT_IMPL::EnableNodeUpdateTimer<typename Policy::Engine>::value; |
| 131 | + REACT_IMPL::NodeUpdateTimerEnabled<typename Policy::Engine>::value; |
128 | 132 |
|
129 | | - static const bool uses_concurrent_input = |
130 | | - REACT_IMPL::EnableConcurrentInput<typename Policy::Engine>::value; |
| 133 | + static const bool is_concurrent = |
| 134 | + REACT_IMPL::IsConcurrentEngine<typename Policy::Engine>::value; |
131 | 135 |
|
132 | | - static const bool uses_parallel_updating = |
133 | | - REACT_IMPL::EnableParallelUpdating<typename Policy::Engine>::value; |
| 136 | + static const bool is_parallel = |
| 137 | + REACT_IMPL::IsParallelEngine<typename Policy::Engine>::value; |
134 | 138 |
|
135 | 139 | /////////////////////////////////////////////////////////////////////////////////////////////// |
136 | 140 | /// Aliases for reactives of this domain |
@@ -218,6 +222,130 @@ class DomainBase |
218 | 222 | #endif //REACT_ENABLE_LOGGING |
219 | 223 | }; |
220 | 224 |
|
| 225 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 226 | +/// Continuation |
| 227 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 228 | +template |
| 229 | +< |
| 230 | + typename TSourceDomain, |
| 231 | + typename TTargetDomain |
| 232 | +> |
| 233 | +class Continuation |
| 234 | +{ |
| 235 | + using NodePtrT = REACT_IMPL::NodeBasePtrT<TSourceDomain>; |
| 236 | + |
| 237 | +public: |
| 238 | + using SourceDomainT = TSourceDomain; |
| 239 | + using TargetDomainT = TTargetDomain; |
| 240 | + |
| 241 | + Continuation() = default; |
| 242 | + Continuation(const Continuation&) = delete; |
| 243 | + Continuation& operator=(const Continuation&) = delete; |
| 244 | + |
| 245 | + Continuation(Continuation&& other) : |
| 246 | + nodePtr_( std::move(other.nodePtr_) ) |
| 247 | + {} |
| 248 | + |
| 249 | + explicit Continuation(NodePtrT&& nodePtr) : |
| 250 | + nodePtr_( std::move(nodePtr) ) |
| 251 | + {} |
| 252 | + |
| 253 | + Continuation& operator=(Continuation&& other) |
| 254 | + { |
| 255 | + nodePtr_ = std::move(other.nodePtr_); |
| 256 | + return *this; |
| 257 | + } |
| 258 | + |
| 259 | +private: |
| 260 | + NodePtrT nodePtr_; |
| 261 | +}; |
| 262 | + |
| 263 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 264 | +/// MakeContinuation - Signals |
| 265 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 266 | +template |
| 267 | +< |
| 268 | + typename D, |
| 269 | + typename DOut = D, |
| 270 | + typename S, |
| 271 | + typename FIn |
| 272 | +> |
| 273 | +auto MakeContinuation(const Signal<D,S>& trigger, FIn&& func) |
| 274 | + -> Continuation<D,DOut> |
| 275 | +{ |
| 276 | + using REACT_IMPL::SignalContinuationNode; |
| 277 | + using F = typename std::decay<FIn>::type; |
| 278 | + |
| 279 | + return Continuation<D,DOut>( |
| 280 | + std::make_shared<SignalContinuationNode<D,DOut,S,F>>( |
| 281 | + trigger.NodePtr(), std::forward<FIn>(func))); |
| 282 | +} |
| 283 | + |
| 284 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 285 | +/// MakeContinuation - Events |
| 286 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 287 | +template |
| 288 | +< |
| 289 | + typename D, |
| 290 | + typename DOut = D, |
| 291 | + typename E, |
| 292 | + typename FIn |
| 293 | +> |
| 294 | +auto MakeContinuation(const Events<D,E>& trigger, FIn&& func) |
| 295 | + -> Continuation<D,DOut> |
| 296 | +{ |
| 297 | + using REACT_IMPL::EventContinuationNode; |
| 298 | + using F = typename std::decay<FIn>::type; |
| 299 | + |
| 300 | + return Continuation<D,DOut>( |
| 301 | + std::make_shared<EventContinuationNode<D,DOut,E,F>>( |
| 302 | + trigger.NodePtr(), std::forward<FIn>(func))); |
| 303 | +} |
| 304 | + |
| 305 | + |
| 306 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 307 | +/// MakeContinuation - Synced |
| 308 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 309 | +template |
| 310 | +< |
| 311 | + typename D, |
| 312 | + typename DOut = D, |
| 313 | + typename E, |
| 314 | + typename FIn, |
| 315 | + typename ... TDepValues |
| 316 | +> |
| 317 | +auto MakeContinuation(const Events<D,E>& trigger, |
| 318 | + const SignalPack<D,TDepValues...>& depPack, FIn&& func) |
| 319 | + -> Continuation<D,DOut> |
| 320 | +{ |
| 321 | + using REACT_IMPL::SyncedContinuationNode; |
| 322 | + using F = typename std::decay<FIn>::type; |
| 323 | + |
| 324 | + struct NodeBuilder_ |
| 325 | + { |
| 326 | + NodeBuilder_(const Events<D,E>& trigger, FIn&& func) : |
| 327 | + MyTrigger( trigger ), |
| 328 | + MyFunc( std::forward<FIn>(func) ) |
| 329 | + {} |
| 330 | + |
| 331 | + auto operator()(const Signal<D,TDepValues>& ... deps) |
| 332 | + -> Continuation<D,DOut> |
| 333 | + { |
| 334 | + return Continuation<D,DOut>( |
| 335 | + std::make_shared<SyncedContinuationNode<D,DOut,E,F,TDepValues...>>( |
| 336 | + MyTrigger.NodePtr(), |
| 337 | + std::forward<FIn>(MyFunc), deps.NodePtr() ...)); |
| 338 | + } |
| 339 | + |
| 340 | + const Events<D,E>& MyTrigger; |
| 341 | + FIn MyFunc; |
| 342 | + }; |
| 343 | + |
| 344 | + return REACT_IMPL::apply( |
| 345 | + NodeBuilder_( trigger, std::forward<FIn>(func) ), |
| 346 | + depPack.Data); |
| 347 | +} |
| 348 | + |
221 | 349 | /******************************************/ REACT_END /******************************************/ |
222 | 350 |
|
223 | 351 | /***************************************/ REACT_IMPL_BEGIN /**************************************/ |
|
0 commit comments