m2etis  0.4
FilterExp.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_FILTEREXP_H__
23 #define __M2ETIS_PUBSUB_FILTER_FILTEREXP_H__
24 
26 
27 namespace m2etis {
28 namespace pubsub {
29 namespace filter {
30 
31  template<typename EventType>
32  class FilterExp {
33  public:
34  typedef boost::shared_ptr<FilterExp<EventType>> FilterExpPtr;
35  FilterExp() {}
36  virtual ~FilterExp() {}
37 
38  virtual void Accept(FilterVisitor<EventType> & filter_visitor) const {
39  filter_visitor.Visit(this);
40  }
41 
42  // comparison operators to avoid having global ids in the network to deregister individual filters:
43  bool operator==(const FilterExp & other_filter) const {
44  return this->doCompare(other_filter) && other_filter.doCompare(*this);
45  }
46 
47  bool operator!=(const FilterExp & other_filter) const {
48  return !(*this == other_filter);
49  }
50 
51  // hash function to use predicates as keys in (unordered_)maps
52  // see below regarding specializing function in std namespace
53  size_t hash() const {
54  return doHash();
55  }
56 
57  // for debugging purposes:
58  virtual operator std::string() const {
59  return typeid(*this).name();
60  };
61 
62  std::string toString() {
63  return "FilterExpr";
64  }
65 
66  private:
67  virtual bool doCompare(const FilterExp &) const { return false; } // TODO: (Roland) make abstract
68 
69  virtual size_t doHash() const { return 0; } // TODO: (Roland) make abstract
70 
72  template<typename Archive>
73  void serialize(Archive &, const unsigned int) {
74  }
75  };
76 
77 } /* namespace filter */
78 } /* namespace pubsub */
79 } /* namespace m2etis */
80 
81 namespace std {
82 
83  template<typename EventType>
84  struct hash<m2etis::pubsub::filter::FilterExp<EventType>> : public unary_function<m2etis::pubsub::filter::FilterExp<EventType>, size_t> {
86  return filter.hash();
87  }
88  };
89 
90 } /* namespace std */
91 
92 #endif /* __M2ETIS_PUBSUB_FILTER_FILTEREXP_H_ */
93 
bool operator==(const FilterExp &other_filter) const
Definition: FilterExp.h:43
friend class boost::serialization::access
Definition: FilterExp.h:71
STL namespace.
bool operator!=(const FilterExp &other_filter) const
Definition: FilterExp.h:47
boost::shared_ptr< FilterExp< EventType > > FilterExpPtr
Definition: FilterExp.h:34
virtual void Accept(FilterVisitor< EventType > &filter_visitor) const
Definition: FilterExp.h:38
virtual void Visit(const FilterExp< EventType > *)=0
size_t operator()(const m2etis::pubsub::filter::FilterExp< EventType > &filter) const
Definition: FilterExp.h:85