@@ -19,22 +19,18 @@ template
1919<
2020 typename D,
2121 typename S,
22- typename E,
23- typename ... TArgs
22+ typename E
2423>
2524class FoldBaseNode : public SignalNode <D,S>
2625{
2726public:
2827 FoldBaseNode (const S& initialValue, const EventStreamNodePtr<D,E>& events,
29- const SignalNodePtr<D,TArgs>& ... args, bool registered) :
28+ bool registered) :
3029 SignalNode<D, S>(initialValue, true ),
31- deps_{ std::make_tuple (args ...) },
3230 events_{ events }
3331 {
3432 }
3533
36- virtual const char * GetNodeType () const override { return " FoldBaseNode" ; }
37-
3834 virtual ETickResult Tick (void * turnPtr) override
3935 {
4036 typedef typename D::Engine::TurnInterface TurnInterface;
@@ -44,7 +40,7 @@ class FoldBaseNode : public SignalNode<D,S>
4440 S newValue = calcNewValue ();
4541 D::Log ().template Append <NodeEvaluateEndEvent>(GetObjectId (*this ), turn.Id (), std::this_thread::get_id ().hash ());
4642
47- if (newValue != value_)
43+ if (impl::Equals ( newValue, value_) )
4844 {
4945 value_ = newValue;
5046 Engine::OnNodePulse (*this , turn);
@@ -57,24 +53,12 @@ class FoldBaseNode : public SignalNode<D,S>
5753 }
5854 }
5955
60- virtual int DependencyCount () const override { return 1 + sizeof ... (TArgs) ; }
56+ virtual int DependencyCount () const override { return 1 ; }
6157
6258protected:
63- const EventStreamNodePtr<D,E> events_;
64- const std::tuple<SignalNodePtr<D,TArgs> ...> deps_;
59+ const EventStreamNodePtr<D,E> events_;
6560
6661 virtual S calcNewValue () const = 0;
67-
68- template <typename A>
69- S evaluate (const A& a) const
70- {
71- return apply (a, apply (unpackValues, deps_));
72- }
73-
74- static inline auto unpackValues (const SignalNodePtr<D,TArgs>& ... args) -> std::tuple<TArgs ...>
75- {
76- return std::make_tuple (args->ValueRef () ...);
77- }
7862};
7963
8064// //////////////////////////////////////////////////////////////////////////////////////
@@ -84,65 +68,37 @@ template
8468<
8569 typename D,
8670 typename S,
87- typename E,
88- typename ... TArgs
71+ typename E
8972>
90- class FoldNode : public FoldBaseNode <D,S,E,TArgs... >
73+ class FoldNode : public FoldBaseNode <D,S,E>
9174{
9275public:
9376 FoldNode (const S& initialValue, const EventStreamNodePtr<D,E>& events,
94- const SignalNodePtr<D,TArgs>& ... args, std::function<S(S,E,TArgs ... )> func, bool registered) :
95- FoldBaseNode<D, S, E, TArgs... >(initialValue, events, args ... , true ),
77+ std::function<S(S,E)> func, bool registered) :
78+ FoldBaseNode<D,S,E >(initialValue, events, true ),
9679 func_{ func }
9780 {
9881 if (!registered)
9982 registerNode ();
10083
10184 Engine::OnNodeAttach (*this , *events);
102- EXPAND_PACK (Engine::OnNodeAttach (*this , *args));
10385 }
10486
10587 ~FoldNode ()
10688 {
10789 Engine::OnNodeDetach (*this , *events_);
108-
109- apply
110- (
111- [this ] (const SignalNodePtr<D,TArgs>& ... args)
112- {
113- EXPAND_PACK (Engine::OnNodeDetach (*this , *args));
114- },
115- deps_
116- );
11790 }
11891
11992 virtual const char * GetNodeType () const override { return " FoldNode" ; }
12093
12194protected:
122- const std::function<S(S,E,TArgs ...)> func_;
123-
124- struct ApplyHelper_
125- {
126- ApplyHelper_ (const S& s, const E& e, const std::function<S(S,E,TArgs ...)> func) :
127- s_{ s }, e_{ e }, func_{ func }
128- {
129- }
130-
131- S operator () (TArgs ... args) const
132- {
133- return func_ (s_, e_, args ...);
134- }
135-
136- const S& s_;
137- const E& e_;
138- const std::function<S(S,E,TArgs ...)> func_;
139- };
95+ const std::function<S(S,E)> func_;
14096
14197 virtual S calcNewValue () const override
14298 {
14399 S newValue = value_;
144- for (auto e : events_->REvents ())
145- newValue = evaluate ( ApplyHelper_ ( newValue,e,func_) );
100+ for (const auto & e : events_->REvents ())
101+ newValue = func_ ( newValue,e);
146102 return newValue;
147103 }
148104};
@@ -154,64 +110,37 @@ template
154110<
155111 typename D,
156112 typename S,
157- typename E,
158- typename ... TArgs
113+ typename E
159114>
160- class IterateNode : public FoldBaseNode <D,S,E,TArgs... >
115+ class IterateNode : public FoldBaseNode <D,S,E>
161116{
162117public:
163118 IterateNode (const S& initialValue, const EventStreamNodePtr<D,E>& events,
164- const SignalNodePtr<D,TArgs>& ... args, std::function<S(S,TArgs ... )> func, bool registered) :
165- FoldBaseNode<D, S, E, TArgs... >(initialValue, events, args ... , true ),
119+ std::function<S(S)> func, bool registered) :
120+ FoldBaseNode<D,S,E >(initialValue, events, true ),
166121 func_{ func }
167122 {
168123 if (!registered)
169124 registerNode ();
170125
171126 Engine::OnNodeAttach (*this , *events);
172- EXPAND_PACK (Engine::OnNodeAttach (*this , *args));
173127 }
174128
175129 ~IterateNode ()
176130 {
177131 Engine::OnNodeDetach (*this , *events_);
178-
179- apply
180- (
181- [this ] (const SignalNodePtr<D,TArgs>& ... args)
182- {
183- EXPAND_PACK (Engine::OnNodeDetach (*this , *args));
184- },
185- deps_
186- );
187132 }
188133
189134 virtual const char * GetNodeType () const override { return " IterateNode" ; }
190135
191136protected:
192- const std::function<S(S,TArgs ...)> func_;
193-
194- struct ApplyHelper_
195- {
196- ApplyHelper_ (const S& s, const std::function<S(S,TArgs ...)> func) :
197- s_{ s }, func_{ func }
198- {
199- }
200-
201- S operator () (TArgs ... args) const
202- {
203- return func_ (s_, args ...);
204- }
205-
206- const S& s_;
207- const std::function<S(S,TArgs ...)> func_;
208- };
137+ const std::function<S(S)> func_;
209138
210139 virtual S calcNewValue () const override
211140 {
212141 S newValue = value_;
213- for (int i= 0 ; i < events_->REvents (). size (); i++ )
214- newValue = evaluate ( ApplyHelper_ ( newValue,func_) );
142+ for (const auto & e : events_->REvents ())
143+ newValue = func_ ( newValue);
215144 return newValue;
216145 }
217146};
0 commit comments