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