Skip to content

Commit 7992dc1

Browse files
committed
Cleanup.
1 parent 88e9430 commit 7992dc1

6 files changed

Lines changed: 60 additions & 66 deletions

File tree

include/react/EventStream.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ class REvents : public Reactive<EventStreamNode<D,E>>
3838
}
3939
};
4040

41+
////////////////////////////////////////////////////////////////////////////////////////
42+
namespace impl
43+
{
44+
45+
template <typename D, typename L, typename R>
46+
bool Equals(const REvents<D,L>& lhs, const REvents<D,R>& rhs)
47+
{
48+
return lhs.Equals(rhs);
49+
}
50+
51+
} // ~namespace react::impl
52+
4153
////////////////////////////////////////////////////////////////////////////////////////
4254
/// REventSource
4355
////////////////////////////////////////////////////////////////////////////////////////

include/react/ReactiveBase.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,16 @@ class Reactive
4444
std::shared_ptr<T> ptr_;
4545
};
4646

47+
////////////////////////////////////////////////////////////////////////////////////////
48+
namespace impl
49+
{
50+
51+
template <typename L, typename R>
52+
bool Equals(L lhs, R rhs)
53+
{
54+
return lhs == rhs;
55+
}
56+
57+
} // ~namespace react::impl
58+
4759
} // ~namespace react

include/react/Signal.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ class SignalNode;
2020
template <typename D, typename S>
2121
class VarNode;
2222

23+
template
24+
<
25+
typename D,
26+
typename S,
27+
typename ... TArgs
28+
>
29+
class FunctionNode;
30+
2331
////////////////////////////////////////////////////////////////////////////////////////
2432
/// RSignal
2533
////////////////////////////////////////////////////////////////////////////////////////
@@ -62,6 +70,18 @@ class RSignal : public Reactive<SignalNode<D,S>>
6270
}
6371
};
6472

73+
////////////////////////////////////////////////////////////////////////////////////////
74+
namespace impl
75+
{
76+
77+
template <typename D, typename L, typename R>
78+
bool Equals(const RSignal<D,L>& lhs, const RSignal<D,R>& rhs)
79+
{
80+
return lhs.Equals(rhs);
81+
}
82+
83+
} // ~namespace react::impl
84+
6585
////////////////////////////////////////////////////////////////////////////////////////
6686
/// RVarSignal
6787
////////////////////////////////////////////////////////////////////////////////////////

include/react/graph/EventStreamNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <algorithm>
55
#include <functional>
66
#include <memory>
7+
#include <thread>
78
#include <vector>
89

910
#include "tbb/spin_mutex.h"

include/react/graph/SignalNodes.h

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,10 @@
55
#include <tuple>
66

77
#include "GraphBase.h"
8-
#include "react/Signal.h"
9-
#include "react/EventStream.h"
108

