Skip to content

Commit 55fbe9b

Browse files
committed
Removed obsolete files.
Added more tests.
1 parent df1bf4b commit 55fbe9b

23 files changed

Lines changed: 1065 additions & 2862 deletions

‎include/react/algorithm.h‎

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

18-
#include "react/API.h"
19-
#include "react/detail/algorithm_nodes.h"
20-
18+
#include "react/api.h"
2119
#include "react/state.h"
2220
#include "react/event.h"
2321

22+
#include "react/detail/algorithm_nodes.h"
23+
2424
/*****************************************/ REACT_BEGIN /*****************************************/
2525

2626
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -66,7 +66,6 @@ template <typename S, typename T, typename F, typename E>
6666
auto Iterate(const Group& group, T&& initialValue, F&& func, const Event<E>& evnt) -> State<S>
6767
{
6868
using REACT_IMPL::IterateNode;
69-
using REACT_IMPL::IsCallableWith;
7069
using REACT_IMPL::SameGroupOrLink;
7170
using REACT_IMPL::CreateWrappedNode;
7271

@@ -80,7 +79,6 @@ template <typename S, typename T, typename F, typename E>
8079
auto IterateByRef(const Group& group, T&& initialValue, F&& func, const Event<E>& evnt) -> State<S>
8180
{
8281
using REACT_IMPL::IterateByRefNode;
83-
using REACT_IMPL::IsCallableWith;
8482
using REACT_IMPL::SameGroupOrLink;
8583
using REACT_IMPL::CreateWrappedNode;
8684

@@ -105,7 +103,6 @@ template <typename S, typename T, typename F, typename E, typename ... Us>
105103
auto Iterate(const Group& group, T&& initialValue, F&& func, const Event<E>& evnt, const State<Us>& ... states) -> State<S>
106104
{
107105
using REACT_IMPL::SyncedIterateNode;
108-
using REACT_IMPL::IsCallableWith;
109106
using REACT_IMPL::SameGroupOrLink;
110107
using REACT_IMPL::CreateWrappedNode;
111108

@@ -119,7 +116,6 @@ template <typename S, typename T, typename F, typename E, typename ... Us>
119116
auto IterateByRef(const Group& group, T&& initialValue, F&& func, const Event<E>& evnt, const State<Us>& ... states) -> State<S>
120117
{
121118
using REACT_IMPL::SyncedIterateByRefNode;
122-
using REACT_IMPL::IsCallableWith;
123119
using REACT_IMPL::SameGroupOrLink;
124120
using REACT_IMPL::CreateWrappedNode;
125121

‎include/react/api.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ enum class TransactionFlags
3333

3434
REACT_DEFINE_BITMASK_OPERATORS(TransactionFlags)
3535

36+
enum class Token { value };
37+
3638
///////////////////////////////////////////////////////////////////////////////////////////////////
3739
/// API types
3840
///////////////////////////////////////////////////////////////////////////////////////////////////

‎include/react/detail/algorithm_nodes.h‎

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class IterateNode : public StateNode<S>
4444

4545
virtual UpdateResult Update(TurnId turnId) noexcept override
4646
{
47-
S newValue = func_(EventRange<E>( GetInternals(evnt_).Events() ), this->Value());
47+
S newValue = func_(GetInternals(evnt_).Events(), this->Value());
4848

4949
if (! (newValue == this->Value()))
5050
{
@@ -81,15 +81,15 @@ class IterateByRefNode : public StateNode<S>
8181

8282
~IterateByRefNode()
8383
{
84-
this->DetachFromMe(GetInternals(evnt).GetNodeId());
84+
this->DetachFromMe(GetInternals(evnt_).GetNodeId());
8585
this->UnregisterMe();
8686
}
8787

8888
virtual UpdateResult Update(TurnId turnId) noexcept override
8989
{
90-
func_(EventRange<E>( GetInternals(evnt_).Events() ), this->Value());
90+
func_(GetInternals(evnt_).Events(), this->Value());
9191

92-
// Always assume change
92+
// Always assume a change
9393
return UpdateResult::changed;
9494
}
9595

@@ -119,7 +119,8 @@ class SyncedIterateNode : public StateNode<S>
119119

120120
~SyncedIterateNode()
121121
{
122-
apply([this] (const auto& ... syncs) { REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_);
122+
apply([this] (const auto& ... syncs)
123+
{ REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_);
123124
this->DetachFromMe(GetInternals(evnt_).GetNodeId());
124125
this->UnregisterMe();
125126
}
@@ -130,12 +131,10 @@ class SyncedIterateNode : public StateNode<S>
130131
if (GetInternals(evnt_).Events().empty())
131132
return UpdateResult::unchanged;
132133

133-
S newValue = apply(
134-
[this] (const auto& ... syncs)
134+
S newValue = apply([this] (const auto& ... syncs)
135135
{
136-
return func_(EventRange<E>( GetInternals(evnt_).Events() ), this->Value(), GetInternals(syncs).Value() ...);
137-
},
138-
syncHolder_);
136+
return func_(GetInternals(evnt_).Events(), this->Value(), GetInternals(syncs).Value() ...);
137+
}, syncHolder_);
139138

140139
if (! (newValue == this->Value()))
141140
{
@@ -190,7 +189,7 @@ class SyncedIterateByRefNode : public StateNode<S>
190189
apply(
191190
[this] (const auto& ... args)
192191
{
193-
func_(EventRange<E>( GetInternals(evnt_).Events() ), this->Value(), GetInternals(args).Value() ...);
192+
func_(GetInternals(evnt_).Events(), this->Value(), GetInternals(args).Value() ...);
194193
},
195194
syncHolder_);
196195

@@ -199,7 +198,7 @@ class SyncedIterateByRefNode : public StateNode<S>
199198

200199
private:
201200
F func_;
202-
Event<E> events_;
201+
Event<E> evnt_;
203202

204203
std::tuple<State<TSyncs> ...> syncHolder_;
205204
};
@@ -305,75 +304,70 @@ class SnapshotNode : public StateNode<S>
305304
/// MonitorNode
306305
///////////////////////////////////////////////////////////////////////////////////////////////////
307306
template <typename S>
308-
class MonitorNode : public EventStreamNode<S>
307+
class MonitorNode : public EventNode<S>
309308
{
310309
public:
311-
MonitorNode(const Group& group, const State<S>& target) :
312-
MonitorNode::EventStreamNode( group ),
313-
target_( target )
310+
MonitorNode(const Group& group, const State<S>& input) :
311+
MonitorNode::EventNode( group ),
312+
input_( input )
314313
{
315314
this->RegisterMe();
316-
this->AttachToMe(GetInternals(target).GetNodeId());
315+
this->AttachToMe(GetInternals(input_).GetNodeId());
317316
}
318317

319318
~MonitorNode()
320319
{
321-
this->DetachFromMe(GetInternals(target_).GetNodeId());
320+
this->DetachFromMe(GetInternals(input_).GetNodeId());
322321
this->UnregisterMe();
323322
}
324323

325324
virtual UpdateResult Update(TurnId turnId) noexcept override
326325
{
327-
this->Events().push_back(GetInternals(target_).Value());
328-
326+
this->Events().push_back(GetInternals(input_).Value());
329327
return UpdateResult::changed;
330328
}
331329

332330
private:
333-
State<S> target_;
331+
State<S> input_;
334332
};
335333

336334
///////////////////////////////////////////////////////////////////////////////////////////////////
337335
/// PulseNode
338336
///////////////////////////////////////////////////////////////////////////////////////////////////
339337
template <typename S, typename E>
340-
class PulseNode : public EventStreamNode<S>
338+
class PulseNode : public EventNode<S>
341339
{
342340
public:
343-
PulseNode(const Group& group, const State<S>& target, const Event<E>& trigger) :
344-
PulseNode::EventStreamNode( group ),
345-
target_( target ),
341+
PulseNode(const Group& group, const State<S>& input, const Event<E>& trigger) :
342+
PulseNode::EventNode( group ),
343+
input_( input ),
346344
trigger_( trigger )
347345
{
348346
this->RegisterMe();
349-
this->AttachToMe(GetInternals(target).GetNodeId());
347+
this->AttachToMe(GetInternals(input).GetNodeId());
350348
this->AttachToMe(GetInternals(trigger).GetNodeId());
351349
}
352350

353351
~PulseNode()
354352
{
355353
this->DetachFromMe(GetInternals(trigger_).GetNodeId());
356-
this->DetachFromMe(GetInternals(target_).GetNodeId());
354+
this->DetachFromMe(GetInternals(input_).GetNodeId());
357355
this->UnregisterMe();
358356
}
359357

360358
virtual UpdateResult Update(TurnId turnId) noexcept override
361359
{
362-
for (size_t i = 0; i < GetInternals(trigger_).Events().size(); i++)
363-
this->Events().push_back(GetInternals(target_).Value());
360+
for (size_t i = 0; i < GetInternals(trigger_).Events().size(); ++i)
361+
this->Events().push_back(GetInternals(input_).Value());
364362

365363
if (! this->Events().empty())
366-
{
367364
return UpdateResult::changed;
368-
}
369365
else
370-
{
371366
return UpdateResult::unchanged;
372-
}
373367
}
374368

375369
private:
376-
State<S> target_;
370+
State<S> input_;
377371
Event<E> trigger_;
378372
};
379373

‎include/react/detail/event_nodes.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,27 @@ class SyncedEventProcessingNode : public EventNode<TOut>
285285
syncHolder_( syncs ... )
286286
{
287287
this->RegisterMe();
288-
this->AttachToMe(dep->GetNodeId());
289-
REACT_EXPAND_PACK(this->AttachToMe(syncs->GetNodeId()));
288+
this->AttachToMe(GetInternals(dep).GetNodeId());
289+
REACT_EXPAND_PACK(this->AttachToMe(GetInternals(syncs).GetNodeId()));
290290
}
291291

292292
~SyncedEventProcessingNode()
293293
{
294-
apply([this] (const auto& ... syncs) { REACT_EXPAND_PACK(this->DetachFromMe(syncs->GetNodeId())); }, syncHolder_);
295-
this->DetachFromMe(dep_->GetNodeId());
294+
apply([this] (const auto& ... syncs)
295+
{ REACT_EXPAND_PACK(this->DetachFromMe(GetInternals(syncs).GetNodeId())); }, syncHolder_);
296+
this->DetachFromMe(GetInternals(dep_).GetNodeId());
296297
this->UnregisterMe();
297298
}
298299

299300
virtual UpdateResult Update(TurnId turnId) noexcept override
300301
{
301302
// Updates might be triggered even if only sync nodes changed. Ignore those.
302-
if (dep_->Events().empty())
303+
if (GetInternals(dep_).Events().empty())
303304
return UpdateResult::unchanged;
304305

305-
apply(
306-
[this] (const auto& ... syncs)
306+
apply([this] (const auto& ... syncs)
307307
{
308-
func_(EventRange<TIn>( this->dep_->Events() ), std::back_inserter(this->Events()), syncs->Value() ...);
308+
func_(GetInternals(dep_).Events(), std::back_inserter(this->Events()), GetInternals(syncs).Value() ...);
309309
},
310310
syncHolder_);
311311

‎include/react/detail/state_nodes.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class StateSlotNode : public StateNode<S>
261261
{ return UpdateResult::changed; }
262262
};
263263

264-
State<S> input_;
264+
State<S> input_;
265265
NodeId inputNodeId_;
266266
VirtualInputNode slotInput_;
267267

‎include/react/event.h‎

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
#pragma once
1111

1212
#include "react/detail/defs.h"
13-
#include "react/api.h"
14-
#include "react/group.h"
15-
#include "react/common/ptrcache.h"
1613

1714
#include <memory>
1815
#include <type_traits>
1916
#include <utility>
2017

21-
#include "react/detail/event_nodes.h"
18+
#include "react/api.h"
19+
#include "react/group.h"
2220

21+
#include "react/detail/event_nodes.h"
2322

23+
#include "react/common/ptrcache.h"
2424

2525
/*****************************************/ REACT_BEGIN /*****************************************/
2626

@@ -136,12 +136,12 @@ class EventSource : public Event<E>
136136
void Emit(E&& value)
137137
{ EmitValue(std::move(value)); }
138138

139-
template <typename T = E, typename = std::enable_if_t<std::is_same_v<T,Token>>::type>
139+
template <typename T = E, typename = std::enable_if_t<std::is_same_v<T, Token>>>
140140
void Emit()
141141
{ EmitValue(Token::value); }
142142

143143
EventSource& operator<<(const E& value)
144-
{ EmitValue(e); return *this; }
144+
{ EmitValue(value); return *this; }
145145

146146
EventSource& operator<<(E&& value)
147147
{ EmitValue(std::move(value)); return *this; }
@@ -311,8 +311,8 @@ auto Merge(const Event<U1>& dep1, const Event<Us>& ... deps) -> decltype(auto)
311311
template <typename F, typename E>
312312
auto Filter(const Group& group, F&& pred, const Event<E>& dep) -> Event<E>
313313
{
314-
auto filterFunc = [capturedPred = std::forward<F>(pred)] (const EventValueList<E>& evts, EventValueSink<E> out)
315-
{ std::copy_if(evts.begin(), evts.end(), out, capturedPred); };
314+
auto filterFunc = [capturedPred = std::forward<F>(pred)] (const EventValueList<E>& events, EventValueSink<E> out)
315+
{ std::copy_if(events.begin(), events.end(), out, capturedPred); };
316316

317317
return Event<E>(group, std::move(filterFunc), dep);
318318
}
@@ -324,19 +324,19 @@ auto Filter(F&& pred, const Event<E>& dep) -> Event<E>
324324
template <typename F, typename E, typename ... Ts>
325325
auto Filter(const Group& group, F&& pred, const Event<E>& dep, const State<Ts>& ... states) -> Event<E>
326326
{
327-
auto filterFunc = [capturedPred = std::forward<F>(pred)] (const EventValueList<E>& evts, EventValueSink<E> out, const Us& ... values)
327+
auto filterFunc = [capturedPred = std::forward<F>(pred)] (const EventValueList<E>& evts, EventValueSink<E> out, const Ts& ... values)
328328
{
329329
for (const auto& v : evts)
330330
if (capturedPred(v, values ...))
331331
*out++ = v;
332332
};
333333

334-
return Event<E>(group, std::move(filterFunc), dep, State ...);
334+
return Event<E>(group, std::move(filterFunc), dep, states ...);
335335
}
336336

337337
template <typename F, typename E, typename ... Ts>
338338
auto Filter(F&& pred, const Event<E>& dep, const State<Ts>& ... states) -> Event<E>
339-
{ return Filter(dep.GetGroup(), std::forward<F>(pred), dep); }
339+
{ return Filter(dep.GetGroup(), std::forward<F>(pred), dep, states ...); }
340340

341341
///////////////////////////////////////////////////////////////////////////////////////////////////
342342
/// Transform
@@ -357,10 +357,10 @@ auto Transform(F&& op, const Event<T>& dep) -> Event<E>
357357
template <typename E, typename F, typename T, typename ... Us>
358358
auto Transform(const Group& group, F&& op, const Event<T>& dep, const State<Us>& ... states) -> Event<E>
359359
{
360-
auto transformFunc = [capturedOp = std::forward<F>(pred)] (const EventValueList<T>& evts, EventValueSink<E> out, const Us& ... values)
360+
auto transformFunc = [capturedOp = std::forward<F>(op)] (const EventValueList<T>& evts, EventValueSink<E> out, const Us& ... values)
361361
{
362362
for (const auto& v : evts)
363-
*out++ = capturedPred(v, values ...);
363+
*out++ = capturedOp(v, values ...);
364364
};
365365

366366
return Event<E>(group, std::move(transformFunc), dep, states ...);
@@ -390,23 +390,6 @@ template <typename U1, typename ... Us>
390390
auto Join(const Event<U1>& dep1, const Event<Us>& ... deps) -> Event<std::tuple<U1, Us ...>>
391391
{ return Join(dep1.GetGroup(), dep1, deps ...); }
392392

393-
///////////////////////////////////////////////////////////////////////////////////////////////////
394-
/// Token
395-
///////////////////////////////////////////////////////////////////////////////////////////////////
396-
enum class Token { value };
397-
398-
/*struct Tokenizer
399-
{
400-
template <typename T>
401-
Token operator()(const T&) const { return Token::value; }
402-
};
403-
404-
template <typename T>
405-
auto Tokenize(T&& source) -> decltype(auto)
406-
{
407-
return Transform(source, Tokenizer{ });
408-
}*/
409-
410393
/******************************************/ REACT_END /******************************************/
411394

412395
/***************************************/ REACT_IMPL_BEGIN /**************************************/

‎project/msvc/CppReactTest.vcxproj‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@
166166
<ClCompile Include="..\..\tests\src\event_tests.cpp" />
167167
<ClCompile Include="..\..\tests\src\observer_test.cpp" />
168168
<ClCompile Include="..\..\tests\src\algorithm_tests.cpp" />
169-
<ClCompile Include="..\..\tests\src\ParallelizationTest.cpp" />
170169
<ClCompile Include="..\..\tests\src\state_tests.cpp" />
171170
<ClCompile Include="..\..\tests\src\transaction_tests.cpp" />
172171
</ItemGroup>

‎project/msvc/CppReactTest.vcxproj.filters‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
</Filter>
1616
</ItemGroup>
1717
<ItemGroup>
18-
<ClCompile Include="..\..\tests\src\ParallelizationTest.cpp">
19-
<Filter>Source Files</Filter>
20-
</ClCompile>
2118
<ClCompile Include="..\..\tests\src\event_tests.cpp">
2219
<Filter>Source Files</Filter>
2320
</ClCompile>

0 commit comments

Comments
 (0)