m2etis  0.4
FilterPredicate.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_FILTERPREDICATE_H__
23 #define __M2ETIS_PUBSUB_FILTER_FILTERPREDICATE_H__
24 
25 #include <functional>
26 #include <map>
27 #include <set>
28 #include <string>
29 
30 #include "m2etis/TemplateHelper.h" // for Int2Type
31 
35 
47 
48 #include "boost/archive/text_iarchive.hpp"
49 #include "boost/archive/text_oarchive.hpp"
50 #include "boost/make_shared.hpp"
51 #include "boost/serialization/export.hpp"
52 #include "boost/serialization/base_object.hpp"
53 #include "boost/serialization/list.hpp"
54 #include "boost/serialization/map.hpp"
55 #include "boost/serialization/variant.hpp"
56 #include "boost/serialization/shared_ptr.hpp"
57 #include "boost/serialization/vector.hpp"
58 
59 namespace m2etis {
60 namespace pubsub {
61 
62  M2ETIS_API extern std::map<filter::AttributeName, std::shared_ptr<filter::AttributeAccessor_Basic> > attributes_accessor_map; // TODO: (Roland) make non-static
63 
64  enum OperatorName {
66  };
67 
68 namespace filter {
69 
70  template <typename EventType, typename AttributeType> class AttributeFilter;
71  template <typename EventType, typename AttributeType> class EqualsAttributeFilter;
72  template <typename EventType, typename AttributeType> class NotEqualsAttributeFilter;
73  template <typename EventType, typename AttributeType> class GreaterThanAttributeFilter;
74  template <typename EventType, typename AttributeType> class LessThanAttributeFilter;
75 
76  template <typename EventType, typename NetworkType> class DecisionTreeFilter;
77  template <typename EventType, typename NetworkType> class GeneralBooleanExpressionsFilter;
78 
79  template <typename EventType, typename NetworkType> class DecisionTreePreProcessVisitor;
80  template <typename EventType, typename NetworkType> class GeneralBooleanExpressionsPreProcessVisitor;
81 
82  // the following operator overloading and creator functions allow writing
83  // boolean expressions like:
84 // boost::make_shared<m2etis::pubsub::filter::OrExp<Position> > (
85 // (Equals<Position, int>(POSITION_X, {90}) ||
86 // Equals<Position, std::string>(POSITION_REGION, {"Ansbach"})
87 //
88 // )
89 
90  // instead of the following more complex syntax:
91  // x = 1 or y = 1:
92  // auto static_predicate2 = std::make_shared<OrExp<Position> > (
93  // std::make_shared<EqualsAttributeFilter<Position, int> >(&Position::x, std::vector<int>( {1})),
94  // std::make_shared<EqualsAttributeFilter<Position, int> >(&Position::y, std::vector<int>( {1})));
95 
96 
97  // operator overloading (easier notation):
98  template <typename BooleanExpType1, typename BooleanExpType2> OrExp<typename BooleanExpType1::schema> operator||(const BooleanExpType1 & operand1, const BooleanExpType2 & operand2) {
99  return OrExp<typename BooleanExpType1::schema>(boost::make_shared<BooleanExpType1>(operand1), boost::make_shared<BooleanExpType2>(operand2));
100  }
101  template <typename BooleanExpType1, typename BooleanExpType2> AndExp<typename BooleanExpType1::schema> operator&&(const BooleanExpType1 & operand1, const BooleanExpType2 & operand2) {
102  return AndExp<typename BooleanExpType1::schema>(boost::make_shared<BooleanExpType1>(operand1), boost::make_shared<BooleanExpType2>(operand2));
103  }
104 
105  // creator functions for type deduction and easier notation:
106  template <class EventType, class AttributeType> EqualsAttributeFilter<EventType, AttributeType> Equals(AttributeName attribute_id, const AttributeType & constants) {
107  return EqualsAttributeFilter<EventType, AttributeType>(attribute_id, constants);
108  }
109 
110  template <class EventType, class AttributeType> NotEqualsAttributeFilter<EventType, AttributeType> NotEquals(AttributeName attribute_id, const AttributeType & constants) {
111  return NotEqualsAttributeFilter<EventType, AttributeType>(attribute_id, constants);
112  }
113 
114  template <class EventType, class AttributeType> LessThanAttributeFilter<EventType, AttributeType> LessThan(AttributeName attribute_id, const AttributeType & constants) {
115  return LessThanAttributeFilter<EventType, AttributeType>(attribute_id, constants);
116  }
117 
118  template <class EventType, class AttributeType> GreaterThanAttributeFilter<EventType, AttributeType> GreaterThan(AttributeName attribute_id, const AttributeType & constants) {
119  return GreaterThanAttributeFilter<EventType, AttributeType>(attribute_id, constants);
120  }
121 
122 } /* namespace filter */
123 } /* namespace pubsub */
124 } /* namespace m2etis */
125 
126 #endif /* __M2ETIS_PUBSUB_FILTER_FILTERPREDICATE_H__ */
127 
#define M2ETIS_API
OrExp< typename BooleanExpType1::schema > operator||(const BooleanExpType1 &operand1, const BooleanExpType2 &operand2)
GreaterThanAttributeFilter< EventType, AttributeType > GreaterThan(AttributeName attribute_id, const AttributeType &constants)
NotEqualsAttributeFilter< EventType, AttributeType > NotEquals(AttributeName attribute_id, const AttributeType &constants)
LessThanAttributeFilter< EventType, AttributeType > LessThan(AttributeName attribute_id, const AttributeType &constants)
M2ETIS_API std::map< filter::AttributeName, std::shared_ptr< filter::AttributeAccessor_Basic > > attributes_accessor_map
AndExp< typename BooleanExpType1::schema > operator&&(const BooleanExpType1 &operand1, const BooleanExpType2 &operand2)
EqualsAttributeFilter< EventType, AttributeType > Equals(AttributeName attribute_id, const AttributeType &constants)