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 
18 namespace 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 
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> >
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 } // namespace zypp
230 #endif // ZYPP_RELCOMPARE_H
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:206
static const Rel NE
Definition: Rel.h:53
static const Rel LT
Definition: Rel.h:54
static const Rel GT
Definition: Rel.h:56
bool compareByRel(Rel op, const Tp &lhs, const Tp &rhs, TCompare compare)
Comparison of two elements using relational operator op.
Definition: RelCompare.h:106
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:185
Relational operators.
Definition: Rel.h:45
static const Rel EQ
Definition: Rel.h:52
static const Rel LE
Definition: Rel.h:55
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:192
static const Rel ANY
Definition: Rel.h:58
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:199
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:220
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:171
int operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:86
SetCompare compare(const SetRelationMixin< Derived > &src, const SetRelationMixin< Derived > &trg)
relates: SetRelationMixin Compare sets
static const Rel GE
Definition: Rel.h:57
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:162
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Rel.h:143
General compare functor returning -1, 0, 1.
Definition: RelCompare.h:84
Functor to compare two elements by Rel based on a general TCompare functor.
Definition: RelCompare.h:156
bool operator()(const Tp &lhs, const Tp &rhs) const
Definition: RelCompare.h:178
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
CompareBy(Rel op_r)
Definition: RelCompare.h:158
static const Rel NONE
Definition: Rel.h:59