m2etis  0.4
DecisionTreeNode.h
Go to the documentation of this file.
1 /*
2  Copyright (2016) Michael Baer, Daniel Bonrath, All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 
22 #ifndef __M2ETIS_PUBSUB_FILTER_DECISIONTREE_DECISIONTREENODE_H__
23 #define __M2ETIS_PUBSUB_FILTER_DECISIONTREE_DECISIONTREENODE_H__
24 
25 #include <set>
26 #include <stdexcept>
27 #include <string>
28 #include <typeinfo>
29 
30 namespace m2etis {
31 namespace pubsub {
32 namespace filter {
33 
34  template<typename EventType, typename NetworkType>
36  public:
37  virtual ~DecisionTreeNode() {
38  }
39 
40  virtual void visit(const EventType & event, std::set<typename NetworkType::Key> &) = 0;
41 
42  // merges with another decision tree. needed for filter propagation
43  virtual void merge(boost::shared_ptr<DecisionTreeNode<EventType, NetworkType> > & other_tree, typename NetworkType::Key subscriber) = 0;
44 
45  virtual void changeSubscriber(typename NetworkType::Key subscriber) = 0;
46 
47  // adds subscriber
48  virtual void addSubscriber(const typename NetworkType::Key &) {
49  M2ETIS_THROW_API("DecisionTreeNode", "addSubscriber called for non-leaf node.");
50  }
51 
52  // Removes the node from the tree;
53  virtual void removeSubscriber(const typename NetworkType::Key &) {
54  M2ETIS_THROW_API("DecisionTreeNode", "removeSubscriber called for non-leaf node.");
55  }
56 
57  virtual bool hasSubscriber() {
58  M2ETIS_THROW_API("DecisionTreeNode", "hasSubscriber called for non-leaf node.");
59  }
60 
61  virtual bool hasSubscription(typename NetworkType::Key subscriber) = 0;
62 
63  // for debugging purposes:
64  virtual operator std::string() const {
65  return typeid(*this).name();
66  }
67 
69  template<typename Archive>
70  void serialize(Archive & ar, const unsigned int version) {
71  }
72  };
73 
74 } /* namespace filter */
75 } /* namespace pubsub */
76 } /* namespace m2etis */
77 
78 #endif /* __M2ETIS_PUBSUB_FILTER_DECISIONTREE_DECISIONTREENODE_H__ */
79 
void serialize(Archive &ar, const unsigned int version)
virtual void addSubscriber(const typename NetworkType::Key &)
virtual void merge(boost::shared_ptr< DecisionTreeNode< EventType, NetworkType > > &other_tree, typename NetworkType::Key subscriber)=0
virtual bool hasSubscription(typename NetworkType::Key subscriber)=0
virtual void visit(const EventType &event, std::set< typename NetworkType::Key > &)=0
friend class boost::serialization::access
virtual void removeSubscriber(const typename NetworkType::Key &)
virtual void changeSubscriber(typename NetworkType::Key subscriber)=0
#define M2ETIS_THROW_API(module, message)
throws on wrong API usage
Definition: Exceptions.h:40