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