libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_RELCOMPARE_H 00013 #define ZYPP_RELCOMPARE_H 00014 00015 #include <functional> 00016 00017 #include "zypp/Rel.h" 00018 00020 namespace zypp 00021 { 00022 00079 00085 template<class _Tp> 00086 struct Compare : public std::binary_function<_Tp,_Tp,int> 00087 { 00088 int operator()( const _Tp & lhs, const _Tp & rhs ) const 00089 { return _Tp::compare( lhs, rhs ); } 00090 }; 00091 00093 00107 template<class _Tp, class _Compare> 00108 inline bool compareByRel( Rel op, const _Tp & lhs, const _Tp & rhs, 00109 _Compare compare ) 00110 { 00111 switch ( op.inSwitch() ) 00112 { 00113 case Rel::EQ_e: 00114 return compare( lhs, rhs ) == 0; 00115 break; 00116 case Rel::NE_e: 00117 return compare( lhs, rhs ) != 0; 00118 break; 00119 case Rel::LT_e: 00120 return compare( lhs, rhs ) < 0; 00121 break; 00122 case Rel::LE_e: 00123 return compare( lhs, rhs ) <= 0; 00124 break; 00125 case Rel::GT_e: 00126 return compare( lhs, rhs ) > 0; 00127 break; 00128 case Rel::GE_e: 00129 return compare( lhs, rhs ) >= 0; 00130 break; 00131 case Rel::ANY_e: 00132 return true; 00133 break; 00134 case Rel::NONE_e: 00135 return false; 00136 break; 00137 } 00138 return false; 00139 } 00140 00144 template<class _Tp> 00145 inline bool compareByRel( Rel op, const _Tp & lhs, const _Tp & rhs ) 00146 { return compareByRel( op, lhs, rhs, Compare<_Tp>() ); } 00147 00149 00151 00158 template<class _Tp, class _Compare = Compare<_Tp> > 00159 struct CompareBy : public std::binary_function<_Tp,_Tp,bool> 00160 { 00161 CompareBy( Rel op_r ) 00162 : _op( op_r ) 00163 {} 00164 00165 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00166 { return compareByRel( _op, lhs, rhs, _Compare() ); } 00167 00168 Rel _op; 00169 }; 00170 00171 template<class _Tp, class _Compare = Compare<_Tp> > 00172 struct CompareByEQ : public std::binary_function<_Tp,_Tp,bool> 00173 { 00174 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00175 { return compareByRel( Rel::EQ, lhs, rhs, _Compare() ); } 00176 }; 00177 00178 template<class _Tp, class _Compare = Compare<_Tp> > 00179 struct CompareByNE : public std::binary_function<_Tp,_Tp,bool> 00180 { 00181 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00182 { return compareByRel( Rel::NE, lhs, rhs, _Compare() ); } 00183 }; 00184 00185 template<class _Tp, class _Compare = Compare<_Tp> > 00186 struct CompareByLT : public std::binary_function<_Tp,_Tp,bool> 00187 { 00188 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00189 { return compareByRel( Rel::LT, lhs, rhs, _Compare() ); } 00190 }; 00191 00192 template<class _Tp, class _Compare = Compare<_Tp> > 00193 struct CompareByLE : public std::binary_function<_Tp,_Tp,bool> 00194 { 00195 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00196 { return compareByRel( Rel::LE, lhs, rhs, _Compare() ); } 00197 }; 00198 00199 template<class _Tp, class _Compare = Compare<_Tp> > 00200 struct CompareByGT : public std::binary_function<_Tp,_Tp,bool> 00201 { 00202 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00203 { return compareByRel( Rel::GT, lhs, rhs, _Compare() ); } 00204 }; 00205 00206 template<class _Tp, class _Compare = Compare<_Tp> > 00207 struct CompareByGE : public std::binary_function<_Tp,_Tp,bool> 00208 { 00209 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00210 { return compareByRel( Rel::GE, lhs, rhs, _Compare() ); } 00211 }; 00212 00213 template<class _Tp, class _Compare = Compare<_Tp> > 00214 struct CompareByANY : public std::binary_function<_Tp,_Tp,bool> 00215 { 00216 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00217 { return compareByRel( Rel::ANY, lhs, rhs, _Compare() ); } 00218 }; 00219 00220 template<class _Tp, class _Compare = Compare<_Tp> > 00221 struct CompareByNONE : public std::binary_function<_Tp,_Tp,bool> 00222 { 00223 bool operator()( const _Tp & lhs, const _Tp & rhs ) const 00224 { return compareByRel( Rel::NONE, lhs, rhs, _Compare() ); } 00225 }; 00226 00228 00230 00231 } // namespace zypp 00233 #endif // ZYPP_RELCOMPARE_H