libzypp: zypp/RelCompare.h Source File

libzypp 17.38.13

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> >
156 struct CompareBy
157 {
158 CompareBy( Rel op_r )
159 : _op( op_r )
160 {}
161
162 bool operator()( const Tp & lhs, const Tp & rhs ) const
163 { return compareByRel( _op, lhs, rhs, TCompare() ); }
164
165 Rel _op;
166 };
167
168 template<class Tp, class TCompare = Compare<Tp> >
169 struct CompareByEQ
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> >
176 struct CompareByNE
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> >
183 struct CompareByLT
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> >
190 struct CompareByLE
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> >
197 struct CompareByGT
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> >
204 struct CompareByGE
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> >
211 struct CompareByANY
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> >
218 struct CompareByNONE
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
Rel.h
zypp::compareByRel
bool compareByRel(Rel op, const Tp &lhs, const Tp &rhs, TCompare compare)
Comparison of two elements using relational operator op.
Definition RelCompare.h:106
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::CompareByANY
Definition RelCompare.h:212
zypp::CompareByANY::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:213
zypp::CompareByEQ
Definition RelCompare.h:170
zypp::CompareByEQ::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:171
zypp::CompareByGE
Definition RelCompare.h:205
zypp::CompareByGE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:206
zypp::CompareByGT
Definition RelCompare.h:198
zypp::CompareByGT::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:199
zypp::CompareByLE
Definition RelCompare.h:191
zypp::CompareByLE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:192
zypp::CompareByLT
Definition RelCompare.h:184
zypp::CompareByLT::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:185
zypp::CompareByNE
Definition RelCompare.h:177
zypp::CompareByNE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:178
zypp::CompareByNONE
Definition RelCompare.h:219
zypp::CompareByNONE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:220
zypp::CompareBy::_op
Rel _op
Definition RelCompare.h:165
zypp::CompareBy::CompareBy
CompareBy(Rel op_r)
Definition RelCompare.h:158
zypp::CompareBy::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:162
zypp::Compare
General compare functor returning -1, 0, 1.
Definition RelCompare.h:85
zypp::Compare::operator()
int operator()(const Tp &lhs, const Tp &rhs) const
Definition RelCompare.h:86
zypp::Rel
Relational operators.
Definition Rel.h:46
zypp::Rel::inSwitch
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition Rel.h:143
zypp::Rel::LT
static const Rel LT
Definition Rel.h:54
zypp::Rel::GT
static const Rel GT
Definition Rel.h:56
zypp::Rel::LE
static const Rel LE
Definition Rel.h:55
zypp::Rel::GE
static const Rel GE
Definition Rel.h:57
zypp::Rel::NONE
static const Rel NONE
Definition Rel.h:59
zypp::Rel::NE
static const Rel NE
Definition Rel.h:53
zypp::Rel::ANY
static const Rel ANY
Definition Rel.h:58
zypp::Rel::EQ
static const Rel EQ
Definition Rel.h:52
zypp::Rel::ANY_e
@ ANY_e
Definition Rel.h:75
zypp::Rel::LT_e
@ LT_e
Definition Rel.h:71
zypp::Rel::GT_e
@ GT_e
Definition Rel.h:69
zypp::Rel::NE_e
@ NE_e
Definition Rel.h:74
zypp::Rel::LE_e
@ LE_e
Definition Rel.h:73
zypp::Rel::NONE_e
@ NONE_e
Definition Rel.h:68
zypp::Rel::EQ_e
@ EQ_e
Definition Rel.h:70
zypp::Rel::GE_e
@ GE_e
Definition Rel.h:72