Skip to content

Commit 8d9e9b6

Browse files
committed
Moved some definitions from ReactiveDomain.h to separate files to unwind include mess.
1 parent a808e32 commit 8d9e9b6

15 files changed

Lines changed: 394 additions & 284 deletions

File tree

include/react/Observer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <memory>
1212
#include <unordered_map>
1313

14+
#include "react/interface/IReactiveNode.h"
15+
1416
#include "react/graph/ObserverNodes.h"
1517

1618
/***********************************/ REACT_BEGIN /************************************/

include/react/Options.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// Copyright Sebastian Jeckel 2014.
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+
#pragma once
8+
9+
#include "react/Defs.h"
10+
11+
/***********************************/ REACT_BEGIN /************************************/
12+
13+
////////////////////////////////////////////////////////////////////////////////////////
14+
/// CommitFlags
15+
////////////////////////////////////////////////////////////////////////////////////////
16+
enum ETurnFlags
17+
{
18+
enable_input_merging = 1 << 0
19+
};
20+
21+
/************************************/ REACT_END /*************************************/

include/react/ReactiveDomain.h

Lines changed: 6 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,26 @@
1111
#include <atomic>
1212
#include <functional>
1313
#include <memory>
14+
#include <utility>
1415

1516
#include "tbb/concurrent_vector.h"
1617
#include "tbb/queuing_mutex.h"
1718
#include "tbb/spin_mutex.h"
1819

19-
#include "Observer.h"
20+
#include "react/Observer.h"
21+
#include "react/Options.h"
22+
#include "react/Traits.h"
2023

24+
#include "react/common/ContinuationInput.h"
2125
#include "react/common/Types.h"
26+
2227
#include "react/logging/EventLog.h"
2328
#include "react/logging/EventRecords.h"
2429

2530
#include "react/propagation/TopoSortEngine.h"
2631

2732
/***********************************/ REACT_BEGIN /************************************/
2833

29-
template <typename D, typename S>
30-
class RSignal;
31-
32-
template <typename D, typename S>
33-
class RVarSignal;
34-
35-
template <typename D, typename S>
36-
using RRefSignal = RSignal<D,std::reference_wrapper<S>>;
37-
38-
template <typename D, typename S>
39-
using RVarRefSignal = RVarSignal<D,std::reference_wrapper<S>>;
40-
41-
template <typename D, typename E>
42-
class REvents;
43-
44-
template <typename D, typename E>
45-
class REventSource;
46-
4734
enum class EventToken;
4835

4936
template
@@ -55,186 +42,10 @@ template
5542
auto MakeSignal(F&& func, const RSignal<D,TArgs>& ... args)
5643
-> RSignal<D, typename std::result_of<F(TArgs...)>::type>;
5744

