libzypp 17.38.7
RelCompare.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_RELCOMPARE_H
13#define ZYPP_RELCOMPARE_H
14
15#include <zypp/Rel.h>
16
18namespace zypp
19{
20
77
83 template<class Tp>
84 struct Compare
85 {
86 int operator()( const Tp & lhs, const Tp & rhs ) const
87 { return Tp::compare( lhs, rhs ); }
88 };
89
91
105 template<class Tp, class TCompare>
106 inline bool compareByRel( Rel op, const Tp & lhs, const Tp & rhs, TCompare compare )
107 {
108 switch ( op.inSwitch() )
109 {
110 case Rel::EQ_e:
111 return compare( lhs, rhs ) == 0;
112 break;
113 case Rel::NE_e:
114 return compare( lhs, rhs ) != 0;
115 break;
116 case Rel::LT_e:
117 return compare( lhs, rhs ) < 0;
118 break;
119 case Rel::LE_e:
120 return compare( lhs, rhs ) <= 0;
121 break;
122 case Rel::GT_e:
123 return compare( lhs, rhs ) > 0;
124 break;
125 case Rel::GE_e:
126 return compare( lhs, rhs ) >= 0;
127 break;
128 case Rel::ANY_e:
129 return true;
130 break;
131 case Rel::NONE_e:
132 return false;
133 break;
134 }
135 return false;
136 }
137
141 template<class Tp>
142 inline bool compareByRel( Rel op, const Tp & lhs, const Tp & rhs )
143 { return compareByRel( op, lhs, rhs, Compare<Tp>() ); }
144
146
148
155 template<class Tp, class TCompare = Compare<Tp> >
157 {
159 : _op( op_r )
160 {}
161
162 bool operator()( const Tp & lhs, const Tp & rhs ) const
163 { return compareByRel( _op, lhs, rhs, TCompare() ); }
164
166 };
167
168 template<class Tp, class TCompare = Compare<Tp> >
170 {
171 bool operator()( const Tp & lhs, const Tp & rhs ) const
172 { return compareByRel( Rel::EQ, lhs, rhs, TCompare() ); }
173 };
174
175 template<class Tp, class TCompare = Compare<Tp> >
177 {
178 bool operator()( const Tp & lhs, const Tp & rhs ) const
179 { return compareByRel( Rel::NE, lhs, rhs, TCompare() ); }
180 };
181
182 template<class Tp, class TCompare = Compare<Tp> >
184 {
185 bool operator()( const Tp & lhs, const Tp & rhs ) const
186 { return compareByRel( Rel::LT, lhs, rhs, TCompare() ); }
187 };
188
189 template<class Tp, class TCompare = Compare<Tp> >
191 {
192 bool operator()( const Tp & lhs, const Tp & rhs ) const
193 { return compareByRel( Rel::LE, lhs, rhs, TCompare() ); }
194 };
195
196 template<class Tp, class TCompare = Compare<Tp> >
198 {
199 bool operator()( const Tp & lhs, const Tp & rhs ) const
200 { return compareByRel( Rel::GT, lhs, rhs, TCompare() ); }
201 };
202
203 template<class Tp, class TCompare = Compare<Tp> >
205 {
206 bool operator()( const Tp & lhs, const Tp & rhs ) const
207 { return compareByRel( Rel::GE, lhs, rhs, TCompare() ); }
208 };
209
210 template<class Tp, class TCompare = Compare<Tp> >
212 {
213 bool operator()( const Tp & lhs, const Tp & rhs ) const
214 { return compareByRel( Rel::ANY, lhs, rhs, TCompare() ); }
215 };
216
217 template<class Tp, class TCompare = Compare<Tp> >
219 {
220 bool operator()( const Tp & lhs, const Tp & rhs ) const
221 { return compareByRel( Rel::NONE, lhs, rhs, TCompare() ); }
222 };
223
225
227
228} // namespace zypp
230#endif // ZYPP_RELCOMPARE_H
bool compareByRel(Rel op, const Tp &lhs, const Tp &rhs, TCompare compare)
Comparison of two elements using relational operator op.
Definition RelCompare.h:106
Easy-to use interface to the ZYPP dependency resolver.
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:213
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:171
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:206
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:199
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:192
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:185
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:178
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:220
CompareBy(Rel op_r)
Definition RelCompare.h:158
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:162
General compare functor returning -1, 0, 1.
Definition RelCompare.h:85
int operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:86
Relational operators.
Definition Rel.h:46
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition Rel.h:143
static const Rel LT
Definition Rel.h:54
static const Rel GT
Definition Rel.h:56
static const Rel LE
Definition Rel.h:55
static const Rel GE
Definition Rel.h:57
static const Rel NONE
Definition Rel.h:59
static const Rel NE
Definition Rel.h:53
static const Rel ANY
Definition Rel.h:58
static const Rel EQ
Definition Rel.h:52
@ ANY_e
Definition Rel.h:75
@ LT_e
Definition Rel.h:71
@ GT_e
Definition Rel.h:69
@ NE_e
Definition Rel.h:74
@ LE_e
Definition Rel.h:73
@ NONE_e
Definition Rel.h:68
@ EQ_e
Definition Rel.h:70
@ GE_e
Definition Rel.h:72