| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 46dee49 commit d13b3f4
37 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,8 @@ | |||
| 11 | 11 | #include <utility> | |
| 12 | 12 | #include <vector> | |
| 13 | 13 | ||
| 14 | - #include "react/Domain.h" | ||
| 15 | 14 | #include "react/Signal.h" | |
| 16 | - #include "react/Observer.h" | ||
| 17 | - | ||
| 15 | + /* | ||
| 18 | 16 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 | 17 | /// Example 1 - Hello world | |
| 20 | 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
@@ -26,7 +24,7 @@ namespace example1 | |||
| 26 | 24 | // Defines a domain. | |
| 27 | 25 | // Each domain represents a separate dependency graph, managed by a dedicated propagation engine. | |
| 28 | 26 | // Reactives of different domains can not be combined. | |
| 29 | - REACTIVE_DOMAIN(D, sequential) | ||
| 27 | + ReactiveGroup | ||
| 30 | 28 | ||
| 31 | 29 | // Define type aliases for the given domain in this namespace. | |
| 32 | 30 | // Now we can use VarSignalT instead of D::VarSignalT. | |
@@ -41,8 +39,8 @@ namespace example1 | |||
| 41 | 39 | namespace v1 | |
| 42 | 40 | { | |
| 43 | 41 | // The two words | |
| 44 | - VarSignalT<string> firstWord = MakeVar<D>(string("Change")); | ||
| 45 | - VarSignalT<string> secondWord = MakeVar<D>(string("me!")); | ||
| 42 | + VarSignalT<string> firstWord( string("Change") ); | ||
| 43 | + VarSignalT<string> secondWord( string("me!") ); | ||
| 46 | 44 | ||
| 47 | 45 | SignalT<string> bothWords = MakeSignal(With(firstWord,secondWord), concatFunc); | |
| 48 | 46 | ||
@@ -388,5 +386,32 @@ int main() | |||
| 388 | 386 | example5::v2::Run(); | |
| 389 | 387 | example5::v3::Run(); | |
| 390 | 388 | ||
| 389 | + return 0; | ||
| 390 | + } | ||
| 391 | + | ||
| 392 | + */ | ||
| 393 | + | ||
| 394 | + using namespace react; | ||
| 395 | + | ||
| 396 | + int main() | ||
| 397 | + { | ||
| 398 | + auto group = ReactiveGroup<shared>( ); | ||
| 399 | + | ||
| 400 | + auto sig1 = VarSignal<int, unique>( 1, group ); | ||
| 401 | + auto sig2 = VarSignal<int, shared>( 2, group ); | ||
| 402 | + | ||
| 403 | + sig1.Set(1); | ||
| 404 | + sig1 <<= 1; | ||
| 405 | + | ||
| 406 | + sig2.Modify([] (int& value) { value = 3; }); | ||
| 407 | + | ||
| 408 | + group.DoTransaction( | ||
| 409 | + [&] | ||
| 410 | + { | ||
| 411 | + sig1 <<= 2; | ||
| 412 | + }); | ||
| 413 | + | ||
| 414 | + auto sig3 = Signal<int, unique>( [] (auto a, auto b) { return a + b; }, sig1, sig2 ); | ||
| 415 | + | ||
| 391 | 416 | return 0; | |
| 392 | 417 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,118 @@ | |||
| 1 | + | ||
| 2 | + // Copyright Sebastian Jeckel 2016. | ||
| 3 | + // Distributed under the Boost Software License, Version 1.0. | ||
| 4 | + // (See accompanying file LICENSE_1_0.txt or copy at | ||
| 5 | + // http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | + | ||
| 7 | + #ifndef REACT_API_H_INCLUDED | ||
| 8 | + #define REACT_API_H_INCLUDED | ||
| 9 | + | ||
| 10 | + #pragma once | ||
| 11 | + | ||
| 12 | + #include "react/detail/Defs.h" | ||
| 13 | + #include "react/common/Util.h" | ||
| 14 | + | ||
| 15 | + /*****************************************/ REACT_BEGIN /*****************************************/ | ||
| 16 | + | ||
| 17 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 18 | + /// API constants | ||
| 19 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 20 | + enum OwnershipPolicy | ||
| 21 | + { | ||
| 22 | + unique, | ||
| 23 | + shared | ||
| 24 | + }; | ||
| 25 | + | ||
| 26 | + enum ThreadingPolicy | ||
| 27 | + { | ||
| 28 | + sequential, | ||
| 29 | + concurrent | ||
| 30 | + }; | ||
| 31 | + | ||
| 32 | + enum class WeightHint | ||
| 33 | + { | ||
| 34 | + automatic, | ||
| 35 | + light, | ||
| 36 | + heavy | ||
| 37 | + }; | ||
| 38 | + | ||
| 39 | + enum class TransactionFlags | ||
| 40 | + { | ||
| 41 | + none = 1 << 0, | ||
| 42 | + allow_merging = 1 << 1 | ||
| 43 | + }; | ||
| 44 | + | ||
| 45 | + REACT_DEFINE_BITMASK_OPERATORS(TransactionFlags) | ||
| 46 | + | ||
| 47 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 48 | + /// API types | ||
| 49 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 50 | + | ||
| 51 | + // Groups | ||
| 52 | + template <OwnershipPolicy = unique> | ||
| 53 | + class ReactiveGroup; | ||
| 54 | + | ||
| 55 | + // Signals | ||
| 56 | + template <typename T> | ||
| 57 | + class SignalBase; | ||
| 58 | + | ||
| 59 | + template <typename T> | ||
| 60 | + class VarSignalBase; | ||
| 61 | + | ||
| 62 | + template <typename T, OwnershipPolicy = unique> | ||
| 63 | + class Signal; | ||
| 64 | + | ||
| 65 | + template <typename T, OwnershipPolicy = unique> | ||
| 66 | + class VarSignal; | ||
| 67 | + | ||
| 68 | + // Events | ||
| 69 | + template <typename T> | ||
| 70 | + class EventBase; | ||
| 71 | + | ||
| 72 | + template <typename T> | ||
| 73 | + class EventSourceBase; | ||
| 74 | + | ||
| 75 | + template <typename T, OwnershipPolicy = unique> | ||
| 76 | + class Event; | ||
| 77 | + | ||
| 78 | + template <typename T, OwnershipPolicy = unique> | ||
| 79 | + class EventSource; | ||
| 80 | + | ||
| 81 | + enum class Token; | ||
| 82 | + | ||
| 83 | + // Observers | ||
| 84 | + class Observer; | ||
| 85 | + | ||
| 86 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 87 | + /// Traits | ||
| 88 | + /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 89 | + template <typename T> | ||
| 90 | + struct IsSignal { static const bool value = false; }; | ||
| 91 | + | ||
| 92 | + template <typename T, OwnershipPolicy ownership_policy> | ||
| 93 | + struct IsSignal<Signal<T, ownership_policy>> { static const bool value = true; }; | ||
| 94 | + | ||
| 95 | + template <typename T, OwnershipPolicy ownership_policy> | ||
| 96 | + struct IsSignal<VarSignal<T, ownership_policy>> { static const bool value = true; }; | ||
| 97 | + | ||
| 98 | + template <typename T> | ||
| 99 | + struct IsEvent { static const bool value = false; }; | ||
| 100 | + | ||
| 101 | + template <typename T, OwnershipPolicy ownership_policy> | ||
| 102 | + struct IsEvent<Event<T, ownership_policy>> { static const bool value = true; }; | ||
| 103 | + | ||
| 104 | + template <typename T, OwnershipPolicy ownership_policy> | ||
| 105 | + struct IsEvent<EventSource<T, ownership_policy>> { static const bool value = true; }; | ||
| 106 | + | ||
| 107 | + template <typename T> | ||
| 108 | + struct AsNonInputNode { using type = T; }; | ||
| 109 | + | ||
| 110 | + template <typename T, OwnershipPolicy ownership_policy> | ||
| 111 | + struct AsNonInputNode<VarSignal<T, ownership_policy>> { using type = Signal<T, ownership_policy>; }; | ||
| 112 | + | ||
| 113 | + template <typename T, OwnershipPolicy ownership_policy> | ||
| 114 | + struct AsNonInputNode<EventSource<T, ownership_policy>> { using type = Event<T, ownership_policy>; }; | ||
| 115 | + | ||
| 116 | + /******************************************/ REACT_END /******************************************/ | ||
| 117 | + | ||
| 118 | + #endif // REACT_TYPETRAITS_H_INCLUDED | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,32 +15,16 @@ | |||
| 15 | 15 | #include <type_traits> | |
| 16 | 16 | #include <utility> | |
| 17 | 17 | ||
| 18 | + #include "react/API.h" | ||
| 18 | 19 | #include "react/detail/graph/AlgorithmNodes.h" | |
| 19 | 20 | ||
| 20 | 21 | /*****************************************/ REACT_BEGIN /*****************************************/ | |
| 21 | 22 | ||
| 22 | - /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 23 | - /// Forward declarations | ||
| 24 | - /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 25 | - template <typename T> | ||
| 26 | - class Signal; | ||
| 27 | - | ||
| 28 | - template <typename T> | ||
| 29 | - class VarSignal; | ||
| 30 | - | ||
| 31 | - template <typename T> | ||
| 32 | - class Events; | ||
| 33 | - | ||
| 34 | - template <typename T> | ||
| 35 | - class EventSource; | ||
| 36 | - | ||
| 37 | - enum class Token; | ||
| 38 | - | ||
| 39 | 23 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 40 | 24 | /// Hold - Hold the most recent event in a signal | |
| 41 | 25 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 42 | - template <typename T, typename V> | ||
| 43 | - auto Hold(const Events<T>& events, V&& init) -> Signal<T> | ||
| 26 | + template <typename T, typename U> | ||
| 27 | + auto Hold(const Events<T>& events, U&& init) -> Signal<T> | ||
| 44 | 28 | { | |
| 45 | 29 | using REACT_IMPL::HoldNode; | |
| 46 | 30 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments