m2etis  0.4
GetMinPredicatesVisitor.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_GETMINPREDICATESVISITOR_H__
23 #define __M2ETIS_PUBSUB_FILTER_GETMINPREDICATESVISITOR_H__
24 
25 #include <stack>
26 
28 
29 namespace m2etis {
30 namespace pubsub {
31 namespace filter {
32 
33  // implementation of GetMinPredicates algorithm in Bittner
34  template <typename EventType>
35  class GetMinPredicatesVisitor : public FilterVisitor<EventType> {
36  public:
38 
40 
41  virtual void Visit(const FilterExp<EventType> *) override {}
42 
43  virtual void Visit(const AndExp<EventType> *) override {
44  int operand1 = operand_stack_.top();
45  operand_stack_.pop();
46  int operand2 = operand_stack_.top();
47  operand_stack_.pop();
48 
49  operand_stack_.push(operand1 + operand2);
50  }
51 
52  virtual void Visit(const OrExp<EventType> *) override {
53  int operand1 = operand_stack_.top();
54  operand_stack_.pop();
55  int operand2 = operand_stack_.top();
56  operand_stack_.pop();
57 
58  operand_stack_.push((operand1 < operand2) ? operand1 : operand2); // return minimum
59  }
60 
61  virtual void Visit(const Predicate<EventType> * predicate) override {
62  operand_stack_.push(1);
63  }
64 
65  int get_result() const {
66  return operand_stack_.empty() ? 0 : operand_stack_.top();
67  }
68 
69  private:
70  std::stack<int> operand_stack_; // stack to store operands (=results of 2 children) of GetMinPredicates
71  }; // class MatchVisitor
72 
73 } /* namespace filter */
74 } /* namespace pubsub */
75 } /* namespace m2etis */
76 
77 #endif /* __M2ETIS_PUBSUB_FILTER_GETMINPREDICATESVISITOR_H__ */
78 
virtual void Visit(const OrExp< EventType > *) override
virtual void Visit(const AndExp< EventType > *) override
virtual void Visit(const Predicate< EventType > *predicate) override
virtual void Visit(const FilterExp< EventType > *) override