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 
00022 namespace zypp
00023 { 
00024 
00026   //
00027   //    CLASS NAME : ResStore
00028   //
00031   class ResStore
00032   {
00033     friend std::ostream & operator<<( std::ostream & str, const ResStore & obj );
00034 
00035   public:
00037     class Impl;
00038 
00040     typedef ResObject                ResT;
00041 
00042   private:
00043     typedef std::set<ResT::Ptr>      StorageT;
00044 
00045   public:
00046 
00047     typedef StorageT::size_type      size_type;
00048     typedef StorageT::iterator       iterator;
00049     typedef StorageT::const_iterator const_iterator;
00050 
00051   public:
00053     ResStore();
00055     ~ResStore();
00056 
00057   public:
00059     iterator begin()
00060     { return store().begin(); }
00062     iterator end()
00063     { return store().end(); }
00065     const_iterator begin() const
00066     { return store().begin(); }
00068     const_iterator end() const
00069     { return store().end(); }
00070 
00072     bool empty() const
00073     { return store().empty(); }
00075     size_type size() const
00076     { return store().size(); }
00077 
00078     // insert/erase
00080     iterator insert( const ResT::Ptr & ptr_r )
00081     { return store().insert( ptr_r ).first; }
00083     template <class _InputIterator>
00084       void insert( _InputIterator first_r, _InputIterator last_r )
00085       { store().insert( first_r, last_r ); }
00087     size_type erase( const ResT::Ptr & ptr_r )
00088     { return store().erase( ptr_r ); }
00090     void erase( iterator first_r, iterator last_r )
00091     { store().erase( first_r, last_r ); }
00093     void clear()
00094     { store().clear(); }
00095 
00111     template <class _Function, class _Filter>
00112       int forEach( _Filter filter_r, _Function fnc_r ) const
00113       {
00114         int cnt = 0;
00115         for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
00116           {
00117             if ( filter_r( *it ) )
00118               {
00119                 ++cnt;
00120                 if ( ! fnc_r( *it ) )
00121                   return -cnt;
00122               }
00123           }
00124         return cnt;
00125       }
00126 
00127     template <class _Function>
00128       int forEach( _Function fnc_r ) const
00129       {
00130         int cnt = 0;
00131         for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
00132           {
00133             ++cnt;
00134             if ( ! fnc_r( *it ) )
00135               return -cnt;
00136           }
00137         return cnt;
00138       }
00139 
00140   private:
00142     StorageT _store;
00144     StorageT & store()
00145     { return _store; }
00147     const StorageT & store() const
00148     { return _store; }
00149 
00150   private:
00152     RW_pointer<Impl> _pimpl; // currently unsused
00153   };
00155 
00157   std::ostream & operator<<( std::ostream & str, const ResStore & obj );
00158 
00160 } // namespace zypp
00162 #endif // ZYPP_RESSTORE_H

Generated on Thu Jul 6 00:07:22 2006 for zypp by  doxygen 1.4.6