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/ResFilters.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;
57 typedef pool::PoolTraits::byCapabilityIndex_iterator byCapabilityIndex_iterator;
58 typedef pool::PoolTraits::AdditionalCapabilities AdditionalCapabilities;
59 typedef pool::PoolTraits::repository_iterator repository_iterator;
62 /** Singleton ctor. */
63 static ResPool instance();
66 ResPoolProxy proxy() const;
69 /** The pools serial number. Changing whenever the
70 * whenever the content changes. (Resolvables or
73 const SerialNumber & serial() const;
79 size_type size() const;
81 /** \name Iterate through all PoolItems (all kinds). */
84 const_iterator begin() const
85 { return make_filter_begin( pool::ByPoolItem(), store() ); }
87 const_iterator end() const
88 { return make_filter_end( pool::ByPoolItem(), store() ); }
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.
97 PoolItem find( const sat::Solvable & slv_r ) const;
100 /** \name Iterate through 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 through 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 through all ResObjects of a certain kind. */
182 typedef zypp::resfilter::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 through all ResObjects with a certain name (all kinds).
202 * \deprecated Instead of iterating byName and filter byKind use ByIdent iterator.
205 typedef zypp::resfilter::ByName ByName;
206 typedef filter_iterator<ByName,const_iterator> byName_iterator;
208 byName_iterator ZYPP_DEPRECATED byNameBegin( const std::string & name_r ) const
209 { return make_filter_begin( ByName(name_r), *this ); }
211 byName_iterator ZYPP_DEPRECATED byNameEnd( const std::string & name_r ) const
212 { return make_filter_end( ByName(name_r), *this ); }
216 /** \name Iterate through all ResObjects which have at least
217 * one Capability with index \a index_r in dependency \a depType_r.
220 byCapabilityIndex_iterator byCapabilityIndexBegin( const std::string & index_r, Dep depType_r ) const;
222 byCapabilityIndex_iterator byCapabilityIndexEnd( const std::string & index_r, Dep depType_r ) const;
226 /** \name Iterate through all Repositories that contribute ResObjects.
229 size_type knownRepositoriesSize() const;
231 repository_iterator knownRepositoriesBegin() const;
233 repository_iterator knownRepositoriesEnd() const;
237 /** \name Iterate through requested/available Locales.
240 /** Set the requested locales.
241 * Languages to be supported by the system, e.g. language specific
242 * packages to be installed.
244 void setRequestedLocales( const LocaleSet & locales_r );
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.
249 bool addRequestedLocale( const Locale & locale_r );
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.
254 bool eraseRequestedLocale( const Locale & locale_r );
256 /** Return the requested locales.
257 * \see \ref setRequestedLocales
259 const LocaleSet & getRequestedLocales() const;
261 /** Wheter this \ref Locale is in the set of requested locales. */
262 bool isRequestedLocale( const Locale & locale_r ) const;
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.
268 const LocaleSet & getAvailableLocales() const;
270 /** Wheter this \ref Locale is in the set of available locales. */
271 bool isAvailableLocale( const Locale & locale_r ) const;
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.
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.
284 * Handling additional requirement. E.G. need package "foo" and package
285 * "foo1" which has a greater version than 1.0:
288 * Capabilities capset;
289 * capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
290 * capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
292 * // The user is setting this capablility
293 * ResPool::AdditionalCapabilities aCapabilities;
294 * aCapabilities[ResStatus::USER] = capset;
296 * setAdditionalRequire( aCapabilities );
299 void setAdditionalRequire( const AdditionalCapabilities & capset ) const;
300 AdditionalCapabilities & additionalRequire() const;
303 * Handling additional conflicts. E.G. do not install anything which provides "foo":
306 * Capabilities capset;
307 * capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
309 * // The user is setting this capablility
310 * ResPool::AdditionalCapabilities aCapabilities;
311 * aCapabilities[ResStatus::USER] = capset;
313 * setAdditionalConflict( aCapabilities );
316 void setAdditionalConflict( const AdditionalCapabilities & capset ) const;
317 AdditionalCapabilities & additionaConflict() const;
320 * Handling additional provides. This is used for ignoring a requirement.
321 * e.G. Do ignore the requirement "foo":
324 * Capabilities capset;
325 * capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo"));
327 * // The user is setting this capablility
328 * ResPool::AdditionalCapabilities aCapabilities;
329 * aCapabilities[ResStatus::USER] = capset;
331 * setAdditionalProvide( aCapabilities );
334 void setAdditionalProvide( const AdditionalCapabilities & capset ) const;
335 AdditionalCapabilities & additionaProvide() const;
338 const pool::PoolTraits::ItemContainerT & store() const;
339 const pool::PoolTraits::Id2ItemT & id2item() const;
343 ResPool( pool::PoolTraits::Impl_constPtr impl_r );
344 /** Const access to implementation. */
345 pool::PoolTraits::Impl_constPtr _pimpl;
347 ///////////////////////////////////////////////////////////////////
349 /** \relates ResPool Stream output */
350 std::ostream & operator<<( std::ostream & str, const ResPool & obj );
352 /////////////////////////////////////////////////////////////////
354 ///////////////////////////////////////////////////////////////////
356 #include "zypp/ResPoolProxy.h"
358 #endif // ZYPP_RESPOOL_H