Skip to content

Commit 8b75a3f

Browse files
committed
Cleanup.
1 parent a9b6870 commit 8b75a3f

8 files changed

Lines changed: 78 additions & 96 deletions

File tree

include/react/Signal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ class RSignal : public Reactive<REACT_IMPL::SignalNode<D,S>>
5454
using NodeT = REACT_IMPL::SignalNode<D,S>;
5555

5656
public:
57-
struct SignalTag {};
58-
59-
typedef S ValueT;
57+
using ValueT = S;
6058

6159
RSignal() :
6260
Reactive()

include/react/common/Concurrency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class BlockingCondition
4949
}// ~mutex_
5050

5151
template <typename F>
52-
inline bool RunIfBlocked(F&& func)
52+
bool RunIfBlocked(F&& func)
5353
{// mutex_
5454
std::lock_guard<std::mutex> scopedLock(mutex_);
5555

include/react/graph/ConversionNodes.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class FoldBaseNode : public SignalNode<D,S>
4141

4242
virtual ETickResult Tick(void* turnPtr) override
4343
{
44-
typedef typename D::Engine::TurnInterface TurnInterface;
45-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
44+
using TurnT = typename D::Engine::TurnInterface;
45+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
4646

4747
D::Log().template Append<NodeEvaluateBeginEvent>(GetObjectId(*this), turn.Id(), std::this_thread::get_id().hash());
4848
S newValue = calcNewValue();
@@ -64,7 +64,7 @@ class FoldBaseNode : public SignalNode<D,S>
6464
virtual int DependencyCount() const override { return 1; }
6565

6666
protected:
67-
const EventStreamNodePtr<D,E> events_;
67+
EventStreamNodePtr<D,E> events_;
6868

6969
virtual S calcNewValue() const = 0;
7070
};
@@ -185,8 +185,8 @@ class HoldNode : public SignalNode<D,S>
185185

186186
virtual ETickResult Tick(void* turnPtr) override
187187
{
188-
typedef typename D::Engine::TurnInterface TurnInterface;
189-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
188+
using TurnT = typename D::Engine::TurnInterface;
189+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
190190

191191
D::Log().template Append<NodeEvaluateBeginEvent>(GetObjectId(*this), turn.Id(), std::this_thread::get_id().hash());
192192
S newValue = value_;
@@ -247,8 +247,8 @@ class SnapshotNode : public SignalNode<D,S>
247247

248248
virtual ETickResult Tick(void* turnPtr) override
249249
{
250-
typedef typename D::Engine::TurnInterface TurnInterface;
251-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
250+
using TurnT = typename D::Engine::TurnInterface;
251+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
252252

253253
trigger_->SetCurrentTurn(turn);
254254

@@ -275,7 +275,7 @@ class SnapshotNode : public SignalNode<D,S>
275275

276276
private:
277277
const SignalNodePtr<D,S> target_;
278-
const EventStreamNodePtr<D,E> trigger_;
278+
const EventStreamNodePtr<D,E> trigger_;
279279
};
280280

281281
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -308,8 +308,8 @@ class MonitorNode : public EventStreamNode<D,E>
308308

309309
virtual ETickResult Tick(void* turnPtr) override
310310
{
311-
typedef typename D::Engine::TurnInterface TurnInterface;
312-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
311+
using TurnT = typename D::Engine::TurnInterface;
312+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
313313

314314
SetCurrentTurn(turn, true);
315315

@@ -395,8 +395,8 @@ class PulseNode : public EventStreamNode<D,S>
395395
virtual int DependencyCount() const { return 2; }
396396

397397
private:
398-
const SignalNodePtr<D, S> target_;
399-
const EventStreamNodePtr<D, E> trigger_;
398+
const SignalNodePtr<D, S> target_;
399+
const EventStreamNodePtr<D, E> trigger_;
400400
};
401401

402402
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -476,7 +476,7 @@ class EventFlattenNode : public EventStreamNode<D, TInner>
476476
virtual int DependencyCount() const override { return 2; }
477477

478478
private:
479-
SignalNodePtr<D,TOuter> outer_;
479+
SignalNodePtr<D,TOuter> outer_;
480480
EventStreamNodePtr<D,TInner> inner_;
481481
};
482482

include/react/graph/EventStreamNodes.h

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,25 @@ template
3434
class EventStreamNode : public ReactiveNode<D,E,void>
3535
{
3636
public:
37-
typedef std::vector<E> EventListT;
38-
typedef tbb::spin_mutex EventMutexT;
37+
using EventListT = std::vector<E>;
38+
using EventMutexT = tbb::spin_mutex;
3939

40-
typedef std::shared_ptr<EventStreamNode> NodePtrT;
41-
typedef std::weak_ptr<EventStreamNode> NodeWeakPtrT;
40+
using PtrT = std::shared_ptr<EventStreamNode>;
41+
using WeakPtrT = std::weak_ptr<EventStreamNode>;
4242

43-
typedef typename D::Engine EngineT;
44-
typedef typename EngineT::TurnInterface TurnInterface;
43+
using EngineT = typename D::Engine;
44+
using TurnT = typename EngineT::TurnInterface;
4545

4646
explicit EventStreamNode(bool registered) :
47-
ReactiveNode(true),
48-
curTurnId_{ INT_MAX }
47+
ReactiveNode(true)
4948
{
5049
if (!registered)
5150
registerNode();
5251
}
5352

5453
virtual const char* GetNodeType() const override { return "EventStreamNode"; }
5554

56-
EventListT& Events()
57-
{
58-
return events_;
59-
}
60-
61-
void SetCurrentTurn(const TurnInterface& turn, bool forceUpdate = false, bool noClear = false)
55+
void SetCurrentTurn(const TurnT& turn, bool forceUpdate = false, bool noClear = false)
6256
{// eventMutex_
6357
EventMutexT::scoped_lock lock(eventMutex_);
6458

@@ -70,21 +64,21 @@ class EventStreamNode : public ReactiveNode<D,E,void>
7064
}
7165
}// ~eventMutex_
7266

73-
void ClearEvents() { events_.clear(); }
74-
75-
const E& Front() { events_.front(); }
67+
EventListT& Events() { return events_; }
68+
void ClearEvents() { events_.clear(); }
7669

7770
protected:
78-
EventListT events_;
79-
EventMutexT eventMutex_;
80-
uint curTurnId_;
71+
EventListT events_;
72+
EventMutexT eventMutex_;
73+
74+
uint curTurnId_ = INT_MAX;
8175
};
8276

