Skip to content

Commit d13b3f4

Browse files
committed
Major redesign WIP.
1 parent 46dee49 commit d13b3f4

37 files changed

Lines changed: 1920 additions & 3287 deletions

examples/src/BasicSignals.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
#include <utility>
1212
#include <vector>
1313

14-
#include "react/Domain.h"
1514
#include "react/Signal.h"
16-
#include "react/Observer.h"
17-
15+
/*
1816
///////////////////////////////////////////////////////////////////////////////////////////////////
1917
/// Example 1 - Hello world
2018
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -26,7 +24,7 @@ namespace example1
2624
// Defines a domain.
2725
// Each domain represents a separate dependency graph, managed by a dedicated propagation engine.
2826
// Reactives of different domains can not be combined.
29-
REACTIVE_DOMAIN(D, sequential)
27+
ReactiveGroup
3028
3129
// Define type aliases for the given domain in this namespace.
3230
// Now we can use VarSignalT instead of D::VarSignalT.
@@ -41,8 +39,8 @@ namespace example1
4139
namespace v1
4240
{
4341
// 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!") );
4644
4745
SignalT<string> bothWords = MakeSignal(With(firstWord,secondWord), concatFunc);
4846
@@ -388,5 +386,32 @@ int main()
388386
example5::v2::Run();
389387
example5::v3::Run();
390388
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+
391416
return 0;
392417
}

include/react/API.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff 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

include/react/Algorithm.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,16 @@
1515
#include <type_traits>
1616
#include <utility>
1717

18+
#include "react/API.h"
1819
#include "react/detail/graph/AlgorithmNodes.h"
1920

2021
/*****************************************/ REACT_BEGIN /*****************************************/
2122

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-
3923
///////////////////////////////////////////////////////////////////////////////////////////////////
4024
/// Hold - Hold the most recent event in a signal
4125
///////////////////////////////////////////////////////////////////////////////////////////////////
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>
4428
{
4529
using REACT_IMPL::HoldNode;
4630

0 commit comments

Comments
 (0)