m2etis  0.4
EqualsAttributeFilter.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_EQUALSATTRIBUTEFILTER_H__
23 #define __M2ETIS_PUBSUB_FILTER_FILTEREXPRESSIONS_EQUALSATTRIBUTEFILTER_H__
24 
27 
28 namespace m2etis {
29 namespace pubsub {
30 namespace filter {
31 
32  template<typename EventType, typename AttributeType> class AttributeFilter;
33  template<typename EventType, typename AttributeType> class NotEqualsAttributeFilter;
34  template<typename EventType, typename AttributeType> class GreaterThanAttributeFilter;
35  template<typename EventType, typename AttributeType> class LessThanAttributeFilter;
36 
37  template<typename EventType, typename AttributeType>
38  class EqualsAttributeFilter : public AttributeFilter<EventType, AttributeType> {
39  public:
40  typedef EventType schema; // needed for operator overloading FIXME: (Daniel) really? never used or I don't see it
41  EqualsAttributeFilter() : AttributeFilter<EventType, AttributeType>(-1, {}) {} // needed for boost serialization
42  EqualsAttributeFilter(const AttributeName attribute_id, const AttributeType & constants) : AttributeFilter<EventType, AttributeType>(attribute_id, {constants}) {}
44 
45  // function called to match against an event
46  virtual bool matchAttribute(const AttributeType & attribute) const override {
47  return attribute == this->get_constants()[0]; // attribute type has to implement "=="-operator
48  }
49 
51 
52  virtual void getAttributeType(FilterVisitor<EventType> & visitor) const override {
53  visitor.getAttributeType(this);
54  }
55 
56  virtual bool overlaps(const AttributeFilter<EventType, AttributeType> * other_filter) const override {
57  if (this->get_attribute_id() != other_filter->get_attribute_id()) {
58  return true; // AttributeFilters for different attributes overlap
59  }
60  if (typeid(EqualsAttributeFilter<EventType, AttributeType>) == typeid(*other_filter)) {
61  return this->get_constants()[0] == other_filter->get_constants()[0];
62  }
63  if (typeid(NotEqualsAttributeFilter<EventType, AttributeType>) == typeid(*other_filter)) {
64  return this->get_constants()[0] != other_filter->get_constants()[0];
65  }
66  if (typeid(GreaterThanAttributeFilter<EventType, AttributeType>) == typeid(*other_filter)) {
67  return this->get_constants()[0] > other_filter->get_constants()[0];
68  }
69  if (typeid(LessThanAttributeFilter<EventType, AttributeType>) == typeid(*other_filter)) {
70  return this->get_constants()[0] < other_filter->get_constants()[0];
71  }
72 
73  return true;
74  } // overlaps()
75 
76  private:
77  friend class boost::serialization::access; // not sure if necessary
78  template<typename Archive>
79  void serialize(Archive & ar, const unsigned int) {
80  ar & boost::serialization::base_object<AttributeFilter<EventType, AttributeType>>(*this);
81  }
82  }; // EqualsAttributeFilter
83 
84 } /* namespace filter */
85 } /* namespace pubsub */
86 } /* namespace m2etis */
87 
88 #endif /* __M2ETIS_PUBSUB_FILTER_FILTEREXPRESSIONS_EQUALSATTRIBUTEFILTER_H__ */
89 
virtual void getAttributeType(FilterVisitor< EventType > &visitor) const override
virtual bool overlaps(const AttributeFilter< EventType, AttributeType > *other_filter) const override
virtual void getAttributeType(const GreaterThanAttributeFilter< EventType, std::string > *)
Definition: FilterVisitor.h:49
const std::vector< AttributeType > get_constants() const
friend class boost::serialization::access
virtual bool matchAttribute(const AttributeType &attribute) const override
EqualsAttributeFilter(const AttributeName attribute_id, const AttributeType &constants)