8377
template <typename D, typename E>
84-
using EventStreamNodePtr = typename EventStreamNode<D,E>::NodePtrT;
78+
using EventStreamNodePtr = typename EventStreamNode<D,E>::PtrT;
8579

8680
template <typename D, typename E>
87-
using EventStreamNodeWeakPtr = typename EventStreamNode<D,E>::NodeWeakPtrT;
81+
using EventStreamNodeWeakPtr = typename EventStreamNode<D,E>::WeakPtrT;
8882

8983
///////////////////////////////////////////////////////////////////////////////////////////////////
9084
/// EventSourceNode
@@ -110,8 +104,8 @@ class EventSourceNode : public EventStreamNode<D,E>
110104
{
111105
if (events_.size() > 0 && !changedFlag_)
112106
{
113-
typedef typename D::Engine::TurnInterface TurnInterface;
114-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
107+
using TurnT = typename D::Engine::TurnInterface;
108+
TurnT& turn = *static_cast<TurnInterface*>(turnPtr);
115109

116110
SetCurrentTurn(turn, true, true);
117111
changedFlag_ = true;
@@ -155,9 +149,6 @@ template
155149
class EventMergeNode : public EventStreamNode<D, E>
156150
{
157151
public:
158-
typedef typename D::Engine EngineT;
159-
typedef typename EngineT::TurnInterface TurnInterface;
160-
161152
EventMergeNode(const EventStreamNodePtr<D, TArgs>& ... args, bool registered) :
162153
EventStreamNode<D, E>(true),
163154
deps_{ make_tuple(args ...) },
@@ -185,8 +176,8 @@ class EventMergeNode : public EventStreamNode<D, E>
185176

186177
virtual ETickResult Tick(void* turnPtr) override
187178
{
188-
189-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
179+
using TurnT = typename D::Engine::TurnInterface;
180+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
190181

191182
//printf("EventMergeNode: Tick %08X by thread %08X\n", this, std::this_thread::get_id().hash());
192183

@@ -211,8 +202,8 @@ class EventMergeNode : public EventStreamNode<D, E>
211202
virtual int DependencyCount() const override { return sizeof... (TArgs); }
212203

213204
private:
214-
std::tuple<EventStreamNodePtr<D, TArgs> ...> deps_;
215-
std::function<void(const TurnInterface&)> func_;
205+
const std::tuple<EventStreamNodePtr<D, TArgs> ...> deps_;
206+
const std::function<void(const TurnInterface&)> func_;
216207

217208
inline void expand(const TurnInterface& turn, const EventStreamNodePtr<D, TArgs>& ... args)
218209
{
@@ -260,9 +251,8 @@ class EventFilterNode : public EventStreamNode<D, E>
260251

261252
virtual ETickResult Tick(void* turnPtr) override
262253
{
263-
typedef typename D::Engine EngineT;
264-
typedef typename EngineT::TurnInterface TurnInterface;
265-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
254+
using TurnT = typename D::Engine::TurnInterface;
255+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
266256

267257
SetCurrentTurn(turn, true);
268258

@@ -285,9 +275,8 @@ class EventFilterNode : public EventStreamNode<D, E>
285275
virtual int DependencyCount() const override { return 1; }
286276

287277
private:
288-
EventStreamNodePtr<D,E> src_;
289-
290-
std::function<bool(const E&)> filter_;
278+
const EventStreamNodePtr<D,E> src_;
279+
const std::function<bool(const E&)> filter_;
291280
};
292281

293282
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -323,9 +312,8 @@ class EventTransformNode : public EventStreamNode<D,TOut>
323312

324313
virtual ETickResult Tick(void* turnPtr) override
325314
{
326-
typedef typename D::Engine EngineT;
327-
typedef typename EngineT::TurnInterface TurnInterface;
328-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
315+
using TurnT = typename D::Engine::TurnInterface;
316+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
329317

330318
SetCurrentTurn(turn, true);
331319

@@ -348,9 +336,8 @@ class EventTransformNode : public EventStreamNode<D,TOut>
348336
virtual int DependencyCount() const override { return 1; }
349337

350338
private:
351-
EventStreamNodePtr<D,TIn> src_;
352-
353-
std::function<TOut(const TIn&)> func_;
339+
const EventStreamNodePtr<D,TIn> src_;
340+
const std::function<TOut(const TIn&)> func_;
354341
};
355342

356343
/****************************************/ REACT_IMPL_END /***************************************/

include/react/graph/GraphBase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class NodeBase :
3737
virtual const char* GetNodeType() const override { return "NodeBase"; }
3838

3939
virtual bool IsInputNode() const override { return false; }
40-
virtual bool IsOutputNode() const override { return false; }
41-
virtual bool IsDynamicNode() const override { return false; }
40+
virtual bool IsOutputNode() const override { return false; }
41+
virtual bool IsDynamicNode() const override { return false; }
4242

43-
virtual int DependencyCount() const { return 0; }
43+
virtual int DependencyCount() const { return 0; }
4444

4545
PtrT GetSharedPtr() const
4646
{

include/react/graph/ObserverNodes.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ class ObserverNode :
3131
public IObserverNode
3232
{
3333
public:
34-
typedef std::shared_ptr<ObserverNode> NodePtr;
34+
using PtrT = std::shared_ptr<ObserverNode>;
3535

3636
explicit ObserverNode(bool registered) :
3737
ReactiveNode<D,void,void>(true)
3838
{
3939
}
4040

41-
virtual const char* GetNodeType() const { return "ObserverNode"; }
42-
virtual bool IsOutputNode() const { return true; }
41+
virtual const char* GetNodeType() const { return "ObserverNode"; }
42+
virtual bool IsOutputNode() const { return true; }
4343
};
4444

4545
template <typename D>
46-
using ObserverNodePtr = typename ObserverNode<D>::NodePtr;
46+
using ObserverNodePtr = typename ObserverNode<D>::PtrT;
4747

4848
///////////////////////////////////////////////////////////////////////////////////////////////////
4949
/// SignalObserverNode
@@ -74,8 +74,8 @@ class SignalObserverNode : public ObserverNode<D>
7474

7575
virtual ETickResult Tick(void* turnPtr) override
7676
{
77-
typedef typename D::Engine::TurnInterface TurnInterface;
78-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
77+
using TurnT = typename D::Engine::TurnInterface;
78+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
7979

8080
D::Log().template Append<NodeEvaluateBeginEvent>(GetObjectId(*this), turn.Id(), std::this_thread::get_id().hash());
8181

@@ -109,8 +109,8 @@ class SignalObserverNode : public ObserverNode<D>
109109
}
110110

111111
private:
112-
SignalNodeWeakPtr<D,TArg> subject_;
113-
std::function<void(TArg)> func_;
112+
SignalNodeWeakPtr<D,TArg> subject_;
113+
const std::function<void(TArg)> func_;
114114
};
115115

116116
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -142,8 +142,8 @@ class EventObserverNode : public ObserverNode<D>
142142

143143
virtual ETickResult Tick(void* turnPtr) override
144144
{
145-
typedef typename D::Engine::TurnInterface TurnInterface;
146-
TurnInterface& turn = *static_cast<TurnInterface*>(turnPtr);
145+
using TurnT = typename D::Engine::TurnInterface;
146+
TurnT& turn = *static_cast<TurnT*>(turnPtr);
147147

148148
D::Log().template Append<NodeEvaluateBeginEvent>(GetObjectId(*this), turn.Id(), std::this_thread::get_id().hash());
149149

@@ -181,8 +181,8 @@ class EventObserverNode : public ObserverNode<D>
181181
}
182182

183183
private:
184-
EventStreamNodeWeakPtr<D,TArg> subject_;
185-
std::function<void(TArg)> func_;
184+
EventStreamNodeWeakPtr<D,TArg> subject_;
185+
const std::function<void(TArg)> func_;
186186
};
187187

188188
/****************************************/ REACT_IMPL_END /***************************************/

include/react/graph/ReactorNodes.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,18 @@ class ReactorNode :
187187
bool checkEvent(const EventStreamNodePtr<D,E>& events)
188188
{
189189
if (turnPtr_ == nullptr)
190-
{
191190
return false;
192-
}
193191

194192
events->SetCurrentTurn(*turnPtr_);
195193
return offsets_[reinterpret_cast<uintptr_t>(&events)] < events->Events().size();
196194
}
197195

198196
std::function<void(TContext&)> func_;
199197

200-
LoopT mainLoop_;
201-
TurnT* turnPtr_;
198+
LoopT mainLoop_;
199+
TurnT* turnPtr_;
202200

203-
OutT* curOutPtr_ = nullptr;
201+
OutT* curOutPtr_ = nullptr;
204202

205203
int depCount_ = 0;
206204

0 commit comments

Comments
 (0)