1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResPool.h
12 #ifndef ZYPP_RESPOOL_H
13 #define ZYPP_RESPOOL_H
17 #include "zypp/base/Deprecated.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 { /////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////
33 // CLASS NAME : ResPool
35 /** Global ResObject pool.
37 * Explicitly shared singleton.
39 * \note Filter iterators provided by ResPool are intended to
40 * operate on internal index tables for faster access. If the
41 * the index is not yet implemented, they are realized as
42 * an ordinary filter iterator. Do not provide filter iterators
43 * here, if there is no index table for it.
45 * \include n_ResPool_nomorenameiter
49 friend std::ostream & operator<<( std::ostream & str, const ResPool & obj );
53 typedef PoolItem value_type;
54 typedef pool::PoolTraits::size_type size_type;
55 typedef pool::PoolTraits::const_iterator const_iterator;
56 typedef pool::PoolTraits::repository_iterator repository_iterator;
59 /** Singleton ctor. */
60 static ResPool instance();
63 ResPoolProxy proxy() const;
66 /** The pools serial number. Changing whenever the
67 * whenever the content changes. (Resolvables or
70 const SerialNumber & serial() const;
76 size_type size() const;
78 /** \name Iterate over all PoolItems (all kinds). */
81 const_iterator begin() const
82 { return make_filter_begin( pool::ByPoolItem(), store() ); }
84 const_iterator end() const
85 { return make_filter_end( pool::ByPoolItem(), store() ); }
89 /** Return the corresponding \ref PoolItem.
90 * Pool and sat pool should be in sync. Returns an empty
91 * \ref PoolItem if there is no corresponding \ref PoolItem.
92 * \see \ref PoolItem::satSolvable.
94 PoolItem find( const sat::Solvable & slv_r ) const;
96 PoolItem find( const ResObject::constPtr & resolvable_r ) const
97 { return( resolvable_r ? find( resolvable_r->satSolvable() ) : PoolItem() ); }
100 /** \name Iterate over all PoolItems matching a \c _Filter. */
102 template<class _Filter>
103 filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
104 { return make_filter_begin( filter_r, *this ); }
106 template<class _Filter>
107 filter_iterator<_Filter,const_iterator> filterEnd( const _Filter & filter_r ) const
108 { return make_filter_end( filter_r, *this ); }
112 /** \name Iterate over all PoolItems of a certain name and kind. */
114 typedef pool::ByIdent ByIdent;
115 typedef pool::PoolTraits::byIdent_iterator byIdent_iterator;
117 byIdent_iterator byIdentBegin( const ByIdent & ident_r ) const
119 return make_transform_iterator( id2item().equal_range( ident_r.get() ).first,
120 pool::PoolTraits::Id2ItemValueSelector() );
123 byIdent_iterator byIdentBegin( ResKind kind_r, IdString name_r ) const
124 { return byIdentBegin( ByIdent(kind_r,name_r) ); }
126 byIdent_iterator byIdentBegin( ResKind kind_r, const C_Str & name_r ) const
127 { return byIdentBegin( ByIdent(kind_r,name_r) ); }
130 byIdent_iterator byIdentBegin( IdString name_r ) const
131 { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
134 byIdent_iterator byIdentBegin( const C_Str & name_r ) const
135 { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
137 /** Derive name and kind from \ref PoolItem. */
138 byIdent_iterator byIdentBegin( const PoolItem & pi_r ) const
139 { return byIdentBegin( ByIdent(pi_r.satSolvable()) ); }
140 /** Derive name and kind from \ref sat::Solvable. */
141 byIdent_iterator byIdentBegin( sat::Solvable slv_r ) const
142 { return byIdentBegin( ByIdent(slv_r) ); }
143 /** Takes a \ref sat::Solvable::ident string. */
144 byIdent_iterator byIdentBegin( IdString ident_r ) const
145 { return byIdentBegin( ByIdent(ident_r) ); }
148 byIdent_iterator byIdentEnd( const ByIdent & ident_r ) const
150 return make_transform_iterator( id2item().equal_range( ident_r.get() ).second,
151 pool::PoolTraits::Id2ItemValueSelector() );
154 byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
155 { return byIdentEnd( ByIdent(kind_r,name_r) ); }
157 byIdent_iterator byIdentEnd( ResKind kind_r, const C_Str & name_r ) const
158 { return byIdentEnd( ByIdent(kind_r,name_r) ); }
161 byIdent_iterator byIdentEnd( IdString name_r ) const
162 { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
165 byIdent_iterator byIdentEnd( const C_Str & name_r ) const
166 { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
168 /** Derive name and kind from \ref PoolItem. */
169 byIdent_iterator byIdentEnd( const PoolItem & pi_r ) const
170 { return byIdentEnd( ByIdent(pi_r.satSolvable()) ); }
171 /** Derive name and kind from \ref sat::Solvable. */
172 byIdent_iterator byIdentEnd( sat::Solvable slv_r ) const
173 { return byIdentEnd( ByIdent(slv_r) ); }
174 /** Takes a \ref sat::Solvable::ident string. */
175 byIdent_iterator byIdentEnd( IdString ident_r ) const
176 { return byIdentEnd( ByIdent(ident_r) ); }
180 /** \name Iterate over all ResObjects of a certain kind. */
182 typedef filter::ByKind ByKind;
183 typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
185 byKind_iterator byKindBegin( const ResKind & kind_r ) const
186 { return make_filter_begin( ByKind(kind_r), *this ); }
189 byKind_iterator byKindBegin() const
190 { return make_filter_begin( resfilter::byKind<_Res>(), *this ); }
192 byKind_iterator byKindEnd( const ResKind & kind_r ) const
193 { return make_filter_end( ByKind(kind_r), *this ); }
196 byKind_iterator byKindEnd() const
197 { return make_filter_end( resfilter::byKind<_Res>(), *this ); }
201 /** \name Iterate over all ResObjects with a certain name (all kinds). */
203 typedef zypp::resfilter::ByName ByName;
204 typedef filter_iterator<ByName,const_iterator> byName_iterator;
206 byName_iterator byNameBegin( const std::string & name_r ) const
207 { return make_filter_begin( ByName(name_r), *this ); }
209 byName_iterator byNameEnd( const std::string & name_r ) const
210 { return make_filter_end( ByName(name_r), *this ); }
214 /** \name Special iterators. */
219 /** \name Iterate over all Repositories that contribute ResObjects.
222 size_type knownRepositoriesSize() const;
224 repository_iterator knownRepositoriesBegin() const;
226 repository_iterator knownRepositoriesEnd() const;
228 /** Find a \ref Repository named \c alias_r.
229 * Returns \ref Repository::norepository if there is no such \ref Repository.
231 Repository reposFind( const std::string & alias_r ) const;
235 /** \name Handle locale support.
237 * A \ref filter::ByLocaleSupport is provided to iterate over
238 * all items supporting a specific locale.
240 * \see \ref sat::LocaleSupport for a more convenient interface.
243 * ResPool pool( ResPool::instance() );
245 * filter::ByLocaleSupport f( Locale("de") );
246 * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
248 * MIL << *it << endl; // supporting "de"
251 * f = filter::ByLocaleSupport( pool.getRequestedLocales() );
252 * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
254 * MIL << *it << endl; // supporting any requested locale
259 /** Set the requested locales.
260 * Languages to be supported by the system, e.g. language specific
261 * packages to be installed.
263 void setRequestedLocales( const LocaleSet & locales_r );
265 /** Add one \ref Locale to the set of requested locales.
266 * Return \c true if \c locale_r was newly added to the set.
268 bool addRequestedLocale( const Locale & locale_r );
270 /** Erase one \ref Locale from the set of requested locales.
271 * Return \c false if \c locale_r was not found in the set.
273 bool eraseRequestedLocale( const Locale & locale_r );
275 /** Return the requested locales.
276 * \see \ref setRequestedLocales
278 const LocaleSet & getRequestedLocales() const;
280 /** Wheter this \ref Locale is in the set of requested locales. */
281 bool isRequestedLocale( const Locale & locale_r ) const;
283 /** Get the set of available locales.
284 * This is computed from the package data so it actually
285 * represents all locales packages claim to support.
287 const LocaleSet & getAvailableLocales() const;
289 /** Wheter this \ref Locale is in the set of available locales. */
290 bool isAvailableLocale( const Locale & locale_r ) const;
294 /** \name Handle automatic soft-locks.
296 * Solvables with and ident listed here are per default created with
297 * a setSoftLock applied. I.e. the \ref Resolver should not automatically
298 * select them, if they are just recommended.
300 * This list is considered when adding new repos to the pool. It is
301 * \b not the list of currently softLocked items.
303 * Mainly used to re-apply soft-locks remembered during the last commit.
306 typedef pool::PoolTraits::AutoSoftLocks AutoSoftLocks;
307 typedef pool::PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
309 bool autoSoftLocksEmpty() const;
310 size_type autoSoftLocksSize() const;
311 autoSoftLocks_iterator autoSoftLocksBegin() const;
312 autoSoftLocks_iterator autoSoftLocksEnd() const;
314 /** Set a new soft-lock list.
315 * The soft-locks of existing PoolItems are adjusted according
316 * to the list. (usually called on target load)
318 void setAutoSoftLocks( const AutoSoftLocks & newLocks_r );
320 /** Suggest a new soft-lock list based on the current selection.
321 * Based on the the current soft-lock list. Items tagged to be
322 * installed are removed, and those tagged to be deleted are added.
323 * (usually remembered on commit).
325 void getActiveSoftLocks( AutoSoftLocks & activeLocks_r );
329 /** \name Handle hard locks (e.g set from /etc/zypp/locks).
331 * As this kind of lock is query based, it's quite expensive.
333 * These queries are re-evaluated when adding new repos to the pool.
336 typedef pool::PoolTraits::HardLockQueries HardLockQueries;
337 typedef pool::PoolTraits::hardLockQueries_iterator hardLockQueries_iterator;
339 bool hardLockQueriesEmpty() const;
340 size_type hardLockQueriesSize() const;
341 hardLockQueries_iterator hardLockQueriesBegin() const;
342 hardLockQueries_iterator hardLockQueriesEnd() const;
344 /** Set a new set of queries.
345 * The hard-locks of existing PoolItems are adjusted according
346 * to the queries. (usually called on target load)
348 void setHardLockQueries( const HardLockQueries & newLocks_r );
350 /** Suggest a new set of queries based on the current selection.
351 * (usually remembered on commit).
353 void getHardLockQueries( HardLockQueries & activeLocks_r );
357 const pool::PoolTraits::ItemContainerT & store() const;
358 const pool::PoolTraits::Id2ItemT & id2item() const;
362 ResPool( pool::PoolTraits::Impl_Ptr impl_r );
363 /** Access to implementation. */
364 RW_pointer<pool::PoolTraits::Impl> _pimpl;
366 ///////////////////////////////////////////////////////////////////
368 /** \relates ResPool Stream output */
369 std::ostream & operator<<( std::ostream & str, const ResPool & obj );
371 /////////////////////////////////////////////////////////////////
373 ///////////////////////////////////////////////////////////////////
375 #include "zypp/ResPoolProxy.h"
377 #endif // ZYPP_RESPOOL_H