00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_RESFILTERS_H
00013 #define ZYPP_RESFILTERS_H
00014
00015 #include "zypp/base/Functional.h"
00016 #include "zypp/Resolvable.h"
00017 #include "zypp/CapFilters.h"
00018
00019 #include "zypp/Source.h"
00020 #include "zypp/source/SourceImpl.h"
00021
00022 #include "zypp/PoolItem.h"
00023 #include "zypp/CapAndItem.h"
00024
00026 namespace zypp
00027 {
00028
00029 namespace resfilter
00030 {
00031
00143
00144
00145
00146
00148
00150 typedef std::unary_function<ResObject::constPtr, bool> ResObjectFilterFunctor;
00151
00153 struct ByKind : public ResObjectFilterFunctor
00154 {
00155 ByKind( const ResObject::Kind & kind_r )
00156 : _kind( kind_r )
00157 {}
00158
00159 bool operator()( ResObject::constPtr p ) const
00160 {
00161 return p->kind() == _kind;
00162 }
00163
00164 ResObject::Kind _kind;
00165 };
00166
00168 template<class _Res>
00169 inline ByKind byKind()
00170 { return ByKind( ResTraits<_Res>::kind ); }
00171
00173 struct ByName : public ResObjectFilterFunctor
00174 {
00175 ByName( const std::string & name_r )
00176 : _name( name_r )
00177 {}
00178
00179 bool operator()( ResObject::constPtr p ) const
00180 {
00181 return p->name() == _name;
00182 }
00183
00184 std::string _name;
00185 };
00186
00187
00189 struct BySource : public ResObjectFilterFunctor
00190 {
00191 BySource( Source_Ref source_r )
00192 : _source( source_r )
00193 {}
00194
00195 bool operator()( ResObject::constPtr p ) const
00196 {
00197 return p->source() == _source;
00198 }
00199
00200 Source_Ref _source;
00201 };
00202
00203
00216 template<class _Compare = CompareByEQ<Edition> >
00217 struct ByEdition : public ResObjectFilterFunctor
00218 {
00219 ByEdition( const Edition & edition_r,
00220 _Compare cmp_r )
00221 : _edition( edition_r )
00222 , _cmp( cmp_r )
00223 {}
00224
00225 bool operator()( ResObject::constPtr p ) const
00226 {
00227 return _cmp( p->edition(), _edition );
00228 }
00229
00230 Edition _edition;
00231 _Compare _cmp;
00232 };
00233
00235 template<class _Compare>
00236 ByEdition<_Compare> byEdition( const Edition & edition_r, _Compare cmp_r )
00237 { return ByEdition<_Compare>( edition_r, cmp_r ); }
00238
00240 template<class _Compare>
00241 ByEdition<_Compare> byEdition( const Edition & edition_r )
00242 { return byEdition( edition_r, _Compare() ); }
00243
00244
00257 template<class _Compare = CompareByEQ<Arch> >
00258 struct ByArch : public ResObjectFilterFunctor
00259 {
00260 ByArch( const Arch & arch_r,
00261 _Compare cmp_r )
00262 : _arch( arch_r )
00263 , _cmp( cmp_r )
00264 {}
00265
00266 bool operator()( ResObject::constPtr p ) const
00267 {
00268 return _cmp( p->arch(), _arch );
00269 }
00270
00271 Arch _arch;
00272 _Compare _cmp;
00273 };
00274
00276 template<class _Compare>
00277 ByArch<_Compare> byArch( const Arch & arch_r, _Compare cmp_r )
00278 { return ByArch<_Compare>( arch_r, cmp_r ); }
00279
00281 template<class _Compare>
00282 ByArch<_Compare> byArch( const Arch & arch_r )
00283 { return byArch( arch_r, _Compare() ); }
00284
00285
00287
00289
00290
00291
00293
00295 typedef std::unary_function<PoolItem, bool> PoolItemFilterFunctor;
00296
00298 struct ByInstalled : public PoolItemFilterFunctor
00299 {
00300 bool operator()( const PoolItem & p ) const
00301 {
00302 return p.status().isInstalled();
00303 }
00304
00305 };
00306
00308 struct ByUninstalled : public PoolItemFilterFunctor
00309 {
00310 bool operator()( const PoolItem & p ) const
00311 {
00312 return p.status().isUninstalled();
00313 }
00314 };
00315
00317 struct ByTransact : public PoolItemFilterFunctor
00318 {
00319 bool operator()( const PoolItem & p ) const
00320 {
00321 return p.status().transacts();
00322 }
00323 };
00324
00326 struct ByLock : public PoolItemFilterFunctor
00327 {
00328 bool operator()( const PoolItem & p ) const
00329 {
00330 return p.status().isLocked();
00331 }
00332 };
00333
00334
00336
00340 struct ByCapabilityIndex
00341 {
00342 bool operator()( const CapAndItem & cai ) const
00343 {
00344 return true;
00345 }
00346 };
00347
00348
00352 struct ByCapMatch
00353 {
00354 bool operator()( const CapAndItem & cai ) const
00355 {
00356 return cai.cap.matches( _cap ) == CapMatch::yes;
00357 }
00358 ByCapMatch( const Capability & cap_r )
00359 : _cap( cap_r )
00360 {}
00361 const Capability & _cap;
00362 };
00363
00364
00366 struct ByCaIUninstalled
00367 {
00368 bool operator()( const CapAndItem & cai ) const
00369 {
00370 return cai.item.status().isUninstalled();
00371 }
00372 };
00373
00375 struct ByCaIInstalled
00376 {
00377 bool operator()( const CapAndItem & cai ) const
00378 {
00379 return cai.item.status().isInstalled();
00380 }
00381 };
00382
00384 struct ByCaITransact
00385 {
00386 bool operator()( const CapAndItem & cai ) const
00387 {
00388 return cai.item.status().transacts();
00389 }
00390 };
00391
00393 struct ByCaINotTransact
00394 {
00395 bool operator()( const CapAndItem & cai ) const
00396 {
00397 return !(cai.item.status().transacts());
00398 }
00399 };
00400
00401
00403 struct ByCaIKind
00404 {
00405 ByCaIKind( const ResObject::Kind & kind_r )
00406 : _kind( kind_r )
00407 {}
00408
00409 bool operator()( const CapAndItem & cai ) const
00410 {
00411 return cai.item->kind() == _kind;
00412 }
00413
00414 ResObject::Kind _kind;
00415 };
00416
00418 template<class _Res>
00419 inline ByCaIKind byCaIKind()
00420 { return ByCaIKind( ResTraits<_Res>::kind ); }
00421
00423
00425
00426 }
00429 }
00431 #endif // ZYPP_RESFILTERS_H