FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added ReactorT::Context::Get. · jchjava/cpp.react@5a2bb61 · GitHub

Commit 5a2bb61

Browse files
committed
Added ReactorT::Context::Get.
1 parent 04bf0eb commit 5a2bb61

2 files changed

Lines changed: 54 additions & 22 deletions

File tree

‎include/react/Reactor.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ class Reactor
5050
node_.RepeatUntil(evn.NodePtr(), std::forward<F>(func));
5151
}
5252

53+
template <typename S>
54+
const S& Get(const Signal<D,S>& sig)
55+
{
56+
return node_.Get(sig.NodePtr());
57+
}
58+
5359
private:
5460
NodeT& node_;
5561
};

‎include/react/detail/graph/ReactorNodes.h‎

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ class ReactorNode :
7878

7979
// First blocking event is not initiated by Tick() but after loop creation.
8080
NodeBase<D>* p = mainLoop_.get();
81-
82-
assert(p != nullptr);
83-
84-
Engine::OnNodeAttach(*this, *p);
81+
doAttach(p);
8582

8683
++depCount_;
8784
}
@@ -101,8 +98,7 @@ class ReactorNode :
10198

10299
if (p != nullptr)
103100
{
104-
Engine::OnDynamicNodeAttach(*this, *p, *turnPtr_);
105-
++depCount_;
101+
doDynAttach(p);
106102
}
107103
else
108104
{
@@ -126,10 +122,7 @@ class ReactorNode :
126122
while (! checkEvent(events))
127123
(*curOutPtr_)(nullptr);
128124

129-
assert(turnPtr_ != nullptr);
130-
131-
Engine::OnDynamicNodeDetach(*this, *events, *turnPtr_);
132-
--depCount_;
125+
doDynDetach(events.get());
133126

134127
auto index = offsets_[reinterpret_cast<uintptr_t>(events.get())]++;
135128
return events->Events()[index];
@@ -147,8 +140,7 @@ class ReactorNode :
147140
{
148141
// Non-dynamic attach in case first loop until is encountered before the loop was
149142
// suspended for the first time.
150-
Engine::OnNodeAttach(*this, *eventsPtr);
151-
++depCount_;
143+
doAttach(eventsPtr.get());
152144
}
153145

154146
// Don't enter loop if event already present
@@ -190,18 +182,20 @@ class ReactorNode :
190182
--depCount_;
191183
}
192184

193-
//template <typename S>
194-
//S& Get(const std::shared_ptr<SignalNode<D,S>>& sig)
195-
//{
196-
// // Attach to target signal node
197-
// (*curOutPtr_)(sig.get());
185+
template <typename S>
186+
const S& Get(const std::shared_ptr<SignalNode<D,S>>& sigPtr)
187+
{
188+
// Do dynamic attach followed by attach if Get() happens during a turn.
189+
if (turnPtr_ != nullptr)
190+
{
191+
// Request attach
192+
(*curOutPtr_)(sigPtr.get());
198193

199-
// Engine::OnDynamicNodeDetach(*this, *events, *turnPtr_);
200-
// --depCount_;
194+
doDynDetach(sigPtr.get());
195+
}
201196

202-
// auto index = offsets_[reinterpret_cast<uintptr_t>(events.get())]++;
203-
// return events->Events()[index];
204-
//}
197+
return sigPtr->ValueRef();
198+
}
205199

206200
private:
207201
template <typename E>
@@ -216,6 +210,38 @@ class ReactorNode :
216210
return offsets_[index] < events->Events().size();
217211
}
218212

213+
void doAttach(NodeBase<D>* nodePtr)
214+
{
215+
assert(nodePtr != nullptr);
216+
assert(turnPtr_ == nullptr);
217+
Engine::OnNodeAttach(*this, *nodePtr);
218+
++depCount_;
219+
}
220+
221+
void doDetach(NodeBase<D>* nodePtr)
222+
{
223+
assert(nodePtr != nullptr);
224+
assert(turnPtr_ == nullptr);
225+
Engine::OnNodeDetach(*this, *nodePtr);
226+
--depCount_;
227+
}
228+
229+
void doDynAttach(NodeBase<D>* nodePtr)
230+
{
231+
assert(nodePtr != nullptr);
232+
assert(turnPtr_ != nullptr);
233+
Engine::OnDynamicNodeAttach(*this, *nodePtr, *turnPtr_);
234+
++depCount_;
235+
}
236+
237+
void doDynDetach(NodeBase<D>* nodePtr)
238+
{
239+
assert(nodePtr != nullptr);
240+
assert(turnPtr_ != nullptr);
241+
Engine::OnDynamicNodeDetach(*this, *nodePtr, *turnPtr_);
242+
--depCount_;
243+
}
244+
219245
std::function<void(TContext)> func_;
220246

221247
PullT mainLoop_;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL