ResStore.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_RESSTORE_H
00013 #define ZYPP_RESSTORE_H
00014 
00015 #include <iosfwd>
00016 #include <set>
00017 
00018 #include "zypp/base/PtrTypes.h"
00019 #include "zypp/ResObject.h"
00020 #include "zypp/ResFilters.h"
00021 
00023 namespace zypp
00024 { 
00025 
00027   //
00028   //    CLASS NAME : ResStore
00029   //
00032   class ResStore
00033   {
00034     friend std::ostream & operator<<( std::ostream & str, const ResStore & obj );
00035 
00036   public:
00038     class Impl;
00039 
00041     typedef ResObject                ResT;
00042     
00043   private:
00044     typedef std::set<ResT::Ptr>      StorageT;
00045     
00046   public:
00047     typedef StorageT::value_type     value_type;
00048     typedef StorageT::const_reference const_reference;
00049     typedef StorageT::size_type      size_type;
00050     typedef StorageT::iterator       iterator;
00051     typedef StorageT::const_iterator const_iterator;
00052     typedef boost::filter_iterator<resfilter::ResFilter, const_iterator>  resfilter_const_iterator;
00053 
00054   public:
00056     ResStore();
00058     ~ResStore();
00059 
00060   public:
00062     iterator begin()
00063     { return store().begin(); }
00065     iterator end()
00066     { return store().end(); }
00068     const_iterator begin() const
00069     { return store().begin(); }
00071     const_iterator end() const
00072     { return store().end(); }
00073 
00075     bool empty() const
00076     { return store().empty(); }
00078     size_type size() const
00079     { return store().size(); }
00080 
00081     // insert/erase
00083     iterator insert( const ResT::Ptr & ptr_r )
00084     { return store().insert( ptr_r ).first; }
00085     
00087     iterator insert( iterator position, const value_type &v )
00088     { return store().insert( position, v ); }
00089     
00091     template <class _InputIterator>
00092       void insert( _InputIterator first_r, _InputIterator last_r )
00093       { store().insert( first_r, last_r ); }
00095     size_type erase( const ResT::Ptr & ptr_r )
00096     { return store().erase( ptr_r ); }
00098     void erase( iterator pos_r )
00099     { store().erase( pos_r ); }
00101     void erase( iterator first_r, iterator last_r )
00102     { store().erase( first_r, last_r ); }
00104     void erase( const Resolvable::Kind & kind_r )
00105     {
00106       for ( iterator it = begin(); it != end();  )
00107         {
00108           if ( (*it)->kind() == kind_r )
00109             {
00110               store().erase( it++ ); // postfix! Incrementing before erase
00111             }
00112           else
00113             ++it;
00114         }
00115     }
00117     template<class _Res>
00118       void erase()
00119       { erase( ResTraits<_Res>::kind ); }
00121     void clear()
00122     { store().clear(); }
00123 
00139     template <class _Function, class _Filter>
00140       int forEach( _Filter filter_r, _Function fnc_r ) const
00141       {
00142         int cnt = 0;
00143         for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
00144           {
00145             if ( filter_r( *it ) )
00146               {
00147                 ++cnt;
00148                 if ( ! fnc_r( *it ) )
00149                   return -cnt;
00150               }
00151           }
00152         return cnt;
00153       }
00154 
00155     template <class _Function>
00156       int forEach( _Function fnc_r ) const
00157       {
00158         int cnt = 0;
00159         for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
00160           {
00161             ++cnt;
00162             if ( ! fnc_r( *it ) )
00163               return -cnt;
00164           }
00165         return cnt;
00166       }
00167 
00168   private:
00170     StorageT _store;
00172     StorageT & store()
00173     { return _store; }
00175     const StorageT & store() const
00176     { return _store; }
00177 
00178   private:
00180     RW_pointer<Impl> _pimpl; // currently unsused
00181   };
00183 
00185   std::ostream & operator<<( std::ostream & str, const ResStore & obj );
00186 
00188 } // namespace zypp
00190 #endif // ZYPP_RESSTORE_H

Generated on Tue Sep 25 19:23:06 2007 for libzypp by  doxygen 1.5.3