- Add ResPool::reposFind to get repositories by alias.
[platform/upstream/libzypp.git] / zypp / ResPool.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ResPool.h
10  *
11 */
12 #ifndef ZYPP_RESPOOL_H
13 #define ZYPP_RESPOOL_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/Deprecated.h"
18 #include "zypp/base/Iterator.h"
19
20 #include "zypp/pool/PoolTraits.h"
21 #include "zypp/PoolItem.h"
22 #include "zypp/Filter.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27
28   class SerialNumber;
29   class ResPoolProxy;
30
31   ///////////////////////////////////////////////////////////////////
32   //
33   //    CLASS NAME : ResPool
34   //
35   /** Global ResObject pool.
36    *
37    * Explicitly shared singleton.
38    *
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.
44    *
45    * \include n_ResPool_nomorenameiter
46   */
47   class ResPool
48   {
49     friend std::ostream & operator<<( std::ostream & str, const ResPool & obj );
50
51     public:
52       /** \ref PoolItem */
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;
57
58     public:
59       /** Singleton ctor. */
60       static ResPool instance();
61
62       /** preliminary */
63       ResPoolProxy proxy() const;
64
65     public:
66       /** The pools serial number. Changing whenever the
67        * whenever the content changes. (Resolvables or
68        * Dependencies).
69        */
70       const SerialNumber & serial() const;
71
72     public:
73       /**  */
74       bool empty() const;
75       /**  */
76       size_type size() const;
77
78       /** \name Iterate over all PoolItems (all kinds). */
79       //@{
80       /** */
81       const_iterator begin() const
82       { return make_filter_begin( pool::ByPoolItem(), store() ); }
83       /** */
84       const_iterator end() const
85       { return make_filter_end( pool::ByPoolItem(), store() ); }
86       //@}
87
88     public:
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.
93        */
94       PoolItem find( const sat::Solvable & slv_r ) const;
95       /** \overload */
96       PoolItem find( const ResObject::constPtr & resolvable_r ) const
97       { return( resolvable_r ? find( resolvable_r->satSolvable() ) : PoolItem() ); }
98
99     public:
100       /** \name Iterate over all PoolItems matching a \c _Filter. */
101       //@{
102       template<class _Filter>
103       filter_iterator<_Filter,const_iterator> filterBegin( const _Filter & filter_r ) const
104       { return make_filter_begin( filter_r, *this ); }
105
106       template<class _Filter>
107       filter_iterator<_Filter,const_iterator> filterEnd( const _Filter & filter_r ) const
108       { return make_filter_end( filter_r, *this ); }
109       //@}
110
111     public:
112       /** \name Iterate over all PoolItems of a certain name and kind. */
113       //@{
114       typedef pool::ByIdent                       ByIdent;
115       typedef pool::PoolTraits::byIdent_iterator  byIdent_iterator;
116
117       byIdent_iterator byIdentBegin( const ByIdent & ident_r ) const
118       {
119         return make_transform_iterator( id2item().equal_range( ident_r.get() ).first,
120                                         pool::PoolTraits::Id2ItemValueSelector() );
121       }
122
123       byIdent_iterator byIdentBegin( ResKind kind_r, IdString name_r ) const
124       { return byIdentBegin( ByIdent(kind_r,name_r) ); }
125
126       byIdent_iterator byIdentBegin( ResKind kind_r, const C_Str & name_r ) const
127       { return byIdentBegin( ByIdent(kind_r,name_r) ); }
128
129       template<class _Res>
130       byIdent_iterator byIdentBegin( IdString name_r ) const
131       { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
132
133       template<class _Res>
134       byIdent_iterator byIdentBegin( const C_Str & name_r ) const
135       { return byIdentBegin( ByIdent(ResTraits<_Res>::kind,name_r) ); }
136
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) ); }
146
147
148       byIdent_iterator byIdentEnd( const ByIdent & ident_r ) const
149       {
150         return make_transform_iterator( id2item().equal_range( ident_r.get() ).second,
151                                         pool::PoolTraits::Id2ItemValueSelector() );
152       }
153
154       byIdent_iterator byIdentEnd( ResKind kind_r, IdString name_r ) const
155       { return byIdentEnd( ByIdent(kind_r,name_r) ); }
156
157       byIdent_iterator byIdentEnd( ResKind kind_r, const C_Str & name_r ) const
158       { return byIdentEnd( ByIdent(kind_r,name_r) ); }
159
160       template<class _Res>
161       byIdent_iterator byIdentEnd( IdString name_r ) const
162       { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
163
164       template<class _Res>
165       byIdent_iterator byIdentEnd( const C_Str & name_r ) const
166       { return byIdentEnd( ByIdent(ResTraits<_Res>::kind,name_r) ); }
167
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) ); }
177      //@}
178
179     public:
180       /** \name Iterate over all ResObjects of a certain kind. */
181       //@{
182       typedef filter::ByKind ByKind;
183       typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
184
185       byKind_iterator byKindBegin( const ResKind & kind_r ) const
186       { return make_filter_begin( ByKind(kind_r), *this ); }
187
188       template<class _Res>
189           byKind_iterator byKindBegin() const
190       { return make_filter_begin( resfilter::byKind<_Res>(), *this ); }
191
192       byKind_iterator byKindEnd( const ResKind & kind_r ) const
193       { return make_filter_end( ByKind(kind_r), *this ); }
194
195       template<class _Res>
196           byKind_iterator byKindEnd() const
197       { return make_filter_end( resfilter::byKind<_Res>(), *this ); }
198       //@}
199
200     public:
201       /** \name Iterate over all ResObjects with a certain name (all kinds). */
202       //@{
203       typedef zypp::resfilter::ByName ByName;
204       typedef filter_iterator<ByName,const_iterator> byName_iterator;
205
206       byName_iterator byNameBegin( const std::string & name_r ) const
207       { return make_filter_begin( ByName(name_r), *this ); }
208
209       byName_iterator byNameEnd( const std::string & name_r ) const
210       { return make_filter_end( ByName(name_r), *this ); }
211       //@}
212
213     public:
214       /** \name Special iterators. */
215       //@{
216
217       //@}
218    public:
219       /** \name Iterate over all Repositories that contribute ResObjects.
220        */
221       //@{
222       size_type knownRepositoriesSize() const;
223
224       repository_iterator knownRepositoriesBegin() const;
225
226       repository_iterator knownRepositoriesEnd() const;
227
228       /** Find a \ref Repository named \c alias_r.
229        * Returns \ref Repository::norepository if there is no such \ref Repository.
230        */
231       Repository reposFind( const std::string & alias_r ) const;
232       //@}
233
234     public:
235       /** \name Handle locale support.
236        *
237        * A \ref filter::ByLocaleSupport is provided to iterate over
238        * all items supporting a specific locale.
239        *
240        * \see \ref sat::LocaleSupport for a more convenient interface.
241        *
242        * \code
243        * ResPool pool( ResPool::instance() );
244        *
245        * filter::ByLocaleSupport f( Locale("de") );
246        * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
247        * {
248        *   MIL << *it << endl; // supporting "de"
249        * }
250        *
251        * f = filter::ByLocaleSupport( pool.getRequestedLocales() );
252        * for_( it, pool.filterBegin(f), pool.filterEnd(f) )
253        * {
254        *   MIL << *it << endl; // supporting any requested locale
255        * }
256        * \endcode
257        */
258       //@{
259       /** Set the requested locales.
260        * Languages to be supported by the system, e.g. language specific
261        * packages to be installed.
262        */
263       void setRequestedLocales( const LocaleSet & locales_r );
264
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.
267       */
268       bool addRequestedLocale( const Locale & locale_r );
269
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.
272        */
273       bool eraseRequestedLocale( const Locale & locale_r );
274
275       /** Return the requested locales.
276        * \see \ref setRequestedLocales
277       */
278       const LocaleSet & getRequestedLocales() const;
279
280       /** Wheter this \ref Locale is in the set of requested locales. */
281       bool isRequestedLocale( const Locale & locale_r ) const;
282
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.
286        */
287       const LocaleSet & getAvailableLocales() const;
288
289       /** Wheter this \ref Locale is in the set of available locales. */
290       bool isAvailableLocale( const Locale & locale_r ) const;
291       //@}
292
293     public:
294       /** \name Handle automatic soft-locks.
295        *
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.
299        *
300        * This list is considered when adding new repos to the pool. It is
301        * \b not the list of currently softLocked items.
302        *
303        * Mainly used to re-apply soft-locks remembered during the last commit.
304        */
305       //@{
306       typedef pool::PoolTraits::AutoSoftLocks          AutoSoftLocks;
307       typedef pool::PoolTraits::autoSoftLocks_iterator autoSoftLocks_iterator;
308
309       bool autoSoftLocksEmpty() const;
310       size_type autoSoftLocksSize() const;
311       autoSoftLocks_iterator autoSoftLocksBegin() const;
312       autoSoftLocks_iterator autoSoftLocksEnd() const;
313
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)
317       */
318       void setAutoSoftLocks( const AutoSoftLocks & newLocks_r );
319
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).
324       */
325       void getActiveSoftLocks( AutoSoftLocks & activeLocks_r );
326       //@}
327
328     public:
329       /** \name Handle hard locks (e.g set from /etc/zypp/locks).
330        *
331        * As this kind of lock is query based, it's quite expensive.
332        *
333        * These queries are re-evaluated when adding new repos to the pool.
334        */
335       //@{
336       typedef pool::PoolTraits::HardLockQueries           HardLockQueries;
337       typedef pool::PoolTraits::hardLockQueries_iterator  hardLockQueries_iterator;
338
339       bool hardLockQueriesEmpty() const;
340       size_type hardLockQueriesSize() const;
341       hardLockQueries_iterator hardLockQueriesBegin() const;
342       hardLockQueries_iterator hardLockQueriesEnd() const;
343
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)
347        */
348       void setHardLockQueries( const HardLockQueries & newLocks_r );
349
350       /** Suggest a new set of queries based on the current selection.
351        * (usually remembered on commit).
352        */
353       void getHardLockQueries( HardLockQueries & activeLocks_r );
354       //@}
355
356     private:
357       const pool::PoolTraits::ItemContainerT & store() const;
358       const pool::PoolTraits::Id2ItemT & id2item() const;
359
360     private:
361       /** Ctor */
362       ResPool( pool::PoolTraits::Impl_Ptr impl_r );
363       /** Access to implementation. */
364       RW_pointer<pool::PoolTraits::Impl> _pimpl;
365   };
366   ///////////////////////////////////////////////////////////////////
367
368   /** \relates ResPool Stream output */
369   std::ostream & operator<<( std::ostream & str, const ResPool & obj );
370
371   /////////////////////////////////////////////////////////////////
372 } // namespace zypp
373 ///////////////////////////////////////////////////////////////////
374
375 #include "zypp/ResPoolProxy.h"
376
377 #endif // ZYPP_RESPOOL_H