DetectorGraph  2.0
graphinputqueue-stl.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_GRAPHINPUTQUEUE_STL_HPP_
16 #define DETECTORGRAPH_INCLUDE_GRAPHINPUTQUEUE_STL_HPP_
17 
18 #include "graphinputdispatcher.hpp"
19 
20 #include <queue>
21 
22 namespace DetectorGraph
23 {
24 /**
25  * @brief _Internal_ - Provides an STL implementation of GraphInputQueue
26  */
27 class GraphInputQueue
28 {
29 public:
30  GraphInputQueue() : mInputQueue() {}
31 
32  template<class TTopicState>
33  void Enqueue(Topic<TTopicState>& aTopic, const TTopicState& aTopicState)
34  {
35  mInputQueue.push(new GraphInputDispatcher<TTopicState>(aTopic, aTopicState));
36  }
37 
39  {
40  if (!mInputQueue.empty())
41  {
42  GraphInputDispatcherInterface* nextInput = mInputQueue.front();
43  mInputQueue.pop();
44 
45  // Will call Topic->Publish(aTopicState)
46  nextInput->Dispatch();
47 
48  delete nextInput;
49 
50  return true;
51  }
52  else
53  {
54  return false;
55  }
56  }
57 
58  bool IsEmpty() const
59  {
60  return mInputQueue.empty();
61  }
62 
64  {
65  while (!mInputQueue.empty())
66  {
67  GraphInputDispatcherInterface* nextInput = mInputQueue.front();
68  mInputQueue.pop();
69  delete nextInput;
70  }
71  }
72 
73 private:
74  std::queue< GraphInputDispatcherInterface* > mInputQueue;
75 };
76 
77 } // namespace DetectorGraph
78 
79 #endif // DETECTORGRAPH_INCLUDE_GRAPHINPUTQUEUE_STL_HPP_
Internal - Provide interface for a GraphInputDispatcher
void Enqueue(Topic< TTopicState > &aTopic, const TTopicState &aTopicState)
Manage data and its handler.
Definition: topic.hpp:84
Internal - Push data to the graph