DetectorGraph
2.0
|
Vending Machine with Named TopicStates and GraphAnalyzer. More...
Go to the source code of this file.
Vending Machine with Named TopicStates and GraphAnalyzer.
This example gives a single-detector solution for a hypothetical one-item, one-coin vending machine. It shows how a single detector can be used to synchronize combine signals - coins being inserted and the "Buy" button being clicked - to produce a third - SaleCompleted. It also introduces the concepts of Trivial TopicStates, Named TopicStates and using GraphAnalyzer.
A Trivial TopicState has no data fields:
These are sometimes useful to represent parameter-less signals, timeouts etc.
Named TopicStates, as opposed to Anonymous ones, are TopicStates that override the TopicState::GetId method. This allows for code that deals with sequences of different TopicStates in a general way. This is used primarily outside (or at the boundary) of the DetectorGraph portion of the application in applications that necessitate any need of generic/transparent treatment of TopicStates. An example of this is GraphStateStore & StateSnapshot. They are often also called Public TopicStates as they're what's exposed to the outside world from the point of view of a DetectorGraph graph.
TopicState "names" come from an application-specific enumeration value for your named TopicStates - values must be cast-able to TopicStateIdType and be different than TopicState::kAnonymousTopicState (-1). An example would be:
(C++03
enums are fine too)
Which then can be used in the overriding of TopicState::GetId for the desired named TopicState:
That then enables things like:
Finally, this example also shows how to use DetectorGraph::GraphAnalyzer to generate a GraphViz-compatible .dot
representation of the graph:
That .dot file when rendered generates the following graph:
Note that the Named TopicStates are represented by outlined rectangles.
For a more sophisticated solution to a similar problem, see fancyvendingmachine.cpp .
Definition in file trivialvendingmachine.cpp.