libzypp  13.10.6
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 _Compare>
108  inline bool compareByRel( Rel op, const _Tp & lhs, const _Tp & rhs,
109  _Compare compare )
110  {
111  switch ( op.inSwitch() )
112  {
113  case Rel::EQ_e:
114  return compare( lhs, rhs ) == 0;
115  break;
116  case Rel::NE_e:
117  return compare( lhs, rhs ) != 0;
118  break;
119  case Rel::LT_e:
120  return compare( lhs, rhs ) < 0;
121  break;
122  case Rel::LE_e:
123  return compare( lhs, rhs ) <= 0;
124  break;
125  case Rel::GT_e:
126  return compare( lhs, rhs ) > 0;
127  break;
128  case Rel::GE_e:
129  return compare( lhs, rhs ) >= 0;
130  break;
131  case Rel::ANY_e:
132  return true;
133  break;
134  case Rel::NONE_e:
135  return false;
136  break;
137  }
138  return false;
139  }
140 
144  template<class _Tp>
145  inline bool compareByRel( Rel op, const _Tp & lhs, const _Tp & rhs )
146  { return compareByRel( op, lhs, rhs, Compare<_Tp>() ); }
147 
149 
151 
158  template<class _Tp, class _Compare = Compare<_Tp> >
159  struct CompareBy : public std::binary_function<_Tp,_Tp,bool>
160  {
161  CompareBy( Rel op_r )
162  : _op( op_r )
163  {}
164 
165  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
166  { return compareByRel( _op, lhs, rhs, _Compare() ); }
167 
169  };
170 
171  template<class _Tp, class _Compare = Compare<_Tp> >
172  struct CompareByEQ : public std::binary_function<_Tp,_Tp,bool>
173  {
174  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
175  { return compareByRel( Rel::EQ, lhs, rhs, _Compare() ); }
176  };
177 
178  template<class _Tp, class _Compare = Compare<_Tp> >
179  struct CompareByNE : public std::binary_function<_Tp,_Tp,bool>
180  {
181  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
182  { return compareByRel( Rel::NE, lhs, rhs, _Compare() ); }
183  };
184 
185  template<class _Tp, class _Compare = Compare<_Tp> >
186  struct CompareByLT : public std::binary_function<_Tp,_Tp,bool>
187  {
188  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
189  { return compareByRel( Rel::LT, lhs, rhs, _Compare() ); }
190  };
191 
192  template<class _Tp, class _Compare = Compare<_Tp> >
193  struct CompareByLE : public std::binary_function<_Tp,_Tp,bool>
194  {
195  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
196  { return compareByRel( Rel::LE, lhs, rhs, _Compare() ); }
197  };
198 
199  template<class _Tp, class _Compare = Compare<_Tp> >
200  struct CompareByGT : public std::binary_function<_Tp,_Tp,bool>
201  {
202  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
203  { return compareByRel( Rel::GT, lhs, rhs, _Compare() ); }
204  };
205 
206  template<class _Tp, class _Compare = Compare<_Tp> >
207  struct CompareByGE : public std::binary_function<_Tp,_Tp,bool>
208  {
209  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
210  { return compareByRel( Rel::GE, lhs, rhs, _Compare() ); }
211  };
212 
213  template<class _Tp, class _Compare = Compare<_Tp> >
214  struct CompareByANY : public std::binary_function<_Tp,_Tp,bool>
215  {
216  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
217  { return compareByRel( Rel::ANY, lhs, rhs, _Compare() ); }
218  };
219 
220  template<class _Tp, class _Compare = Compare<_Tp> >
221  struct CompareByNONE : public std::binary_function<_Tp,_Tp,bool>
222  {
223  bool operator()( const _Tp & lhs, const _Tp & rhs ) const
224  { return compareByRel( Rel::NONE, lhs, rhs, _Compare() ); }
225  };
226 
228 
230 } // namespace zypp
233 #endif // ZYPP_RELCOMPARE_H
static const Rel NE
Definition: Rel.h:51
static const Rel LT
Definition: Rel.h:52
static const Rel GT
Definition: Rel.h:54
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:181
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:195
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:202
Relational operators.
Definition: Rel.h:43
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:223
static const Rel EQ
Definition: Rel.h:50
CompareBy(Rel op_r)
Definition: RelCompare.h:161
static const Rel LE
Definition: Rel.h:53
static const Rel ANY
Definition: Rel.h:56
int operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:88
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:174
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:165
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:188
bool compareByRel(Rel op, const _Tp &lhs, const _Tp &rhs, _Compare compare)
Comparison of two elements using relational operator op.
Definition: RelCompare.h:108
static const Rel GE
Definition: Rel.h:55
General compare functor returning -1, 0, 1.
Definition: RelCompare.h:86
Functor to compare two elements by Rel based on a general _Compare functor.
Definition: RelCompare.h:159
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:209
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Definition: Rel.h:141
bool operator()(const _Tp &lhs, const _Tp &rhs) const
Definition: RelCompare.h:216
static const Rel NONE
Definition: Rel.h:57