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 * For most (*Begin,*End) iterator-pairs there's also an \ref Iterable
47 * provided, so you can use then in range-based for loops:
50 * for_( it, pool.filterBegin(myfilter), pool.filterEnd(myfilter) )
54 * for ( const PoolItem & pi : pool.filter(myfilter) )
58 * \include n_ResPool_nomorenameiter
62 friend std::ostream & operator<<( std::ostream & str, const ResPool & obj );
66 typedef PoolItem value_type;
67 typedef pool::PoolTraits::size_type size_type;
68 typedef pool::PoolTraits::const_iterator const_iterator;
69 typedef pool::PoolTraits::repository_iterator repository_iterator;
72 /** Singleton ctor. */
73 static ResPool instance();
76 ResPoolProxy proxy() const;
79 Resolver & resolver() const;
82 /** The pools serial number. Changing whenever the
83 * whenever the content changes. (Resolvables or
86 const SerialNumber & serial() const;
92 size_type size() const;
94 /** \name Iterate over all PoolItems (all kinds). */
97 const_iterator begin() const
98 { return make_filter_begin( pool::ByPoolItem(), store() ); }
100 const_iterator end() const
101 { return make_filter_end( pool::ByPoolItem(), store() ); }
105 /** Return the corresponding \ref PoolItem.
106 * Pool and sat pool should be in sync. Returns an empty
107 * \ref PoolItem if there is no corresponding \ref PoolItem.
108 * \see \ref PoolItem::satSolvable.
110 PoolItem find( const sat::Solvable & slv_r ) const;
112 PoolItem find( const ResObject::constPtr & resolvable_r ) const
113 { return( resolvable_r ? find( resolvable_r->satSolvable() ) : PoolItem() ); }
116 /** \name Iterate over all PoolItems matching a \c TFilter. */
118 template<class TFilter>
119 filter_iterator<TFilter,const_iterator> filterBegin( const TFilter & filter_r ) const
120 { return make_filter_begin( filter_r, *this ); }
122 template<class TFilter>
123 filter_iterator<TFilter,const_iterator> filterEnd( const TFilter & filter_r ) const
124 { return make_filter_end( filter_r, *this ); }
126 template<class TFilter>
127 Iterable<filter_iterator<TFilter,const_iterator> > filter( const TFilter & filter_r ) const
128 { return makeIterable( filterBegin( filter_r ), filterEnd( filter_r ) ); }
131 /** \name Iterate over all PoolItems by status.
133 * Simply pass the \ref ResStatus predicate you want to use as filter:
135 * // iterate over all orphaned items:
136 * for_( it, pool.byStatusBegin(&ResStatus::isOrphaned), pool.byStatusEnd(&ResStatus::isOrphaned) )
140 * Or use \ref filter::ByStatus in more complex queries:
142 * // iterate over all (orphaned and recommended) items:
143 * functor::Chain<filter::ByStatus,filter::ByStatus> myfilter( filter::ByStatus(&ResStatus::isOrphaned),
144 * filter::ByStatus(&ResStatus::isRecommended) );
145 * for_( it, pool.filterBegin(myfilter), pool.filterEnd(myfilter) )
150 filter_iterator<filter::ByStatus,const_iterator> byStatusBegin( const filter::ByStatus & filter_r ) const
151 { return make_filter_begin( filter_r, *this ); }
153 filter_iterator<filter::ByStatus,const_iterator> byStatusEnd( const filter::ByStatus & filter_r ) const
154 { return make_filter_end( filter_r, *this ); }
156 Iterable<filter_iterator<filter::ByStatus,const_iterator> > byStatus( const filter::ByStatus & filter_r ) const
157 { return makeIterable( byStatusBegin( filter_r ), byStatusEnd( filter_r ) ); }
161 /** \name Iterate over all PoolItems of a certain name and kind. */
163 typedef pool::ByIdent ByIdent;
164 typedef pool::PoolTraits::byIdent_iterator byIdent_iterator;
166 byIdent_iterator byIdentBegin( const ByIdent & ident_r ) const
168 return make_transform_iterator( id2item().equal_range( ident_r.get() ).first,
169 pool::PoolTraits::Id2ItemValueSelector() );
172 byIdent_iterator byIdentBegin( ResKind kind_r, IdString name_r ) const
173 { return byIdentBegin( ByIdent(kind_r,name_r) ); }
175 byIdent_iterator byIdentBegin( ResKind kind_r, const C_Str & name_r ) const
176 { return byIdentBegin( ByIdent(kind_r,name_r) ); }
179 byIdent_iterator byIdentBegin( IdString name_r ) const
180 { return byIdentBegin( ByIdent(ResTraits<TRes>::kind,name_r) ); }
183 byIdent_iterator byIdentBegin( const C_Str & name_r ) const
184 { return byIdentBegin( ByIdent(ResTraits<TRes>::kind,name_r) ); }
186 /** Derive name and kind from \ref PoolItem. */
187 byIdent_iterator byIdentBegin( const PoolItem & pi_r ) const
188 { return byIdentBegin( ByIdent(pi_r.satSolvable()) ); }
189 /** Derive name and kind from \ref sat::Solvable. */
190 byIdent_iterator byIdentBegin( sat::Solvable slv_r ) const
191 { return byIdentBegin( ByIdent(slv_r) ); }
192 /** Takes a \ref sat::Solvable::ident string. */
193 byIdent_iterator byIdentBegin( IdString ident_r ) const
194 { return byIdentBegin( ByIdent(ident_r) ); }
197 byIdent_iterator byIdentEnd( const ByIdent & ident_r ) const
199 return make_transform_iterator( id2item().equal_range( ident_r.get() ).second,
200 pool::PoolTraits::Id2ItemValueSelector() );
203 byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
204 { return byIdentEnd( ByIdent(kind_r,name_r) ); }
206 byIdent_iterator byIdentEnd( ResKind kind_r, const C_Str & name_r ) const
207 { return byIdentEnd( ByIdent(kind_r,name_r) ); }
210 byIdent_iterator byIdentEnd( IdString name_r ) const
211 { return byIdentEnd( ByIdent(ResTraits<TRes>::kind,name_r) ); }
214 byIdent_iterator byIdentEnd( const C_Str & name_r ) const
215 { return byIdentEnd( ByIdent(ResTraits<TRes>::kind,name_r) ); }
217 /** Derive name and kind from \ref PoolItem. */
218 byIdent_iterator byIdentEnd( const PoolItem & pi_r ) const
219 { return byIdentEnd( ByIdent(pi_r.satSolvable()) ); }
220 /** Derive name and kind from \ref sat::Solvable. */
221 byIdent_iterator byIdentEnd( sat::Solvable slv_r ) const
222 { return byIdentEnd( ByIdent(slv_r) ); }
223 /** Takes a \ref sat::Solvable::ident string. */
224 byIdent_iterator byIdentEnd( IdString ident_r ) const
225 { return byIdentEnd( ByIdent(ident_r) ); }
228 Iterable<byIdent_iterator> byIdent( const ByIdent & ident_r ) const
229 { return makeIterable( byIdentBegin( ident_r ), byIdentEnd( ident_r ) ); }
231 Iterable<byIdent_iterator> byIdent( ResKind kind_r, IdString name_r ) const
232 { return makeIterable( byIdentBegin( kind_r, name_r ), byIdentEnd( kind_r, name_r ) ); }
234 Iterable<byIdent_iterator> byIdent( ResKind kind_r, const C_Str & name_r ) const
235 { return makeIterable( byIdentBegin( kind_r, name_r ), byIdentEnd( kind_r, name_r ) ); }
238 Iterable<byIdent_iterator> byIdent( IdString name_r ) const
239 { return makeIterable( byIdentBegin<TRes>( name_r ), byIdentEnd<TRes>( name_r ) ); }
242 Iterable<byIdent_iterator> byIdent( const C_Str & name_r ) const
243 { return makeIterable( byIdentBegin<TRes>( name_r ), byIdentEnd<TRes>( name_r ) ); }
245 Iterable<byIdent_iterator> byIdent( const PoolItem & pi_r ) const
246 { return makeIterable( byIdentBegin( pi_r ), byIdentEnd( pi_r ) ); }
248 Iterable<byIdent_iterator> byIdent(sat::Solvable slv_r ) const
249 { return makeIterable( byIdentBegin( slv_r ), byIdentEnd( slv_r ) ); }
251 Iterable<byIdent_iterator> byIdent( IdString ident_r ) const
252 { return makeIterable( byIdentBegin( ident_r ), byIdentEnd( ident_r ) ); }
256 /** \name Iterate over all ResObjects of a certain kind. */
258 typedef filter::ByKind ByKind;
259 typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
261 byKind_iterator byKindBegin( const ResKind & kind_r ) const
262 { return make_filter_begin( ByKind(kind_r), *this ); }
265 byKind_iterator byKindBegin() const
266 { return make_filter_begin( resfilter::byKind<TRes>(), *this ); }
268 byKind_iterator byKindEnd( const ResKind & kind_r ) const
269 { return make_filter_end( ByKind(kind_r), *this ); }
272 byKind_iterator byKindEnd() const
273 { return make_filter_end( resfilter::byKind<TRes>(), *this ); }
275 Iterable<byKind_iterator> byKind( const ResKind & kind_r ) const
276 { return makeIterable( byKindBegin( kind_r ), byKindEnd( kind_r ) ); }
279 Iterable<byKind_iterator> byKind() const
280 { return makeIterable( byKindBegin<TRes>(), byKindEnd<TRes>() ); }
284 /** \name Iterate over all ResObjects with a certain name (all kinds). */
286 typedef zypp::resfilter::ByName ByName;
287 typedef filter_iterator<ByName,const_iterator> byName_iterator;
289 byName_iterator byNameBegin( const std::string & name_r ) const
290 { return make_filter_begin( ByName(name_r), *this ); }
292 byName_iterator byNameEnd( const std::string & name_r ) const
293 { return make_filter_end( ByName(name_r), *this ); }
295 Iterable<byName_iterator> byName( const std::string & name_r ) const
296 { return makeIterable( byNameBegin( name_r ), byNameEnd( name_r ) ); }
300 /** \name Special iterators. */
305 /** \name Iterate over all Repositories that contribute ResObjects.
308 size_type knownRepositoriesSize() const;
310 repository_iterator knownRepositoriesBegin() const;
312 repository_iterator knownRepositoriesEnd() const;
314 /** Find a \ref Repository named \c alias_r.
315 * Returns \ref Repository::noRepository if there is no such \ref Repository.
317 Repository reposFind( const std::string & alias_r ) const;
319 Iterable<repository_iterator> knownRepositories() const
320 { return makeIterable( knownRepositoriesBegin(), knownRepositoriesEnd() ); }
324 /** \name Handle locale support.
326 * A \ref filter::ByLocaleSupport is provided to iterate over
327 * all items supporting a specific locale.
329 * \see \ref sat::LocaleSupport for a more convenient interface.
332 * ResPool pool( ResPool::instance() );
334 * filter::ByLocaleSupport f( Locale("de") );
335 * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
337 * MIL << *it << endl; // supporting "de"
340 * f = filter::ByLocaleSupport( pool.getRequestedLocales() );
341 * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
343 * MIL << *it << endl; // supporting any requested locale
348 /** Set the requested locales.
349 * Languages to be supported by the system, e.g. language specific
350 * packages to be installed.
352 void setRequestedLocales( const LocaleSet & locales_r );
354 /** Add one \ref Locale to the set of requested locales.
355 * Return \c true if \c locale_r was newly added to the set.
357 bool addRequestedLocale( const Locale & locale_r );
359 /** Erase one \ref Locale from the set of requested locales.
360 * Return \c false if \c locale_r was not found in the set.
362 bool eraseRequestedLocale( const Locale & locale_r );
364 /** Return the requested locales.
365 * \see \ref setRequestedLocales
367 const LocaleSet & getRequestedLocales() const;
369 /** Whether this \ref Locale is in the set of requested locales. */
370 bool isRequestedLocale( const Locale & locale_r ) const;
372 /** Get the set of available locales.
373 * This is computed from the package data so it actually
374 * represents all locales packages claim to support.
376 const LocaleSet & getAvailableLocales() const;
378 /** Whether this \ref Locale is in the set of available locales. */
379 bool isAvailableLocale( const Locale & locale_r ) const;
383 /** \name Handle hard locks (e.g set from /etc/zypp/locks).
385 * As this kind of lock is query based, it's quite expensive.
387 * These queries are re-evaluated when adding new repos to the pool.
390 typedef pool::PoolTraits::HardLockQueries HardLockQueries;
391 typedef pool::PoolTraits::hardLockQueries_iterator hardLockQueries_iterator;
393 bool hardLockQueriesEmpty() const;
394 size_type hardLockQueriesSize() const;
395 hardLockQueries_iterator hardLockQueriesBegin() const;
396 hardLockQueries_iterator hardLockQueriesEnd() const;
398 Iterable<hardLockQueries_iterator> hardLockQueries() const
399 { return makeIterable( hardLockQueriesBegin(), hardLockQueriesEnd() ); }
401 /** Set a new set of queries.
402 * The hard-locks of existing PoolItems are adjusted according
403 * to the queries. (usually called on target load)
405 void setHardLockQueries( const HardLockQueries & newLocks_r );
407 /** Suggest a new set of queries based on the current selection.
408 * (usually remembered on commit).
410 void getHardLockQueries( HardLockQueries & activeLocks_r );
414 const pool::PoolTraits::ItemContainerT & store() const;
415 const pool::PoolTraits::Id2ItemT & id2item() const;
419 ResPool( pool::PoolTraits::Impl_Ptr impl_r );
420 /** Access to implementation. */
421 RW_pointer<pool::PoolTraits::Impl> _pimpl;
423 ///////////////////////////////////////////////////////////////////
425 /** \relates ResPool Stream output */
426 std::ostream & operator<<( std::ostream & str, const ResPool & obj );
428 /////////////////////////////////////////////////////////////////
430 ///////////////////////////////////////////////////////////////////
432 #include "zypp/ResPoolProxy.h"
434 #endif // ZYPP_RESPOOL_H