1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResPool.h
12 #ifndef ZYPP_RESPOOL_H
13 #define ZYPP_RESPOOL_H
17 #include "zypp/APIConfig.h"
18 #include "zypp/base/Iterator.h"
20 #include "zypp/pool/PoolTraits.h"
21 #include "zypp/PoolItem.h"
22 #include "zypp/Filter.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : ResPool
36 /** Global ResObject pool.
38 * Explicitly shared singleton.
40 * \note Filter iterators provided by ResPool are intended to
41 * operate on internal index tables for faster access. If the
42 * the index is not yet implemented, they are realized as
43 * an ordinary filter iterator. Do not provide filter iterators
44 * here, if there is no index table for it.
46 * \include n_ResPool_nomorenameiter
50 friend std::ostream & operator<<( std::ostream & str, const ResPool & obj );
54 typedef PoolItem value_type;
55 typedef pool::PoolTraits::size_type size_type;
56 typedef pool::PoolTraits::const_iterator const_iterator;
57 typedef pool::PoolTraits::repository_iterator repository_iterator;
60 /** Singleton ctor. */
61 static ResPool instance();
64 ResPoolProxy proxy() const;
67 Resolver & resolver() const;
70 /** The pools serial number. Changing whenever the
71 * whenever the content changes. (Resolvables or
74 const SerialNumber & serial() const;
80 size_type size() const;
82 /** \name Iterate over all PoolItems (all kinds). */
85 const_iterator begin() const
86 { return make_filter_begin( pool::ByPoolItem(), store() ); }
88 const_iterator end() const
89 { return make_filter_end( pool::ByPoolItem(), store() ); }
93 /** Return the corresponding \ref PoolItem.
94 * Pool and sat pool should be in sync. Returns an empty
95 * \ref PoolItem if there is no corresponding \ref PoolItem.
96 * \see \ref PoolItem::satSolvable.
98 PoolItem find( const sat::Solvable & slv_r ) const;
100 PoolItem find( const ResObject::constPtr & resolvable_r ) const
101 { return( resolvable_r ? find( resolvable_r->satSolvable() ) : PoolItem() ); }
104 /** \name Iterate over all PoolItems matching a \c _Filter. */
106 template<class _Filter>
107 filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
108 { return make_filter_begin( filter_r, *this ); }
110 template<class _Filter>
111 filter_iterator<_Filter,const_iterator> filterEnd( const _Filter & filter_r ) const
112 { return make_filter_end( filter_r, *this ); }
115 /** \name Iterate over all PoolItems by status.
117 * Simply pass the \ref ResStatus predicate you want to use as filter:
119 * // iterate over all orphaned items:
120 * for_( it, pool.byStatusBegin(&ResStatus::isOrphaned), pool.byStatusEnd(&ResStatus::isOrphaned) )
124 * Or use \ref filter::ByStatus in more complex queries:
126 * // iterate over all (orphaned and recommended) items:
127 * functor::Chain<filter::ByStatus,filter::ByStatus> myfilter( filter::ByStatus(&ResStatus::isOrphaned),
128 * filter::ByStatus(&ResStatus::isRecommended) );
129 * for_( it, pool.filterBegin(myfilter), pool.filterEnd(myfilter) )
134 filter_iterator<filter::ByStatus,const_iterator> byStatusBegin( const filter::ByStatus & filter_r ) const
135 { return make_filter_begin( filter_r, *this ); }
137 filter_iterator<filter::ByStatus,const_iterator> byStatusEnd( const filter::ByStatus & filter_r ) const
138 { return make_filter_end( filter_r, *this ); }
142 /** \name Iterate over all PoolItems of a certain name and kind. */
144 typedef pool::ByIdent ByIdent;
145 typedef pool::PoolTraits::byIdent_iterator byIdent_iterator;
147 byIdent_iterator byIdentBegin( const ByIdent & ident_r ) const
149 return make_transform_iterator( id2item().equal_range( ident_r.get() ).first,
150 pool::PoolTraits::Id2ItemValueSelector() );
153 byIdent_iterator byIdentBegin( ResKind kind_r, IdString name_r ) const
154 { return byIdentBegin( ByIdent(kind_r,name_r) ); }
156 byIdent_iterator byIdentBegin( ResKind kind_r, const C_Str & name_r ) const
157 { return byIdentBegin( ByIdent(kind_r,name_r) ); }
160 byIdent_iterator byIdentBegin( IdString name_r ) const
161 { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
164 byIdent_iterator byIdentBegin( const C_Str & name_r ) const
165 { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
167 /** Derive name and kind from \ref PoolItem. */
168 byIdent_iterator byIdentBegin( const PoolItem & pi_r ) const
169 { return byIdentBegin( ByIdent(pi_r.satSolvable()) ); }
170 /** Derive name and kind from \ref sat::Solvable. */
171 byIdent_iterator byIdentBegin( sat::Solvable slv_r ) const
172 { return byIdentBegin( ByIdent(slv_r) ); }
173 /** Takes a \ref sat::Solvable::ident string. */
174 byIdent_iterator byIdentBegin( IdString ident_r ) const
175 { return byIdentBegin( ByIdent(ident_r) ); }
178 byIdent_iterator byIdentEnd( const ByIdent & ident_r ) const
180 return make_transform_iterator( id2item().equal_range( ident_r.get() ).second,
181 pool::PoolTraits::Id2ItemValueSelector() );
184 byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
185 { return byIdentEnd( ByIdent(kind_r,name_r) ); }
187 byIdent_iterator byIdentEnd( ResKind kind_r, const C_Str & name_r ) const
188 { return byIdentEnd( ByIdent(kind_r,name_r) ); }
191 byIdent_iterator byIdentEnd( IdString name_r ) const
192 { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
195 byIdent_iterator byIdentEnd( const C_Str & name_r ) const
196 { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
198 /** Derive name and kind from \ref PoolItem. */
199 byIdent_iterator byIdentEnd( const PoolItem & pi_r ) const
200 { return byIdentEnd( ByIdent(pi_r.satSolvable()) ); }
201 /** Derive name and kind from \ref sat::Solvable. */
202 byIdent_iterator byIdentEnd( sat::Solvable slv_r ) const
203 { return byIdentEnd( ByIdent(slv_r) ); }
204 /** Takes a \ref sat::Solvable::ident string. */
205 byIdent_iterator byIdentEnd( IdString ident_r ) const
206 { return byIdentEnd( ByIdent(ident_r) ); }
210 /** \name Iterate over all ResObjects of a certain kind. */
212 typedef filter::ByKind ByKind;
213 typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
215 byKind_iterator byKindBegin( const ResKind & kind_r ) const
216 { return make_filter_begin( ByKind(kind_r), *this ); }
219 byKind_iterator byKindBegin() const
220 { return make_filter_begin( resfilter::byKind<_Res>(), *this ); }
222 byKind_iterator byKindEnd( const ResKind & kind_r ) const
223 { return make_filter_end( ByKind(kind_r), *this ); }
226 byKind_iterator byKindEnd() const
227 { return make_filter_end( resfilter::byKind<_Res>(), *this ); }
231 /** \name Iterate over all ResObjects with a certain name (all kinds). */
233 typedef zypp::resfilter::ByName ByName;
234 typedef filter_iterator<ByName,const_iterator> byName_iterator;
236 byName_iterator byNameBegin( const std::string & name_r ) const
237 { return make_filter_begin( ByName(name_r), *this ); }
239 byName_iterator byNameEnd( const std::string & name_r ) const
240 { return make_filter_end( ByName(name_r), *this ); }
244 /** \name Special iterators. */
249 /** \name Iterate over all Repositories that contribute ResObjects.
252 size_type knownRepositoriesSize() const;
254 repository_iterator knownRepositoriesBegin() const;
256 repository_iterator knownRepositoriesEnd() const;
258 /** Find a \ref Repository named \c alias_r.
259 * Returns \ref Repository::norepository if there is no such \ref Repository.
261 Repository reposFind( const std::string & alias_r ) const;
265 /** \name Handle locale support.
267 * A \ref filter::ByLocaleSupport is provided to iterate over
268 * all items supporting a specific locale.
270 * \see \ref sat::LocaleSupport for a more convenient interface.
273 * ResPool pool( ResPool::instance() );
275 * filter::ByLocaleSupport f( Locale("de") );
276 * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
278 * MIL << *it << endl; // supporting "de"
281 * f = filter::ByLocaleSupport( pool.getRequestedLocales() );
282 * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
284 * MIL << *it << endl; // supporting any requested locale
289 /** Set the requested locales.
290 * Languages to be supported by the system, e.g. language specific
291 * packages to be installed.
293 void setRequestedLocales( const LocaleSet & locales_r );
295 /** Add one \ref Locale to the set of requested locales.
296 * Return \c true if \c locale_r was newly added to the set.
298 bool addRequestedLocale( const Locale & locale_r );
300 /** Erase one \ref Locale from the set of requested locales.
301 * Return \c false if \c locale_r was not found in the set.
303 bool eraseRequestedLocale( const Locale & locale_r );
305 /** Return the requested locales.
306 * \see \ref setRequestedLocales
308 const LocaleSet & getRequestedLocales() const;
310 /** Whether this \ref Locale is in the set of requested locales. */
311 bool isRequestedLocale( const Locale & locale_r ) const;
313 /** Get the set of available locales.
314 * This is computed from the package data so it actually
315 * represents all locales packages claim to support.
317 const LocaleSet & getAvailableLocales() const;
319 /** Whether this \ref Locale is in the set of available locales. */
320 bool isAvailableLocale( const Locale & locale_r ) const;
324 /** \name Handle hard locks (e.g set from /etc/zypp/locks).
326 * As this kind of lock is query based, it's quite expensive.
328 * These queries are re-evaluated when adding new repos to the pool.
331 typedef pool::PoolTraits::HardLockQueries HardLockQueries;
332 typedef pool::PoolTraits::hardLockQueries_iterator hardLockQueries_iterator;
334 bool hardLockQueriesEmpty() const;
335 size_type hardLockQueriesSize() const;
336 hardLockQueries_iterator hardLockQueriesBegin() const;
337 hardLockQueries_iterator hardLockQueriesEnd() const;
339 /** Set a new set of queries.
340 * The hard-locks of existing PoolItems are adjusted according
341 * to the queries. (usually called on target load)
343 void setHardLockQueries( const HardLockQueries & newLocks_r );
345 /** Suggest a new set of queries based on the current selection.
346 * (usually remembered on commit).
348 void getHardLockQueries( HardLockQueries & activeLocks_r );
352 const pool::PoolTraits::ItemContainerT & store() const;
353 const pool::PoolTraits::Id2ItemT & id2item() const;
357 ResPool( pool::PoolTraits::Impl_Ptr impl_r );
358 /** Access to implementation. */
359 RW_pointer<pool::PoolTraits::Impl> _pimpl;
361 ///////////////////////////////////////////////////////////////////
363 /** \relates ResPool Stream output */
364 std::ostream & operator<<( std::ostream & str, const ResPool & obj );
366 /////////////////////////////////////////////////////////////////
368 ///////////////////////////////////////////////////////////////////
370 #include "zypp/ResPoolProxy.h"
372 #endif // ZYPP_RESPOOL_H