58-
////////////////////////////////////////////////////////////////////////////////////////
59-
/// IsSignalT
60-
////////////////////////////////////////////////////////////////////////////////////////
61-
template <typename D, typename T>
62-
struct IsSignalT { static const bool value = false; };
63-
64-
template <typename D, typename T>
65-
struct IsSignalT<D, RSignal<D,T>> { static const bool value = true; };
66-
67-
template <typename D, typename T>
68-
struct IsSignalT<D, RVarSignal<D,T>> { static const bool value = true; };
69-
70-
////////////////////////////////////////////////////////////////////////////////////////
71-
/// IsEventT
72-
////////////////////////////////////////////////////////////////////////////////////////
73-
template <typename D, typename T>
74-
struct IsEventT { static const bool value = false; };
75-
76-
template <typename D, typename T>
77-
struct IsEventT<D, REvents<D,T>> { static const bool value = true; };
78-
79-
template <typename D, typename T>
80-
struct IsEventT<D, REventSource<D,T>> { static const bool value = true; };
81-
82-
/************************************/ REACT_END /*************************************/
83-
84-
/*********************************/ REACT_IMPL_BEGIN /*********************************/
85-
86-
////////////////////////////////////////////////////////////////////////////////////////
87-
/// ContinuationInput
88-
////////////////////////////////////////////////////////////////////////////////////////
89-
class ContinuationInput
90-
{
91-
public:
92-
using InputClosureT = std::function<void()>;
93-
using InputVectT = tbb::concurrent_vector<InputClosureT>;
94-
95-
// Note: Shouldn't this be generated by default? Apparently it isn't.
96-
inline ContinuationInput& operator=(ContinuationInput&& other)
97-
{
98-
bufferedInputsPtr_ = std::move(other.bufferedInputsPtr_);
99-
return *this;
100-
}
101-
102-
inline bool IsEmpty() const { return bufferedInputsPtr_ == nullptr; }
103-
104-
template <typename F>
105-
void Add(F&& input)
106-
{
107-
if (bufferedInputsPtr_ == nullptr)
108-
bufferedInputsPtr_ = std::unique_ptr<InputVectT>(new InputVectT());
109-
bufferedInputsPtr_->push_back(std::forward<F>(input));
110-
}
111-
112-
inline void Execute()
113-
{
114-
if (bufferedInputsPtr_ != nullptr)
115-
{
116-
for (auto f : *bufferedInputsPtr_)
117-
f();
118-
bufferedInputsPtr_->clear();
119-
}
120-
}
121-
122-
private:
123-
std::unique_ptr<InputVectT> bufferedInputsPtr_ = nullptr;
124-
};
125-
126-
/**********************************/ REACT_IMPL_END /**********************************/
127-
128-
/***********************************/ REACT_BEGIN /************************************/
129-
130-
////////////////////////////////////////////////////////////////////////////////////////
131-
/// CommitFlags
132-
////////////////////////////////////////////////////////////////////////////////////////
133-
enum ETurnFlags
134-
{
135-
enable_input_merging = 1 << 0
136-
};
137-
13845
/************************************/ REACT_END /*************************************/
13946

14047
/*********************************/ REACT_IMPL_BEGIN /*********************************/
14148

142-
////////////////////////////////////////////////////////////////////////////////////////
143-
/// EngineInterface
144-
////////////////////////////////////////////////////////////////////////////////////////
145-
template
146-
<
147-
typename D,
148-
typename TEngine
149-
>
150-
struct EngineInterface
151-
{
152-
using NodeInterface = typename TEngine::NodeInterface;
153-
using TurnInterface = typename TEngine::TurnInterface;
154-
155-
static TEngine& Engine()
156-
{
157-
static TEngine engine;
158-
return engine;
159-
}
160-
161-
static void OnNodeCreate(NodeInterface& node)
162-
{
163-
D::Log().template Append<NodeCreateEvent>(GetObjectId(node), node.GetNodeType());
164-
Engine().OnNodeCreate(node);
165-
}
166-
167-
static void OnNodeDestroy(NodeInterface& node)
168-
{
169-
D::Log().template Append<NodeDestroyEvent>(GetObjectId(node));
170-
Engine().OnNodeDestroy(node);
171-
}
172-
173-
static void OnNodeAttach(NodeInterface& node, NodeInterface& parent)
174-
{
175-
D::Log().template Append<NodeAttachEvent>(GetObjectId(node), GetObjectId(parent));
176-
Engine().OnNodeAttach(node, parent);
177-
}
178-
179-
static void OnNodeDetach(NodeInterface& node, NodeInterface& parent)
180-
{
181-
D::Log().template Append<NodeDetachEvent>(GetObjectId(node), GetObjectId(parent));
182-
Engine().OnNodeDetach(node, parent);
183-
}
184-
185-
static void OnNodePulse(NodeInterface& node, TurnInterface& turn)
186-
{
187-
D::Log().template Append<NodePulseEvent>(GetObjectId(node), turn.Id());
188-
Engine().OnNodePulse(node, turn);
189-
}
190-
191-
static void OnNodeIdlePulse(NodeInterface& node, TurnInterface& turn)
192-
{
193-
D::Log().template Append<NodeIdlePulseEvent>(GetObjectId(node), turn.Id());
194-
Engine().OnNodeIdlePulse(node, turn);
195-
}
196-
197-
static void OnNodeShift(NodeInterface& node, NodeInterface& oldParent, NodeInterface& newParent, TurnInterface& turn)
198-
{
199-
D::Log().template Append<NodeInvalidateEvent>(GetObjectId(node), GetObjectId(oldParent), GetObjectId(newParent), turn.Id());
200-
Engine().OnNodeShift(node, oldParent, newParent, turn);
201-
}
202-
203-
static void OnTurnAdmissionStart(TurnInterface& turn)
204-
{
205-
D::Log().template Append<TransactionBeginEvent>(turn.Id());
206-
Engine().OnTurnAdmissionStart(turn);
207-
}
208-
209-
static void OnTurnAdmissionEnd(TurnInterface& turn)
210-
{
211-
Engine().OnTurnAdmissionEnd(turn);
212-
}
213-
214-
static void OnTurnEnd(TurnInterface& turn)
215-
{
216-
D::Log().template Append<TransactionEndEvent>(turn.Id());
217-
Engine().OnTurnEnd(turn);
218-
}
219-
220-
static void OnTurnInputChange(NodeInterface& node, TurnInterface& turn)
221-
{
222-
D::Log().template Append<InputNodeAdmissionEvent>(GetObjectId(node), turn.Id());
223-
Engine().OnTurnInputChange(node, turn);
224-
}
225-
226-
static void OnTurnPropagate(TurnInterface& turn)
227-
{
228-
Engine().OnTurnPropagate(turn);
229-
}
230-
231-
template <typename F>
232-
static bool TryMerge(F&& f)
233-
{
234-
return Engine().TryMerge(std::forward<F>(f));
235-
}
236-
};
237-
23849
////////////////////////////////////////////////////////////////////////////////////////
23950
/// Domain
24051
////////////////////////////////////////////////////////////////////////////////////////
@@ -249,9 +60,6 @@ struct DomainPolicy
24960
using Log = TLog;
25061
};
25162

