libzypp  17.25.0
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 <functional>
16 
17 #include <zypp/Rel.h>
18 
20 namespace zypp
21 {
22 
79 
85  template<class Tp>
86  struct Compare : public std::binary_function<Tp,Tp,int>
87  {
88  int operator()( const Tp & lhs, const Tp & rhs ) const
89  { return Tp::compare( lhs, rhs ); }
90  };
91 
93 
107  template<class Tp, class TCompare>
108  inline bool compareByRel( Rel op, const Tp & lhs, const Tp & rhs, TCompare compare )
109  {
110  switch ( op.inSwitch() )
111  {
112  case Rel::EQ_e:
113  return compare( lhs, rhs ) == 0;
114  break;
115  case Rel::NE_e:
116  return compare( lhs, rhs ) != 0;
117  break;
118  case Rel::LT_e:
119  return compare( lhs, rhs ) < 0;
120  break;
121  case Rel::LE_e:
122  return compare( lhs, rhs ) <= 0;
123  break;
124  case Rel::GT_e:
125  return compare( lhs, rhs ) > 0;
126  break;
127  case Rel::GE_e:
128  return compare( lhs, rhs ) >= 0;
129  break;
130  case Rel::ANY_e:
131  return true;
132  break;
133  case Rel::NONE_e:
134  return false;
135  break;
136  }
137  return false;
138  }
139 
143  template<class Tp>
144  inline bool compareByRel( Rel op, const Tp & lhs, const Tp & rhs )
145  { return compareByRel( op, lhs, rhs, Compare<Tp>() ); }
146 
148 
150 
157  template<class Tp, class TCompare = Compare<Tp> >
158  struct CompareBy : public std::binary_function<Tp,Tp,bool>
159  {
160  CompareBy( Rel op_r )
161  : _op( op_r )
162  {}
163 
164  bool operator()( const Tp & lhs, const Tp & rhs ) const
165  { return compareByRel( _op, lhs, rhs, TCompare() ); }
166 
168  };
169 
170  template<class Tp, class TCompare = Compare<Tp> >
171  struct CompareByEQ : public std::binary_function<Tp,Tp,bool>
172  {
173  bool operator()( const Tp & lhs, const Tp & rhs ) const
174  { return compareByRel( Rel::EQ, lhs, rhs, TCompare() ); }
175  };
176 
177  template<class Tp, class TCompare = Compare<Tp> >
178  struct CompareByNE : public std::binary_function<Tp,Tp,bool>
179  {
180  bool operator()( const Tp & lhs, const Tp & rhs ) const
181  { return compareByRel( Rel::NE, lhs, rhs, TCompare() ); }
182  };
183 
184  template<class Tp, class TCompare = Compare<Tp> >
185  struct CompareByLT : public std::binary_function<Tp,Tp,bool>
186  {
187  bool operator()( const Tp & lhs, const Tp & rhs ) const
188  { return compareByRel( Rel::LT, lhs, rhs, TCompare() ); }
189  };
190 
191  template<class Tp, class TCompare = Compare<Tp> >
192  struct CompareByLE : public std::binary_function<Tp,Tp,bool>
193  {
194  bool operator()( const Tp & lhs, const Tp & rhs ) const
195  { return compareByRel( Rel::LE, lhs, rhs, TCompare() ); }
196  };
197 
198  template<class Tp, class TCompare = Compare<Tp> >
199  struct CompareByGT : public std::binary_function<Tp,Tp,bool>
200  {
201  bool operator()( const Tp & lhs, const Tp & rhs ) const
202  { return compareByRel( Rel::GT, lhs, rhs, TCompare() ); }
203  };
204 
205  template<class Tp, class TCompare = Compare<Tp> >
206  struct CompareByGE : public std::binary_function<Tp,Tp,bool>
207  {
208  bool operator()( const Tp & lhs, const Tp & rhs ) const
209  { return compareByRel( Rel::GE, lhs, rhs, TCompare() ); }
210  };
211 
212  template<class Tp, class TCompare = Compare<Tp> >
213  struct CompareByANY : public std::binary_function<Tp,Tp,bool>
214  {
215  bool operator()( const Tp & lhs, const Tp & rhs ) const
216  { return compareByRel( Rel::ANY, lhs, rhs, TCompare() ); }
217  };
218 
219  template<class Tp, class TCompare = Compare<Tp> >
220  struct CompareByNONE : public std::binary_function<Tp,Tp,bool>
221  {
222  bool operator()( const Tp & lhs, const Tp & rhs ) const
223  { return compareByRel( Rel::NONE, lhs, rhs, TCompare() ); }
224  };
225 
227 
229 } // namespace zypp
232 #endif // ZYPP_RELCOMPARE_H
zypp::CompareBy
Functor to compare two elements by Rel based on a general TCompare functor.
Definition: RelCompare.h:158
zypp::Rel::GT
static const Rel GT
Definition: Rel.h:54
zypp::CompareByGT
Definition: RelCompare.h:199
zypp::Rel::LE_e
Definition: Rel.h:71
zypp::CompareByANY::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:215
zypp::Rel::NONE
static const Rel NONE
Definition: Rel.h:57
zypp::Rel
Relational operators.
Definition: Rel.h:43
zypp::CompareBy::CompareBy
CompareBy(Rel op_r)
Definition: RelCompare.h:160
zypp::CompareByLT::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:187
zypp::CompareByNE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:180
zypp::Rel::NONE_e
Definition: Rel.h:66
zypp::Rel::LE
static const Rel LE
Definition: Rel.h:53
zypp::CompareByLT
Definition: RelCompare.h:185
Rel.h
zypp::CompareByNONE
Definition: RelCompare.h:220
zypp::Rel::ANY
static const Rel ANY
Definition: Rel.h:56
zypp::CompareByEQ::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:173
zypp::CompareByGE
Definition: RelCompare.h:206
zypp::CompareByLE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:194
zypp::Rel::NE
static const Rel NE
Definition: Rel.h:51
zypp::Rel::inSwitch
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Rel.h:141
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::CompareByLE
Definition: RelCompare.h:192
zypp::CompareByEQ
Definition: RelCompare.h:171
zypp::CompareByNE
Definition: RelCompare.h:178
zypp::Rel::EQ
static const Rel EQ
Definition: Rel.h:50
zypp::CompareByANY
Definition: RelCompare.h:213
zypp::Rel::NE_e
Definition: Rel.h:72
zypp::Rel::GT_e
Definition: Rel.h:67
zypp::Rel::EQ_e
Definition: Rel.h:68
zypp::Compare
General compare functor returning -1, 0, 1.
Definition: RelCompare.h:86
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:108
zypp::Rel::GE
static const Rel GE
Definition: Rel.h:55
zypp::Rel::LT
static const Rel LT
Definition: Rel.h:52
zypp::Compare::operator()
int operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:88
zypp::Rel::ANY_e
Definition: Rel.h:73
zypp::CompareBy::_op
Rel _op
Definition: RelCompare.h:167
zypp::CompareByGE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:208
zypp::CompareByNONE::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:222
zypp::Rel::GE_e
Definition: Rel.h:70
zypp::Rel::LT_e
Definition: Rel.h:69
zypp::CompareByGT::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:201
zypp::CompareBy::operator()
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:164