153 enum class ResumingGraphTopicStateIds{
164 EventCount(
int aCount = 0) : count(aCount) {}
170 ResumingGraphTopicStateIds::kEventCount);
184 Subscribe<DetectorGraph::ResumeFromSnapshotTopicState>(
this);
185 Subscribe<EventHappened>(
this);
186 SetupPublishing<EventCount>(
this);
192 const auto previousEventCount = aResumeFrom.
snapshot.
GetState<EventCount>();
193 if (previousEventCount)
195 mEventCount = *previousEventCount;
200 void Evaluate(
const EventHappened&)
204 void CompleteEvaluation()
206 Publish(mEventCount);
210 EventCount mEventCount;
219 : mResumingCountDetector(&mGraph)
224 ResumingCountDetector mResumingCountDetector;
226 virtual void ProcessOutput()
229 mStateStore.TakeNewSnapshot(mGraph.GetOutputList());
233 template<
class TTopicState> ptr::shared_ptr<const TTopicState> GetLastTopicState()
const 235 DG_ASSERT(DetectorGraph::TopicState::GetId<TTopicState>()
238 return ptr::static_pointer_cast<
const TTopicState>(
239 mStateStore.GetLastState()->GetState<TTopicState>());
241 ptr::shared_ptr<const DetectorGraph::StateSnapshot> GetLastState()
const 243 return mStateStore.GetLastState();
252 constexpr
char kSavedSnapshotFileName[] =
"resumingGraphSnapshot.txt";
257 std::list< ptr::shared_ptr<const DetectorGraph::TopicState> > topicStatesList;
258 topicStatesList.push_back(ptr::shared_ptr<const DetectorGraph::TopicState>(
new EventCount(1000)));
267 std::ofstream snapshotOutStream(kSavedSnapshotFileName);
275 ptr::shared_ptr<const EventCount> countPtr = aSnapshot.
GetState<EventCount>();
278 snapshotOutStream << countPtr->count << endl;
288 std::list< ptr::shared_ptr<const DetectorGraph::TopicState> > topicStatesList;
290 std::ifstream snapshotInStream(kSavedSnapshotFileName);
291 if (snapshotInStream.is_open())
297 snapshotInStream >> count;
298 topicStatesList.push_back(ptr::shared_ptr<const DetectorGraph::TopicState>(
new EventCount(count)));
313 ResumingGraph resumingGraph = ResumingGraph(resumeSnapshot);
314 for (
int i = 0; i < 7; ++i)
316 resumingGraph.ProcessData(EventHappened());
317 cout <<
"EventCount = " << resumingGraph.GetLastTopicState<EventCount>()->count << endl;
319 const auto latestSnapshot = resumingGraph.GetLastState();
320 WriteSnapshot(*latestSnapshot);
Implements a graph of Topics & Detectors with Input/Output APIs.
A Base class for a basic Graph container.
ptr::shared_ptr< const TopicState > GetState(TopicStateIdType aId) const
Returns a TopicState for a given Id.
The collection of TopicStates that represents the graph state so far.
A StateSnapshot keeper for DetectorGraph TopicStates.
Base struct for topic data types.
DetectorGraph::StateSnapshot snapshot
Base class that implements a Publisher behavior.
A unit of logic in a DetectorGraph.
A Pure interface that declares the Subscriber behavior.
#define DG_ASSERT(condition)