252-
using TurnIdT = uint;
253-
using TurnFlagsT = uint;
254-
25563
template <typename D, typename TPolicy>
25664
class DomainBase
25765
{

include/react/Signal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ template
4848
typename D,
4949
typename S
5050
>
51-
class RSignal : public Reactive< REACT_IMPL::SignalNode<D,S>>
51+
class RSignal : public Reactive<REACT_IMPL::SignalNode<D,S>>
5252
{
5353
protected:
5454
using NodeT = REACT_IMPL::SignalNode<D,S>;

include/react/Traits.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
// Copyright Sebastian Jeckel 2014.
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+
#pragma once
8+
9+
#include "react/Defs.h"
10+
11+
/***********************************/ REACT_BEGIN /************************************/
12+
13+
template <typename D, typename S>
14+
class RSignal;
15+
16+
template <typename D, typename S>
17+
class RVarSignal;
18+
19+
template <typename D, typename S>
20+
using RRefSignal = RSignal<D,std::reference_wrapper<S>>;
21+
22+
template <typename D, typename S>
23+
using RVarRefSignal = RVarSignal<D,std::reference_wrapper<S>>;
24+
25+
template <typename D, typename E>
26+
class REvents;
27+
28+
template <typename D, typename E>
29+
class REventSource;
30+
31+
enum class EventToken;
32+
33+
template
34+
<
35+
typename D,
36+
typename F,
37+
typename ... TArgs
38+
>
39+
auto MakeSignal(F&& func, const RSignal<D,TArgs>& ... args)
40+
-> RSignal<D, typename std::result_of<F(TArgs...)>::type>;
41+
42+
////////////////////////////////////////////////////////////////////////////////////////
43+
/// IsSignalT
44+
////////////////////////////////////////////////////////////////////////////////////////
45+
template <typename D, typename T>
46+
struct IsSignalT { static const bool value = false; };
47+
48+
template <typename D, typename T>
49+
struct IsSignalT<D, RSignal<D,T>> { static const bool value = true; };
50+
51+
template <typename D, typename T>
52+
struct IsSignalT<D, RVarSignal<D,T>> { static const bool value = true; };
53+
54+
////////////////////////////////////////////////////////////////////////////////////////
55+
/// IsEventT
56+
////////////////////////////////////////////////////////////////////////////////////////
57+
template <typename D, typename T>
58+
struct IsEventT { static const bool value = false; };
59+
60+
template <typename D, typename T>
61+
struct IsEventT<D, REvents<D,T>> { static const bool value = true; };
62+
63+
template <typename D, typename T>
64+
struct IsEventT<D, REventSource<D,T>> { static const bool value = true; };
65+
66+
/************************************/ REACT_END /*************************************/

0 commit comments

Comments
 (0)