Skip to content

Commit a87627f

Browse files
committed
More refactoring. Tests and benchmarks now compile with GCC and clang.
* The function aliases for MakeVar etc. in Domain have been removed. They were intended as syntactic sugar, but if the domain is a dependent type, D::template MakeEventSource<int> defeats the purpose. Using MakeEventSource<D,int> directly simpler in this case, and using it all the time is consistent. * ReactiveObject has been removed. Instead, a macro is used to define aliases. ReactiveObject aliases did not work, if the domain is a dependent type. * No longer using {} initialization, because it was giving me trouble.
1 parent 61351b6 commit a87627f

32 files changed

Lines changed: 620 additions & 699 deletions

include/react/Algorithm.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ auto Iterate(const Events<D,E>& events, V&& init, FIn&& func)
5757
using REACT_IMPL::IterateByRefNode;
5858

5959
using F = typename std::decay<FIn>::type;
60+
using R = typename std::result_of<FIn(E,S&)>::type;
6061
using TNode = typename std::conditional<
61-
std::is_same<void,
62-
typename std::result_of<F(E,S)>::type>::value,
62+
std::is_same<void,R>::value,
6363
IterateByRefNode<D,S,E,F>,
6464
IterateNode<D,S,E,F>
65-
>::type;
65+
>::type;
6666