119
////////////////////////////////////////////////////////////////////////////////////////
1210
namespace react {
1311

14-
template <typename T>
15-
class Reactive;
16-
17-
template <typename D, typename S>
18-
class RSignal;
19-
20-
template <typename D, typename E>
21-
class REvents;
22-
2312
////////////////////////////////////////////////////////////////////////////////////////
2413
/// SignalNode
2514
////////////////////////////////////////////////////////////////////////////////////////
@@ -64,7 +53,7 @@ class SignalNode : public ReactiveNode<D,S,S>
6453

6554
S operator()(void) const
6655
{
67-
return value_;
56+
return Value();
6857
}
6958

7059
const S& ValueRef() const
@@ -117,7 +106,7 @@ class VarNode : public SignalNode<D,S>
117106

118107
bool ApplyNewValue()
119108
{
120-
if (! equals(value_, newValue_))
109+
if (! impl::Equals(value_, newValue_))
121110
{
122111
value_ = newValue_;
123112
return true;
@@ -130,25 +119,6 @@ class VarNode : public SignalNode<D,S>
130119

131120
private:
132121
S newValue_;
133-
134-
template <typename L, typename R>
135-
static bool equals(L lhs, R rhs)
136-
{
137-
return lhs == rhs;
138-
}
139-
140-
// todo - ugly
141-
template <typename L, typename R>
142-
static bool equals(const REvents<D,L>& lhs, const REvents<D,R>& rhs)
143-
{
144-
return lhs.Equals(rhs);
145-
}
146-
147-
template <typename L, typename R>
148-
static bool equals(const RSignal<D,L>& lhs, const RSignal<D,R>& rhs)
149-
{
150-
return lhs.Equals(rhs);
151-
}
152122
};
153123

154124
////////////////////////////////////////////////////////////////////////////////////////
@@ -226,9 +196,7 @@ class FunctionNode : public SignalNode<D,S>
226196
S newValue = evaluate();
227197
D::Log().template Append<NodeEvaluateEndEvent>(GetObjectId(*this), turn.Id(), std::this_thread::get_id().hash());
228198

229-
230-
//if (newValue != value_)
231-
if (! equals(value_, newValue))
199+
if (! impl::Equals(value_, newValue))
232200
{
233201
value_ = newValue;
234202
Engine::OnNodePulse(*this, turn);
@@ -245,7 +213,7 @@ class FunctionNode : public SignalNode<D,S>
245213

246214
private:
247215
std::tuple<SignalNodePtr<D,TArgs> ...> deps_;
248-
std::function<S(TArgs ...)> func_;
216+
std::function<S(TArgs ...)> func_;
249217

250218
S evaluate() const
251219
{
@@ -256,25 +224,6 @@ class FunctionNode : public SignalNode<D,S>
256224
{
257225
return std::make_tuple(args->ValueRef() ...);
258226
}
259-
260-
template <typename L, typename R>
261-
static bool equals(L lhs, R rhs)
262-
{
263-
return lhs == rhs;
264-
}
265-
266-
// todo - ugly
267-
template <typename L, typename R>
268-
static bool equals(const REvents<D,L>& lhs, const REvents<D,R>& rhs)
269-
{
270-
return lhs.Equals(rhs);
271-
}
272-
273-
template <typename L, typename R>
274-
static bool equals(const RSignal<D,L>& lhs, const RSignal<D,R>& rhs)
275-
{
276-
return lhs.Equals(rhs);
277-
}
278227
};
279228

280229
////////////////////////////////////////////////////////////////////////////////////////

src/sandbox/Main.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ using namespace std;
1212
// Defines a domain.
1313
// Each domain represents a separate dependency graph, managed by a dedicated propagation engine.
1414
// Reactives of different domains can not be combined.
15-
REACTIVE_DOMAIN(TestDomain, SourceSetEngine);
15+
REACTIVE_DOMAIN(D, SourceSetEngine);
1616

1717

1818
void SignalExample1()
1919
{
2020
cout << "Signal Example 1" << endl;
2121

22-
auto width = TestDomain::MakeVar(60);
23-
auto height = TestDomain::MakeVar(70);
24-
auto depth = TestDomain::MakeVar(8);
22+
auto width = D::MakeVar(60);
23+
auto height = D::MakeVar(70);
24+
auto depth = D::MakeVar(8);
2525

2626
auto area = width * height;
2727
auto volume = area * depth;
@@ -44,9 +44,9 @@ void SignalExample2()
4444
{
4545
cout << "Signal Example 2" << endl;
4646

47-
auto width = TestDomain::MakeVar(60);
48-
auto height = TestDomain::MakeVar(70);
49-
auto depth = TestDomain::MakeVar(8);
47+
auto width = D::MakeVar(60);
48+
auto height = D::MakeVar(70);
49+
auto depth = D::MakeVar(8);
5050

5151
auto volume = (width,height,depth) >>= [] (int w, int h, int d) {
5252
return w * h * d;
@@ -61,7 +61,7 @@ void SignalExample2()
6161
});
6262

6363
{
64-
TestDomain::ScopedTransaction _;
64+
D::ScopedTransaction _;
6565
width <<= 90;
6666
depth <<= 80;
6767
}
@@ -73,8 +73,8 @@ void EventExample1()
7373
{
7474
cout << "Event Example 1" << endl;
7575

76-
auto numbers1 = TestDomain::MakeEventSource<int>();
77-
auto numbers2 = TestDomain::MakeEventSource<int>();
76+
auto numbers1 = D::MakeEventSource<int>();
77+
auto numbers2 = D::MakeEventSource<int>();
7878

7979
auto anyNumber = numbers1 | numbers2;
8080

@@ -88,7 +88,7 @@ void EventExample1()
8888
cout << endl;
8989
}
9090

91-
class Person : public ReactiveObject<TestDomain>
91+
class Person : public ReactiveObject<D>
9292
{
9393
public:
9494
VarSignal<int> Age = MakeVar(1);

0 commit comments

Comments
 (0)