DetectorGraph  2.0
processorcontainer.hpp
Go to the documentation of this file.
1 // Copyright 2017 Nest Labs, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DETECTORGRAPH_INCLUDE_PROCESSORCONTAINER_HPP_
16 #define DETECTORGRAPH_INCLUDE_PROCESSORCONTAINER_HPP_
17 
18 #include "graph.hpp"
19 
20 namespace DetectorGraph
21 {
22 
23 /**
24  * @brief A Base class for a basic Graph container.
25  *
26  * Below is an example of how to implement a ProcessorContainer:
27  *
28  @snippet helloworld.cpp ProcessorContainer
29  *
30  * And an example of how to invoke it:
31  @snippet helloworld.cpp Using ProcessorContainer
32  *
33  * This is the simplest way to build detector graphs and is used throughout the examples.
34  */
35 
37 {
38 public:
40  : mGraph()
41  {
42  }
43 
44  /**
45  * @brief Pushes data followed by graph evaluation and output processing.
46  *
47  * Pushes @param topicState into the graph, performs all pending graph
48  * evaluations calling ProcessOutput for each one of them.
49  */
50  template<class TTopic> void ProcessData(const TTopic& topicState)
51  {
52  mGraph.PushData<TTopic>(topicState);
53  ProcessGraph();
54  }
55 
56  /// @brief Performs all pending Graph Evaluations with output processing.
57  void ProcessGraph()
58  {
60  {
61  ProcessOutput();
62  }
63  }
64 
65  /**
66  * @brief Called after each Graph Evaluation.
67  *
68  * Users should provide an implementation for this method where they can
69  * inspect specific output topics or process all new outputs generically
70  * using Graph::GetOutputList.
71  */
72  virtual void ProcessOutput() = 0;
73 
75 
76  virtual ~ProcessorContainer() {}
77 };
78 
79 }
80 
81 #endif // DETECTORGRAPH_INCLUDE_PROCESSORCONTAINER_HPP_
Implements a graph of Topics & Detectors with Input/Output APIs.
Definition: graph.hpp:127
void PushData(const TTopicState &aTopicState)
Push data to a specific topic in the graph.
Definition: graph.hpp:187
A Base class for a basic Graph container.
bool EvaluateIfHasDataPending()
Evaluates Graph if data is pending and returns true if so.
Definition: graph.cpp:80
void ProcessGraph()
Performs all pending Graph Evaluations with output processing.
virtual void ProcessOutput()=0
Called after each Graph Evaluation.
void ProcessData(const TTopic &topicState)
Pushes data followed by graph evaluation and output processing.