DetectorGraph  2.0
subscriptiondispatcherscontainer-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_SUBSCRIPTIONDISPATCHERCONTAINER_STL_HPP_
16 #define DETECTORGRAPH_INCLUDE_SUBSCRIPTIONDISPATCHERCONTAINER_STL_HPP_
17 
19 
20 #include <vector>
21 
22 namespace DetectorGraph
23 {
24 /**
25  * @brief _Internal_ - Manages any number of SubscriptionDispatchers.
26  *
27  * This class is responsible for creating and owning SubscriptionDispatcher
28  * for a particular detector. A detector that subscribes to two Topics will
29  * have two SubscriptionDispatchers.
30  */
31 class SubscriptionDispatchersContainer
32 {
33 public:
34  template<class TTopicState>
36  {
37  SubscriptionDispatcherInterface* dispacher = new SubscriptionDispatcher<TTopicState>(topic, subscriber);
38  mInDispatchers.push_back(dispacher);
39  }
40 
41  const std::vector<SubscriptionDispatcherInterface*>& GetDispatchers() const
42  {
43  return mInDispatchers;
44  }
45 
46  const size_t GetSize() const
47  {
48  return mInDispatchers.size();
49  }
50 
52  {
53  for (unsigned i = 0; i != GetSize(); ++i)
54  {
55  delete GetDispatchers()[i];
56  }
57  }
58 private:
59  std::vector<SubscriptionDispatcherInterface*> mInDispatchers;
60 };
61 
62 } // namespace DetectorGraph
63 
64 #endif // DETECTORGRAPH_INCLUDE_SUBSCRIPTIONDISPATCHERCONTAINER_STL_HPP_
const std::vector< SubscriptionDispatcherInterface * > & GetDispatchers() const
SubscriptionDispatcherInterface *const (& GetDispatchers() const)[DetectorGraphConfig::kMaxNumberOfInEdges]
Manage data and its handler.
Definition: topic.hpp:84
Internal - Implements the data-out edge from a topic to one of its subscriber.
Internal - Provide interface for a SubscriptionDispatcher
void CreateDispatcher(Topic< TTopicState > *topic, SubscriberInterface< TTopicState > *subscriber)
A Pure interface that declares the Subscriber behavior.