DetectorGraph  2.0
testsplitterdetector.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_TEST_UTIL_SPLITTERDETECTOR_HPP_
16 #define DETECTORGRAPH_TEST_UTIL_SPLITTERDETECTOR_HPP_
17 
18 #include "graph.hpp"
19 #include "topicstate.hpp"
20 #include "detector.hpp"
21 
22 #include <utility>
23 
24 namespace DetectorGraph
25 {
26 
27 /* This is a utility test tool - this is meant to help with unit tests.
28  * It's a "utility" detector and TopicState to stress the publishing to two
29  * different topicStates in the same evaluation pass.
30  *
31  *
32  * Topic<T1> Topic<T2>
33  * ^ ^
34  * \ /
35  * \ /
36  * \ /
37  * \ /
38  * O TestSplitterDetector<T1,T2>
39  * ^
40  * |
41  * - Topic< TestSplitterTrigger<T1,T2> >
42  *
43  *
44  */
45 template <class OutA, class OutB>
46 struct TestSplitterTrigger : public TopicState, public std::pair<OutA, OutB>
47 {
48  TestSplitterTrigger() : std::pair<OutA, OutB>()
49  {
50  }
51 
52  TestSplitterTrigger(const OutA& a, const OutB& b) : std::pair<OutA, OutB>(a,b)
53  {
54  }
55 };
56 
57 template<class OutA, class OutB>
59  public SubscriberInterface< TestSplitterTrigger<OutA, OutB> >,
60  public Publisher<OutA>,
61  public Publisher<OutB>
62 {
63 public:
65  {
66  Subscribe< TestSplitterTrigger<OutA, OutB> >(this);
67  SetupPublishing<OutA>(this);
68  SetupPublishing<OutB>(this);
69  }
70 
71  virtual void Evaluate(const TestSplitterTrigger<OutA, OutB>& pair)
72  {
73  Publisher<OutA>::Publish(pair.first);
74  Publisher<OutB>::Publish(pair.second);
75  }
76 };
77 
78 } // namespace DetectorGraph
79 
80 #endif // DETECTORGRAPH_TEST_UTIL_SPLITTERDETECTOR_HPP_
Implements a graph of Topics & Detectors with Input/Output APIs.
Definition: graph.hpp:127
virtual void Evaluate(const TestSplitterTrigger< OutA, OutB > &pair)
Pure-virtual method that should Evaluate a piece of input data.
void Publish(const T &data)
Publish a new version of T to a Topic.
Definition: publisher.hpp:85
TestSplitterTrigger(const OutA &a, const OutB &b)
Base struct for topic data types.
Definition: topicstate.hpp:52
Base class that implements a Publisher behavior.
Definition: publisher.hpp:66
A unit of logic in a DetectorGraph.
Definition: detector.hpp:68
A Pure interface that declares the Subscriber behavior.