ResPoolProxy.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_RESPOOLPROXY_H
00013 #define ZYPP_RESPOOLPROXY_H
00014 
00015 #include <iosfwd>
00016 
00017 #include "zypp/base/PtrTypes.h"
00018 
00019 #include "zypp/ResPool.h"
00020 #include "zypp/ui/Selectable.h"
00021 #include "zypp/ui/SelFilters.h"
00022 
00024 namespace zypp
00025 { 
00026 
00028   //
00029   //    CLASS NAME : ResPoolProxy
00030   //
00034   class ResPoolProxy
00035   {
00036     friend std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj );
00037 
00038     typedef std::vector<ui::Selectable::Ptr>  SelectableKinds;
00039     typedef std::map<ResKind,SelectableKinds> SelectablePool;
00040 
00041   public:
00043     class Impl;
00044 
00045     typedef SelectableKinds::iterator       iterator;
00046     typedef SelectableKinds::const_iterator const_iterator;
00047     typedef SelectableKinds::size_type      size_type;
00048 
00049     typedef ResPool::repository_iterator    repository_iterator;
00050 
00051   public:
00052 
00060     ResPoolProxy();
00061 
00063     ~ResPoolProxy();
00064 
00065   public:
00068     ui::Selectable::Ptr lookup( const pool::ByIdent & ident_r ) const;
00069 
00070     ui::Selectable::Ptr lookup( IdString ident_r ) const
00071     { return lookup( pool::ByIdent( ident_r ) ); }
00072 
00073     ui::Selectable::Ptr lookup( ResKind kind_r, const std::string & name_r ) const
00074     { return lookup( pool::ByIdent( kind_r, name_r ) ); }
00075 
00076     ui::Selectable::Ptr lookup( const sat::Solvable & solv_r ) const
00077     { return lookup( pool::ByIdent( solv_r ) ); }
00078 
00079     ui::Selectable::Ptr lookup( const ResObject::constPtr & resolvable_r ) const
00080     { return resolvable_r ? lookup( resolvable_r->satSolvable() ) : ui::Selectable::Ptr(); }
00081 
00082     ui::Selectable::Ptr lookup( const PoolItem & pi_r ) const
00083     { return lookup( pi_r.satSolvable() ); }
00085 
00086   public:
00087 
00089     bool empty( const ResKind & kind_r ) const;
00090 
00091     template<class _Res>
00092       bool empty() const
00093       { return empty( ResTraits<_Res>::kind ); }
00094 
00096     size_type size( const ResKind & kind_r ) const;
00097 
00098     template<class _Res>
00099       size_type size() const
00100       { return size( ResTraits<_Res>::kind ); }
00101 
00104     const_iterator byKindBegin( const ResKind & kind_r ) const;
00105 
00106     template<class _Res>
00107       const_iterator byKindBegin() const
00108       { return byKindBegin( ResTraits<_Res>::kind ); }
00109 
00110 
00111     const_iterator byKindEnd( const ResKind & kind_r ) const;
00112 
00113     template<class _Res>
00114       const_iterator byKindEnd() const
00115       { return byKindEnd( ResTraits<_Res>::kind ); }
00117 
00118  public:
00122    size_type knownRepositoriesSize() const;
00123 
00124    repository_iterator knownRepositoriesBegin() const;
00125 
00126    repository_iterator knownRepositoriesEnd() const;
00128 
00129   public:
00133     bool hasInstalledObj( const ResKind & kind_r ) const
00134     {
00135       return(    make_begin<ui::selfilter::ByHasInstalledObj>( kind_r )
00136               != make_end<ui::selfilter::ByHasInstalledObj>( kind_r ) );
00137     }
00138 
00139     template<class _Res>
00140       bool hasInstalledObj() const
00141       { return hasInstalledObj( ResTraits<_Res>::kind ); }
00142 
00143   public:
00152     void saveState() const;
00153 
00154     void saveState( const ResKind & kind_r ) const;
00155 
00156     template<class _Res>
00157       void saveState() const
00158       { return saveState( ResTraits<_Res>::kind ); }
00159 
00160     void restoreState() const;
00161 
00162     void restoreState( const ResKind & kind_r ) const;
00163 
00164     template<class _Res>
00165       void restoreState() const
00166       { return restoreState( ResTraits<_Res>::kind ); }
00167 
00168     bool diffState() const;
00169 
00170     bool diffState( const ResKind & kind_r ) const;
00171 
00172     template<class _Res>
00173       bool diffState() const
00174       { return diffState( ResTraits<_Res>::kind ); }
00176 
00177   private:
00178     template<class _Filter>
00179       filter_iterator<_Filter,const_iterator>
00180       make_begin( _Filter filter_r, const ResKind & kind_r ) const
00181       {
00182         return make_filter_iterator( filter_r,
00183                                      byKindBegin(kind_r),
00184                                      byKindEnd(kind_r) );
00185       }
00186     template<class _Filter>
00187       filter_iterator<_Filter,const_iterator>
00188       make_begin( const ResKind & kind_r ) const
00189       {
00190         return make_begin( _Filter(), kind_r );
00191       }
00192 
00193 
00194     template<class _Filter>
00195       filter_iterator<_Filter,const_iterator>
00196       make_end( _Filter filter_r, const ResKind & kind_r ) const
00197       {
00198         return make_filter_iterator( filter_r,
00199                                      byKindEnd(kind_r),
00200                                      byKindEnd(kind_r) );
00201       }
00202     template<class _Filter>
00203       filter_iterator<_Filter,const_iterator>
00204       make_end( const ResKind & kind_r ) const
00205       {
00206         return make_end( _Filter(), kind_r );
00207       }
00208 
00209   private:
00210     friend class pool::PoolImpl;
00212     ResPoolProxy( ResPool pool_r, const pool::PoolImpl & poolImpl_r );
00214     RW_pointer<Impl> _pimpl;
00215   };
00217 
00219   std::ostream & operator<<( std::ostream & str, const ResPoolProxy & obj );
00220 
00222 } // namespace zypp
00224 #endif // ZYPP_RESPOOLPROXY_H

doxygen