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 00048 typedef StorageT::size_type size_type; 00049 typedef StorageT::iterator iterator; 00050 typedef StorageT::const_iterator const_iterator; 00051 typedef boost::filter_iterator<resfilter::ResFilter, const_iterator> resfilter_const_iterator; 00052 00053 public: 00055 ResStore(); 00057 ~ResStore(); 00058 00059 public: 00061 iterator begin() 00062 { return store().begin(); } 00064 iterator end() 00065 { return store().end(); } 00067 const_iterator begin() const 00068 { return store().begin(); } 00070 const_iterator end() const 00071 { return store().end(); } 00072 00074 bool empty() const 00075 { return store().empty(); } 00077 size_type size() const 00078 { return store().size(); } 00079 00080 // insert/erase 00082 iterator insert( const ResT::Ptr & ptr_r ) 00083 { return store().insert( ptr_r ).first; } 00085 template <class _InputIterator> 00086 void insert( _InputIterator first_r, _InputIterator last_r ) 00087 { store().insert( first_r, last_r ); } 00089 size_type erase( const ResT::Ptr & ptr_r ) 00090 { return store().erase( ptr_r ); } 00092 void erase( iterator pos_r ) 00093 { store().erase( pos_r ); } 00095 void erase( iterator first_r, iterator last_r ) 00096 { store().erase( first_r, last_r ); } 00098 void erase( const Resolvable::Kind & kind_r ) 00099 { 00100 for ( iterator it = begin(); it != end(); ) 00101 { 00102 if ( (*it)->kind() == kind_r ) 00103 { 00104 store().erase( it++ ); // postfix! Incrementing before erase 00105 } 00106 else 00107 ++it; 00108 } 00109 } 00111 template<class _Res> 00112 void erase() 00113 { erase( ResTraits<_Res>::kind ); } 00115 void clear() 00116 { store().clear(); } 00117 00133 template <class _Function, class _Filter> 00134 int forEach( _Filter filter_r, _Function fnc_r ) const 00135 { 00136 int cnt = 0; 00137 for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it ) 00138 { 00139 if ( filter_r( *it ) ) 00140 { 00141 ++cnt; 00142 if ( ! fnc_r( *it ) ) 00143 return -cnt; 00144 } 00145 } 00146 return cnt; 00147 } 00148 00149 template <class _Function> 00150 int forEach( _Function fnc_r ) const 00151 { 00152 int cnt = 0; 00153 for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it ) 00154 { 00155 ++cnt; 00156 if ( ! fnc_r( *it ) ) 00157 return -cnt; 00158 } 00159 return cnt; 00160 } 00161 00162 private: 00164 StorageT _store; 00166 StorageT & store() 00167 { return _store; } 00169 const StorageT & store() const 00170 { return _store; } 00171 00172 private: 00174 RW_pointer<Impl> _pimpl; // currently unsused 00175 }; 00177 00179 std::ostream & operator<<( std::ostream & str, const ResStore & obj ); 00180 00182 } // namespace zypp 00184 #endif // ZYPP_RESSTORE_H
1.5.0