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