1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResStore.h
12 #ifndef ZYPP_RESSTORE_H
13 #define ZYPP_RESSTORE_H
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/ResObject.h"
20 #include "zypp/ResFilters.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : ResStore
34 friend std::ostream & operator<<( std::ostream & str, const ResStore & obj );
40 /** Type of Resolvable provided by ResStore. */
41 typedef ResObject ResT;
44 typedef std::set<ResT::Ptr> StorageT;
48 typedef StorageT::size_type size_type;
49 typedef StorageT::iterator iterator;
50 typedef StorageT::const_iterator const_iterator;
51 typedef boost::filter_iterator<resfilter::ResFilter, const_iterator> resfilter_const_iterator;
62 { return store().begin(); }
65 { return store().end(); }
67 const_iterator begin() const
68 { return store().begin(); }
70 const_iterator end() const
71 { return store().end(); }
75 { return store().empty(); }
77 size_type size() const
78 { return store().size(); }
82 iterator insert( const ResT::Ptr & ptr_r )
83 { return store().insert( ptr_r ).first; }
85 template <class _InputIterator>
86 void insert( _InputIterator first_r, _InputIterator last_r )
87 { store().insert( first_r, last_r ); }
89 size_type erase( const ResT::Ptr & ptr_r )
90 { return store().erase( ptr_r ); }
92 void erase( iterator pos_r )
93 { store().erase( pos_r ); }
95 void erase( iterator first_r, iterator last_r )
96 { store().erase( first_r, last_r ); }
98 void erase( const Resolvable::Kind & kind_r )
100 for ( iterator it = begin(); it != end(); )
102 if ( (*it)->kind() == kind_r )
104 store().erase( it++ ); // postfix! Incrementing before erase
110 /** Erase by Kind. */
113 { erase( ResTraits<_Res>::kind ); }
119 * Both, \a filter_r and \a fnc_r are expected to be
120 * functions or functors taking a <tt>ResT::Ptr</tt>
121 * as argument and return a \c bool.
123 * forEach iterates over all ResTs and invokes \a fnc_r,
124 * iff \a filter_r returned \c true. If \a fnc_r returnes
125 * \c false the loop is aborted.
127 * forEach returns the number of \a fnc_r invocations. Positive
128 * if the loop succeeded. Negative if some call to \a fnc_r
131 * \see \ref RESFILTERS for a collection of predefined filters.
133 template <class _Function, class _Filter>
134 int forEach( _Filter filter_r, _Function fnc_r ) const
137 for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
139 if ( filter_r( *it ) )
142 if ( ! fnc_r( *it ) )
149 template <class _Function>
150 int forEach( _Function fnc_r ) const
153 for ( ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it )
156 if ( ! fnc_r( *it ) )
169 const StorageT & store() const
173 /** Pointer to implementation */
174 RW_pointer<Impl> _pimpl; // currently unsused
176 ///////////////////////////////////////////////////////////////////
178 /** \relates ResStore Stream output */
179 std::ostream & operator<<( std::ostream & str, const ResStore & obj );
181 /////////////////////////////////////////////////////////////////
183 ///////////////////////////////////////////////////////////////////
184 #endif // ZYPP_RESSTORE_H