Predicates.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu)
20  * @date 2017
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 #include <tuple>
28 #include <type_traits>
29 
30 namespace armarx
31 {
32  template <class T>
34  {
35  EqualPredicate(T t) : t{std::move(t)}
36  {
37  }
38 
39  bool
40  operator()(const T& other)
41  {
42  return t == other;
43  }
44 
45  const T t;
46  };
47 
48  template <class T>
51  {
52  return EqualPredicate<T>{std::move(t)};
53  }
54 
55  template <class T>
57  {
58  UnequalPredicate(T t) : t{std::move(t)}
59  {
60  }
61 
62  bool
63  operator()(const T& other)
64  {
65  return t != other;
66  }
67 
68  const T t;
69  };
70 
71  template <class T>
74  {
75  return UnequalPredicate<T>{std::move(t)};
76  }
77 
78  template <class T>
80  {
81  LessPredicate(T t) : t{std::move(t)}
82  {
83  }
84 
85  bool
86  operator()(const T& other)
87  {
88  return other < t;
89  }
90 
91  const T t;
92  };
93 
94  template <class T>
97  {
98  return LessPredicate<T>{std::move(t)};
99  }
100 
101  template <class T>
103  {
104  GreaterPredicate(T t) : t{std::move(t)}
105  {
106  }
107 
108  bool
109  operator()(const T& other)
110  {
111  return other > t;
112  }
113 
114  const T t;
115  };
116 
117  template <class T>
120  {
121  return GreaterPredicate<T>{std::move(t)};
122  }
123 
124  template <class T>
126  {
127  LessEqualPredicate(T t) : t{std::move(t)}
128  {
129  }
130 
131  bool
132  operator()(const T& other)
133  {
134  return other <= t;
135  }
136 
137  const T t;
138  };
139 
140  template <class T>
143  {
144  return LessEqualPredicate<T>{std::move(t)};
145  }
146 
147  template <class T>
149  {
150  GreaterEqualPredicate(T t) : t{std::move(t)}
151  {
152  }
153 
154  bool
155  operator()(const T& other)
156  {
157  return other >= t;
158  }
159 
160  const T t;
161  };
162 
163  template <class T>
166  {
167  return GreaterEqualPredicate<T>{std::move(t)};
168  }
169 } // namespace armarx
armarx::EqualPredicate::EqualPredicate
EqualPredicate(T t)
Definition: Predicates.h:35
armarx::greaterEqualPredicate
GreaterEqualPredicate< T > greaterEqualPredicate(T t)
Definition: Predicates.h:165
armarx::GreaterPredicate::t
const T t
Definition: Predicates.h:114
armarx::LessPredicate::operator()
bool operator()(const T &other)
Definition: Predicates.h:86
armarx::GreaterEqualPredicate::operator()
bool operator()(const T &other)
Definition: Predicates.h:155
armarx::GreaterPredicate
Definition: Predicates.h:102
armarx::lessPredicate
LessPredicate< T > lessPredicate(T t)
Definition: Predicates.h:96
armarx::LessEqualPredicate
Definition: Predicates.h:125
armarx::equalPredicate
EqualPredicate< T > equalPredicate(T t)
Definition: Predicates.h:50
armarx::LessEqualPredicate::operator()
bool operator()(const T &other)
Definition: Predicates.h:132
armarx::lessEqualPredicate
LessEqualPredicate< T > lessEqualPredicate(T t)
Definition: Predicates.h:142
armarx::LessPredicate::LessPredicate
LessPredicate(T t)
Definition: Predicates.h:81
armarx::GreaterPredicate::operator()
bool operator()(const T &other)
Definition: Predicates.h:109
armarx::UnequalPredicate::UnequalPredicate
UnequalPredicate(T t)
Definition: Predicates.h:58
armarx::EqualPredicate::operator()
bool operator()(const T &other)
Definition: Predicates.h:40
armarx::LessPredicate
Definition: Predicates.h:79
armarx::UnequalPredicate
Definition: Predicates.h:56
armarx::GreaterPredicate::GreaterPredicate
GreaterPredicate(T t)
Definition: Predicates.h:104
armarx::GreaterEqualPredicate
Definition: Predicates.h:148
armarx::greaterPredicate
GreaterPredicate< T > greaterPredicate(T t)
Definition: Predicates.h:119
armarx::GreaterEqualPredicate::t
const T t
Definition: Predicates.h:160
armarx::LessEqualPredicate::t
const T t
Definition: Predicates.h:137
armarx::LessEqualPredicate::LessEqualPredicate
LessEqualPredicate(T t)
Definition: Predicates.h:127
armarx::unequalPredicate
UnequalPredicate< T > unequalPredicate(T t)
Definition: Predicates.h:73
armarx::EqualPredicate
Definition: Predicates.h:33
armarx::GreaterEqualPredicate::GreaterEqualPredicate
GreaterEqualPredicate(T t)
Definition: Predicates.h:150
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
armarx::LessPredicate::t
const T t
Definition: Predicates.h:91
armarx::EqualPredicate::t
const T t
Definition: Predicates.h:45
armarx::UnequalPredicate::t
const T t
Definition: Predicates.h:68
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::UnequalPredicate::operator()
bool operator()(const T &other)
Definition: Predicates.h:63