m2etis  0.4
DecisionTreeWalkerVisitor.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_DECISIONTREEWALKERVISITOR_H__
23 #define __M2ETIS_PUBSUB_FILTER_DECISIONTREEWALKERVISITOR_H__
24 
27 
28 namespace m2etis {
29 namespace pubsub {
30 namespace filter {
31 
32  template<typename EventType, typename NetworkType>
33  class DecisionTreeWalkerVisitor : public FilterVisitor<EventType> {
34  public:
35  DecisionTreeWalkerVisitor(boost::shared_ptr<DecisionTreeNode<EventType, NetworkType> > * v) : current_decision_tree_node_ptr_(v) {
36  }
37 
39  }
40 
41  virtual void Visit(const FilterExp<EventType> *) override {
42  M2ETIS_THROW_API("DecisionTreeRemoveSubscriberVisitor", "FilterExp not allowed in decision tree filter strategy.");
43  }
44 
45  virtual void Visit(const AndExp<EventType> *) override {
46  }
47 
48  virtual void Visit(const OrExp<EventType> *) override {
49  M2ETIS_THROW_API("DecisionTreeRemoveSubscriberVisitor", "OrExp not allowed in decision tree filter strategy.");
50  }
51 
52  virtual void Visit(const Predicate<EventType> * equals_predicate) override {
53  if (current_decision_tree_node_ptr_) {
54  // if pointer is zero the specified filter for walking the tree is not registered
55  attribute_type_information.decision_tree_node_ptr_ = current_decision_tree_node_ptr_;
56 
57  equals_predicate->getAttributeType(*this);
58 
59  current_decision_tree_node_ptr_ = attribute_type_information.decision_tree_node_ptr_;
60  }
61  }
62 
64  auto decision_tree_ptr = new DecisionTreeFilter<EventType, NetworkType>();
65  attribute_type_information(filter, decision_tree_ptr, 0);
66  delete decision_tree_ptr;
67  }
68 
70  auto decision_tree_ptr = new DecisionTreeFilter<EventType, NetworkType>();
71  attribute_type_information(filter, decision_tree_ptr, 0);
72  delete decision_tree_ptr;
73  }
74 
76 
77  boost::shared_ptr<DecisionTreeNode<EventType, NetworkType> > * get_current_decision_tree_node_ptr() {
78  return current_decision_tree_node_ptr_;
79  }
80 
81  private:
82  boost::shared_ptr<DecisionTreeNode<EventType, NetworkType> > * current_decision_tree_node_ptr_;
83 
84  AttributeTypeInformation<EventType, NetworkType> attribute_type_information;
85  };
86  // class DecisionTreeWalkerVisitor
87 
88 } /* namespace filter */
89 } /* namespace pubsub */
90 } /* namespace m2etis */
91 
92 #endif /* __M2ETIS_PUBSUB_FILTER_DECISIONTREEWALKERVISITOR_H__ */
93 
virtual void Visit(const AndExp< EventType > *) override
virtual void getAttributeType(const EqualsAttributeFilter< EventType, int > *filter)
DecisionTreeWalkerVisitor(boost::shared_ptr< DecisionTreeNode< EventType, NetworkType > > *v)
virtual void Visit(const Predicate< EventType > *equals_predicate) override
boost::shared_ptr< DecisionTreeNode< EventType, NetworkType > > * get_current_decision_tree_node_ptr()
virtual void getAttributeType(const EqualsAttributeFilter< EventType, std::string > *filter)
virtual void Visit(const FilterExp< EventType > *) override
virtual void Visit(const OrExp< EventType > *) override
#define M2ETIS_THROW_API(module, message)
throws on wrong API usage
Definition: Exceptions.h:40
virtual void getAttributeType(FilterVisitor< EventType > &visitor) const =0