111 enum class VendingMachineTopicStateIds{
123 VendingMachineTopicStateIds::kSaleCompleted);
130 Balance() : numberOfCoins(0) {}
135 VendingMachineTopicStateIds::kBalance);
150 Subscribe<CoinInserted>(
this);
151 Subscribe<BuyButtonClicked>(
this);
152 SetupPublishing<SaleCompleted>(
this);
153 SetupPublishing<Balance>(
this);
156 void Evaluate(
const CoinInserted&)
158 balance.numberOfCoins++;
160 void Evaluate(
const BuyButtonClicked&)
162 if (balance.numberOfCoins > 0)
165 balance.numberOfCoins--;
166 Publisher<SaleCompleted>::Publish(SaleCompleted());
170 DG_LOG(
"Funds not available; no sale made.");
173 void CompleteEvaluation()
175 Publisher<Balance>::Publish(balance);
187 : mSaleDetector(&mGraph)
188 , mSaleTopic(mGraph.ResolveTopic<SaleCompleted>())
189 , mBalanceTopic(mGraph.ResolveTopic<Balance>())
194 SaleDetector mSaleDetector;
204 for (
const auto topicState : mGraph.GetOutputList())
206 switch(static_cast<VendingMachineTopicStateIds>(
207 topicState->GetId()))
209 case VendingMachineTopicStateIds::kSaleCompleted:
210 cout <<
"Sale Made" << endl;
213 case VendingMachineTopicStateIds::kBalance:
215 const std::shared_ptr<const Balance> balance =
216 std::static_pointer_cast<
const Balance>(topicState);
218 cout <<
"Balance: " << balance->numberOfCoins;
219 cout <<
" coins" << endl;
235 VendingMachine vendingMachine;
236 vendingMachine.ProcessData(CoinInserted());
237 vendingMachine.ProcessData(BuyButtonClicked());
239 vendingMachine.ProcessData(BuyButtonClicked());
242 vendingMachine.ProcessData(CoinInserted());
243 vendingMachine.ProcessData(CoinInserted());
244 vendingMachine.ProcessData(BuyButtonClicked());
245 vendingMachine.ProcessData(BuyButtonClicked());
249 analyzer.GenerateDotFile(
"trivial_vending_machine.dot");
Implements a graph of Topics & Detectors with Input/Output APIs.
A Base class for a basic Graph container.
Manage data and its handler.
void DG_LOG(const char *aLogString,...)
A StateSnapshot keeper for DetectorGraph TopicStates.
Base struct for topic data types.
Base class that implements a Publisher behavior.
A unit of logic in a DetectorGraph.
A Pure interface that declares the Subscriber behavior.
Class that provides debugging/diagnostics to a DetectorGraph detector graph.
void TakeNewSnapshot(const std::list< ptr::shared_ptr< const TopicState > > &arTopicStates)
Takes a new state snapshot and appends it to the look back queue.