add basic locale interface to ResPool, remove deprecated _gxx hashes
[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/ResFilters.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
57       typedef pool::PoolTraits::byCapabilityIndex_iterator byCapabilityIndex_iterator;
58       typedef pool::PoolTraits::AdditionalCapabilities     AdditionalCapabilities;
59       typedef pool::PoolTraits::repository_iterator        repository_iterator;
60
61     public:
62       /** Singleton ctor. */
63       static ResPool instance();
64
65       /** preliminary */
66       ResPoolProxy proxy() const;
67
68     public:
69       /** The pools serial number. Changing whenever the
70        * whenever the content changes. (Resolvables or
71        * Dependencies).
72        */
73       const SerialNumber & serial() const;
74
75     public:
76       /**  */
77       bool empty() const;
78       /**  */
79       size_type size() const;
80
81       /** \name Iterate through all PoolItems (all kinds). */
82       //@{
83       /** */
84       const_iterator begin() const
85       { return make_filter_begin( pool::ByPoolItem(), store() ); }
86       /** */
87       const_iterator end() const
88       { return make_filter_end( pool::ByPoolItem(), store() ); }
89       //@}
90
91     public:
92       /** Return the corresponding \ref PoolItem.
93        * Pool and sat pool should be in sync. Returns an empty
94        * \ref PoolItem if there is no corresponding \ref PoolItem.
95        * \see \ref PoolItem::satSolvable.
96        */
97       PoolItem find( const sat::Solvable & slv_r ) const;
98
99     public:
100       /** \name Iterate through 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 through 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 through all ResObjects of a certain kind. */
181       //@{
182       typedef zypp::resfilter::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 through all ResObjects with a certain name (all kinds).
202        * \deprecated Instead of iterating byName and filter byKind use ByIdent iterator.
203       */
204       //@{
205       typedef zypp::resfilter::ByName ByName;
206       typedef filter_iterator<ByName,const_iterator> byName_iterator;
207
208       byName_iterator ZYPP_DEPRECATED byNameBegin( const std::string & name_r ) const
209       { return make_filter_begin( ByName(name_r), *this ); }
210
211       byName_iterator ZYPP_DEPRECATED byNameEnd( const std::string & name_r ) const
212       { return make_filter_end( ByName(name_r), *this ); }
213       //@}
214
215     public:
216       /** \name Iterate through all ResObjects which have at least
217        *  one Capability with index \a index_r in dependency \a depType_r.
218        */
219       //@{
220       byCapabilityIndex_iterator byCapabilityIndexBegin( const std::string & index_r, Dep depType_r ) const;
221
222       byCapabilityIndex_iterator byCapabilityIndexEnd( const std::string & index_r, Dep depType_r ) const;
223       //@}
224
225     public:
226       /** \name Iterate through all Repositories that contribute ResObjects.
227        */
228       //@{
229       size_type knownRepositoriesSize() const;
230
231       repository_iterator knownRepositoriesBegin() const;
232
233       repository_iterator knownRepositoriesEnd() const;
234       //@}
235
236      public:
237       /** \name Iterate through requested/available Locales.
238        */
239       //@{
240       /** Set the requested locales.
241        * Languages to be supported by the system, e.g. language specific
242        * packages to be installed.
243        */
244       void setRequestedLocales( const LocaleSet & locales_r );
245
246       /** Add one \ref Locale to the set of requested locales.
247        * Return \c true if \c locale_r was newly added to the set.
248       */
249       bool addRequestedLocale( const Locale & locale_r );
250
251       /** Erase one \ref Locale from the set of requested locales.
252       * Return \c false if \c locale_r was not found in the set.
253        */
254       bool eraseRequestedLocale( const Locale & locale_r );
255
256       /** Return the requested locales.
257        * \see \ref setRequestedLocales
258       */
259       const LocaleSet & getRequestedLocales() const;
260
261       /** Wheter this \ref Locale is in the set of requested locales. */
262       bool isRequestedLocale( const Locale & locale_r ) const;
263
264       /** Get the set of available locales.
265        * This is computed from the package data so it actually
266        * represents all locales packages claim to support.
267        */
268       const LocaleSet & getAvailableLocales() const;
269
270       /** Wheter this \ref Locale is in the set of available locales. */
271       bool isAvailableLocale( const Locale & locale_r ) const;
272       //@}
273
274    public:
275       /** \name Handling addition capabilities in the pool in order for solving it in
276        *  a solver run. This is used for tasks like needing a package with the name "foo".
277        *  The solver has to evaluate a proper package by his own.
278        *
279        *  CAUTION: This has another semantic in the solver. The required resolvable has
280        *  been set for installation (in the pool) only AFTER a solver run.
281        */
282
283       /**
284        *  Handling additional requirement. E.G. need package "foo" and package
285        *  "foo1" which has a greater version than 1.0:
286        *
287        *  \code
288        *  Capabilities capset;
289        *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
290        *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
291        *
292        *  // The user is setting this capablility
293        *  ResPool::AdditionalCapabilities aCapabilities;
294        *  aCapabilities[ResStatus::USER] = capset;
295        *
296        *  setAdditionalRequire( aCapabilities );
297        *  \endcode
298        */
299       void setAdditionalRequire( const AdditionalCapabilities & capset ) const;
300       AdditionalCapabilities & additionalRequire() const;
301
302      /**
303        *  Handling additional conflicts. E.G. do not install anything which provides "foo":
304        *
305        *  \code75
306        *  Capabilities capset;
307        *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
308        *
309        *  // The user is setting this capablility
310        *  ResPool::AdditionalCapabilities aCapabilities;
311        *  aCapabilities[ResStatus::USER] = capset;
312        *
313        *  setAdditionalConflict( aCapabilities );
314        *  \endcode
315        */
316       void setAdditionalConflict( const AdditionalCapabilities & capset ) const;
317       AdditionalCapabilities & additionaConflict() const;
318
319      /**
320        *  Handling additional provides. This is used for ignoring a requirement.
321        *  e.G. Do ignore the requirement "foo":
322        *
323        *  \code
324        *  Capabilities capset;
325        *  capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
326        *
327        *  // The user is setting this capablility
328        *  ResPool::AdditionalCapabilities aCapabilities;
329        *  aCapabilities[ResStatus::USER] = capset;
330        *
331        *  setAdditionalProvide( aCapabilities );
332        *  \endcode
333        */
334       void setAdditionalProvide( const AdditionalCapabilities & capset ) const;
335       AdditionalCapabilities & additionaProvide() const;
336
337     private:
338       const pool::PoolTraits::ItemContainerT & store() const;
339       const pool::PoolTraits::Id2ItemT & id2item() const;
340
341     private:
342       /** Ctor */
343       ResPool( pool::PoolTraits::Impl_constPtr impl_r );
344       /** Const access to implementation. */
345       pool::PoolTraits::Impl_constPtr _pimpl;
346   };
347   ///////////////////////////////////////////////////////////////////
348
349   /** \relates ResPool Stream output */
350   std::ostream & operator<<( std::ostream & str, const ResPool & obj );
351
352   /////////////////////////////////////////////////////////////////
353 } // namespace zypp
354 ///////////////////////////////////////////////////////////////////
355
356 #include "zypp/ResPoolProxy.h"
357
358 #endif // ZYPP_RESPOOL_H