6767
return Signal<D,S>(
6868
std::make_shared<TNode>(
@@ -89,19 +89,19 @@ auto Iterate(const Events<D,E>& events, V&& init,
8989
using REACT_IMPL::SyncedIterateByRefNode;
9090

9191
using F = typename std::decay<FIn>::type;
92+
using R = typename std::result_of<FIn(E,S&,TDepValues...)>::type;
9293
using TNode = typename std::conditional<
93-
std::is_same<void,
94-
typename std::result_of<F(E,S,TDepValues...)>::type>::value,
94+
std::is_same<void,R>::value,
9595
SyncedIterateByRefNode<D,S,E,F,TDepValues ...>,
9696
SyncedIterateNode<D,S,E,F,TDepValues ...>
97-
>::type;
97+
>::type;
9898

9999
struct NodeBuilder_
100100
{
101101
NodeBuilder_(const Events<D,E>& source, V&& init, FIn&& func) :
102-
MySource{ source },
103-
MyInit{ std::forward<V>(init) },
104-
MyFunc{ std::forward<FIn>(func) }
102+
MySource( source ),
103+
MyInit( std::forward<V>(init) ),
104+
MyFunc( std::forward<FIn>(func) )
105105
{}
106106

107107
auto operator()(const Signal<D,TDepValues>& ... deps)
@@ -119,7 +119,7 @@ auto Iterate(const Events<D,E>& events, V&& init,
119119
};
120120

121121
return REACT_IMPL::apply(
122-
NodeBuilder_{ events, std::forward<V>(init), std::forward<FIn>(func) },
122+
NodeBuilder_( events, std::forward<V>(init), std::forward<FIn>(func) ),
123123
depPack.Data);
124124
}
125125

include/react/Domain.h

Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
#include "react/detail/Defs.h"
1313

1414
#include <utility>
15-
#include <type_traits>
16-
17-
#include "react/TypeTraits.h"
18-
19-
#include "react/detail/EventFwd.h"
20-
#include "react/detail/SignalFwd.h"
2115

2216
#include "react/detail/ReactiveInput.h"
2317
#include "react/detail/Options.h"
@@ -35,6 +29,26 @@
3529
///////////////////////////////////////////////////////////////////////////////////////////////////
3630
/// Forward declarations
3731
///////////////////////////////////////////////////////////////////////////////////////////////////
32+
template <typename D, typename S>
33+
class Signal;
34+
35+
template <typename D, typename S>
36+
class VarSignal;
37+
38+
template <typename D, typename S, typename TOp>
39+
class TempSignal;
40+
41+
template <typename D, typename E>
42+
class Events;
43+
44+
template <typename D, typename E>
45+
class EventSource;
46+
47+
template <typename D, typename E, typename TOp>
48+
class TempEvents;
49+
50+
enum class Token;
51+
3852
template <typename D>
3953
class ReactiveLoop;
4054

@@ -77,7 +91,7 @@ class DomainBase
7791
REACT_IMPL::EnableParallelUpdating<typename Policy::Engine>::value;
7892

7993
///////////////////////////////////////////////////////////////////////////////////////////////
80-
/// Aliases for reactives of current domain
94+
/// Aliases for reactives of this domain
8195
///////////////////////////////////////////////////////////////////////////////////////////////
8296
template <typename S>
8397
using SignalT = Signal<D,S>;
@@ -97,55 +111,6 @@ class DomainBase
97111

98112
using ReactiveLoopT = ReactiveLoop<D>;
99113

100-
///////////////////////////////////////////////////////////////////////////////////////////////////
101-
/// MakeVar
102-
///////////////////////////////////////////////////////////////////////////////////////////////////
103-
template
104-
<
105-
typename V,
106-
typename S = typename std::decay<V>::type,
107-
class = typename std::enable_if<
108-
!IsSignal<S>::value>::type
109-
>
110-
static auto MakeVar(V&& value)
111-
-> VarSignalT<S>
112-
{
113-
return REACT::MakeVar<D>(std::forward<V>(value));
114-
}
115-
116-
//////////////////////////////////////////////////////////////////////////////////////////////////////////
117-
/// MakeVar (higher order)
118-
//////////////////////////////////////////////////////////////////////////////////////////////////////////
119-
template
120-
<
121-
typename V,
122-
typename S = typename std::decay<V>::type,
123-
typename TInner = typename S::ValueT,
124-
class = typename std::enable_if<
125-
IsSignal<S>::value>::type
126-
>
127-
static auto MakeVar(V&& value)
128-
-> VarSignalT<SignalT<TInner>>
129-
{
130-
return REACT::MakeVar<D>(std::forward<V>(value));
131-
}
132-
133-
///////////////////////////////////////////////////////////////////////////////////////////////////
134-
/// MakeEventSource
135-
///////////////////////////////////////////////////////////////////////////////////////////////////
136-
template <typename E>
137-
static auto MakeEventSource()
138-
-> EventSourceT<E>
139-
{
140-
return REACT::MakeEventSource<D,E>();
141-
}
142-
143-
static auto MakeEventSource()
144-
-> EventSourceT<Token>
145-
{
146-
return REACT::MakeEventSource<D>();
147-
}
148-
149114
///////////////////////////////////////////////////////////////////////////////////////////////////
150115
/// DoTransaction
151116
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -215,4 +180,26 @@ class DomainInitializer
215180
struct name : public REACT::DomainBase<name, REACT_IMPL::DomainPolicy<__VA_ARGS__ >> {}; \
216181
REACT_IMPL::DomainInitializer< name > name ## _initializer_;
217182

183+
///////////////////////////////////////////////////////////////////////////////////////////////////
184+
/// Define type aliases for given domain
185+
///////////////////////////////////////////////////////////////////////////////////////////////////
186+
#define USING_REACTIVE_DOMAIN(name) \
187+
template <typename S> \
188+
using SignalT = Signal<name,S>; \
189+
\
190+
template <typename S> \
191+
using VarSignalT = VarSignal<name,S>; \
192+
\
193+
template <typename E = Token> \
194+
using EventsT = Events<name,E>; \
195+
\
196+
template <typename E = Token> \
197+
using EventSourceT = EventSource<name,E>; \
198+
\
199+
using ObserverT = Observer<name>; \
200+
\
201+
using ScopedObserverT = ScopedObserver<name>; \
202+
\
203+
using ReactiveLoopT = ReactiveLoop<name>;
204+
218205
#endif // REACT_DOMAIN_H_INCLUDED

include/react/Event.h

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <type_traits>
1616
#include <utility>
1717

18-
#include "react/detail/EventFwd.h"
19-
2018
#include "react/Observer.h"
2119
#include "react/TypeTraits.h"
2220
#include "react/common/Util.h"
@@ -27,6 +25,17 @@
2725
///////////////////////////////////////////////////////////////////////////////////////////////////
2826
/// Forward declarations
2927
///////////////////////////////////////////////////////////////////////////////////////////////////
28+
template <typename D, typename E>
29+
class Events;
30+
31+
template <typename D, typename E>
32+
class EventSource;
33+
34+
template <typename D, typename E, typename TOp>
35+
class TempEvents;
36+
37+
enum class Token;
38+
3039
template <typename D, typename S>
3140
class Signal;
3241

@@ -36,7 +45,7 @@ class SignalPack;
3645
///////////////////////////////////////////////////////////////////////////////////////////////////
3746
/// MakeEventSource
3847
///////////////////////////////////////////////////////////////////////////////////////////////////
39-
template <typename D, typename E>
48+
template <typename D, typename E = Token>
4049
auto MakeEventSource()
4150
-> EventSource<D,E>
4251
{
@@ -46,16 +55,6 @@ auto MakeEventSource()
4655
std::make_shared<EventSourceNode<D,E>>());
4756
}
4857

49-
template <typename D>
50-
auto MakeEventSource()
51-
-> EventSource<D,Token>
52-
{
53-
using REACT_IMPL::EventSourceNode;
54-
55-
return EventSource<D,Token>(
56-
std::make_shared<EventSourceNode<D,Token>>());
57-
}
58-
5958
///////////////////////////////////////////////////////////////////////////////////////////////////
6059
/// Merge
6160
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -400,11 +399,18 @@ class Events : public REACT_IMPL::EventStreamBase<D,E>
400399

401400
Events() = default;
402401
Events(const Events&) = default;
402+
Events& operator=(const Events&) = default;
403403

404404
Events(Events&& other) :
405405
Events::EventStreamBase( std::move(other) )
406406
{}
407407

408+
Events& operator=(Events&& other)
409+
{
410+
Events::EventStreamBase::operator=( std::move(other) );
411+
return *this;
412+
}
413+
408414
explicit Events(NodePtrT&& nodePtr) :
409415
Events::EventStreamBase( std::move(nodePtr) )
410416
{}
@@ -467,11 +473,18 @@ class Events<D,E&> : public REACT_IMPL::EventStreamBase<D,std::reference_wrapper
467473

468474
Events() = default;
469475
Events(const Events&) = default;
476+
Events& operator=(const Events&) = default;
470477

471478
Events(Events&& other) :
472479
Events::EventStreamBase( std::move(other) )
473480
{}
474481

482+
Events& operator=(Events&& other)
483+
{
484+
Events::EventStreamBase::operator=( std::move(other) );
485+
return *this;
486+
}
487+
475488
explicit Events(NodePtrT&& nodePtr) :
476489
Events::EventStreamBase( std::move(nodePtr) )
477490
{}
@@ -531,11 +544,18 @@ class EventSource : public Events<D,E>
531544
public:
532545
EventSource() = default;
533546
EventSource(const EventSource&) = default;
547+
EventSource& operator=(const EventSource&) = default;
534548

535549
EventSource(EventSource&& other) :
536550
EventSource::Events( std::move(other) )
537551
{}
538552

553+
EventSource& operator=(EventSource&& other)
554+
{
555+
EventSource::Events::operator=( std::move(other) );
556+
return *this;
557+
}
558+
539559
explicit EventSource(NodePtrT&& nodePtr) :
540560
EventSource::Events( std::move(nodePtr) )
541561
{}
@@ -589,11 +609,18 @@ class EventSource<D,E&> : public Events<D,std::reference_wrapper<E>>
589609
public:
590610
EventSource() = default;
591611
EventSource(const EventSource&) = default;
612+
EventSource& operator=(const EventSource&) = default;
592613

593614
EventSource(EventSource&& other) :
594615
EventSource::Events( std::move(other) )
595616
{}
596617

618+
EventSource& operator=(EventSource&& other)
619+
{
620+
EventSource::Events::operator=( std::move(other) );
621+
return *this;
622+
}
623+
597624
explicit EventSource(NodePtrT&& nodePtr) :
598625
EventSource::Events( std::move(nodePtr) )
599626
{}
@@ -630,6 +657,7 @@ class TempEvents : public Events<D,E>
630657
public:
631658
TempEvents() = default;
632659
TempEvents(const TempEvents&) = default;
660+
TempEvents& operator=(const TempEvents&) = default;
633661

634662
TempEvents(TempEvents&& other) :
635663
TempEvents::Events( std::move(other) )

0 commit comments

Comments
 (0)