m2etis  0.4
AndExp.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_FILTEREXPRESSIONS_ANDEXP_H__
23 #define __M2ETIS_PUBSUB_FILTER_FILTEREXPRESSIONS_ANDEXP_H__
24 
25 #include <functional>
26 
28 
29 namespace m2etis {
30 namespace pubsub {
31 namespace filter {
32 
33  template<typename EventType>
34  class AndExp : public FilterExp<EventType> {
35  public:
36  typedef EventType schema; // needed for operator overloading
37  AndExp(const boost::shared_ptr<FilterExp<EventType>> op1, const boost::shared_ptr<FilterExp<EventType>> op2) : operand1_(op1), operand2_(op2) {}
38  virtual ~AndExp() {}
39  AndExp() {} // for boost serialization
40 
41  virtual void Accept(FilterVisitor<EventType> & filter_visitor) const override {
42  operand1_->Accept(filter_visitor);
43  operand2_->Accept(filter_visitor);
44  filter_visitor.Visit(this);
45  }
46 
47  virtual operator boost::shared_ptr<FilterExp<EventType>>() const {
48  return boost::make_shared<AndExp<EventType>>(*this);
49  }
50 
51  // for debugging purposes:
52  virtual operator std::string() const override {
53  return (std::string("AndExp") + "(\n" + std::string(*operand1_) + ", \t\t " + std::string(*operand2_) + ")");
54  }
55 
56  private:
57  boost::shared_ptr<FilterExp<EventType>> operand1_;
58  boost::shared_ptr<FilterExp<EventType>> operand2_;
59 
60  virtual bool doCompare(const FilterExp<EventType> & other_filter) const override {
61  const AndExp * other_AndExp = dynamic_cast<const AndExp *>(&other_filter);
62 
63  if (other_AndExp) {
64  return (*operand1_ == *(other_AndExp->operand1_) && *operand2_ == *(other_AndExp->operand2_));
65  } else {
66  return false;
67  }
68  }
69 
70  virtual size_t doHash() const {
71  return std::hash<FilterExp<EventType>>()(*operand1_) ^ std::hash<FilterExp<EventType>>()(*operand2_);
72  }
73 
75  template<typename Archive>
76  void serialize(Archive & ar, const unsigned int) {
77  ar & boost::serialization::base_object<FilterExp<EventType>>(*this);
78  ar & operand1_;
79  ar & operand2_;
80  }
81  };
82 
83 } /* namespace filter */
84 } /* namespace pubsub */
85 } /* namespace m2etis */
86 
87 #endif /* __M2ETIS_PUBSUB_FILTER_FILTEREXPRESSIONS_ANDEXP_H__ */
88 
AndExp(const boost::shared_ptr< FilterExp< EventType >> op1, const boost::shared_ptr< FilterExp< EventType >> op2)
Definition: AndExp.h:37
friend class boost::serialization::access
Definition: AndExp.h:74
virtual void Accept(FilterVisitor< EventType > &filter_visitor) const override
Definition: AndExp.h:41
virtual void Visit(const FilterExp< EventType > *)=0