1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Pool.h
12 #ifndef ZYPP_SAT_POOL_H
13 #define ZYPP_SAT_POOL_H
17 #include "zypp/Pathname.h"
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/Repository.h"
21 #include "zypp/sat/WhatProvides.h"
22 #include "zypp/sat/SolvableSet.h"
23 #include "zypp/sat/Queue.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 { /////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
42 * Explicitly shared singleton \ref Pool::instance.
44 class Pool : protected detail::PoolMember
47 typedef detail::SolvableIterator SolvableIterator;
48 typedef zypp::detail::RepositoryIterator RepositoryIterator;
49 typedef detail::size_type size_type;
52 /** Singleton ctor. */
53 static Pool instance()
56 /** Ctor from \ref PoolMember. */
57 Pool( const detail::PoolMember & )
61 /** Internal array size for stats only. */
62 size_type capacity() const;
64 /** Housekeeping data serial number. */
65 const SerialNumber & serial() const;
67 /** Update housekeeping data if necessary (e.g. whatprovides). */
70 /** Get rootdir (for file conflicts check) */
71 Pathname rootDir() const;
73 /** Set rootdir (for file conflicts check) */
74 void rootDir( const Pathname & root_r );
77 /** Whether \ref Pool contains repos. */
78 bool reposEmpty() const;
80 /** Number of repos in \ref Pool. */
81 size_type reposSize() const;
83 /** Iterator to the first \ref Repository. */
84 RepositoryIterator reposBegin() const;
86 /** Iterator behind the last \ref Repository. */
87 RepositoryIterator reposEnd() const;
89 /** Iterate the repositories. */
90 Iterable<RepositoryIterator> repos() const
91 { return makeIterable( reposBegin(), reposEnd() ); }
93 /** Return a \ref Repository named \c alias_r.
94 * It a such a \ref Repository does not already exist
95 * a new empty \ref Repository is created.
97 Repository reposInsert( const std::string & alias_r );
99 /** Find a \ref Repository named \c alias_r.
100 * Returns \ref noRepository if there is no such \ref Repository.
102 Repository reposFind( const std::string & alias_r ) const;
104 /** Remove a \ref Repository named \c alias_r.
105 * \see \ref Repository::eraseFromPool
107 void reposErase( const std::string & alias_r )
108 { reposFind( alias_r ).eraseFromPool(); }
110 /** Remove all repos from the pool.
111 * This also shrinks a pool which may have become large
112 * after having added and removed repos lots of times.
115 { while ( ! reposEmpty() ) reposErase( reposBegin()->alias() ); }
118 /** Reserved system repository alias \c @System. */
119 static const std::string & systemRepoAlias();
121 /** Return the system repository if it is on the pool. */
122 Repository findSystemRepo() const;
124 /** Return the system repository, create it if missing. */
125 Repository systemRepo();
128 /** Load \ref Solvables from a solv-file into a \ref Repository named \c name_r.
129 * In case of an exception the \ref Repository is removed from the \ref Pool.
130 * \throws Exception if loading the solv-file fails.
131 * \see \ref Repository::EraseFromPool
133 Repository addRepoSolv( const Pathname & file_r, const std::string & name_r );
134 /** \overload Using the files basename as \ref Repository name. */
135 Repository addRepoSolv( const Pathname & file_r );
136 /** \overload Using the \ref RepoInfo::alias \ref Repo name.
137 * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
139 Repository addRepoSolv( const Pathname & file_r, const RepoInfo & info_r );
142 /** Load \ref Solvables from a helix-file into a \ref Repository named \c name_r.
143 * Supports loading of gzip compressed files (.gz). In case of an exception
144 * the \ref Repository is removed from the \ref Pool.
145 * \throws Exception if loading the helix-file fails.
146 * \see \ref Repository::EraseFromPool
148 Repository addRepoHelix( const Pathname & file_r, const std::string & name_r );
149 /** \overload Using the files basename as \ref Repository name. */
150 Repository addRepoHelix( const Pathname & file_r );
151 /** \overload Using the \ref RepoInfo::alias \ref Repo name.
152 * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
154 Repository addRepoHelix( const Pathname & file_r, const RepoInfo & info_r );
157 /** Whether \ref Pool contains solvables. */
158 bool solvablesEmpty() const;
160 /** Number of solvables in \ref Pool. */
161 size_type solvablesSize() const;
163 /** Iterator to the first \ref Solvable. */
164 SolvableIterator solvablesBegin() const;
166 /** Iterator behind the last \ref Solvable. */
167 SolvableIterator solvablesEnd() const;
169 /** Iterate the solvables. */
170 Iterable<SolvableIterator> solvables() const
171 { return makeIterable( solvablesBegin(), solvablesEnd() ); }
174 /** \name Iterate all Solvables matching a \c TFilter. */
176 template<class TFilter>
177 filter_iterator<TFilter,SolvableIterator> filterBegin( const TFilter & filter_r ) const
178 { return make_filter_iterator( filter_r, solvablesBegin(), solvablesEnd() ); }
180 template<class TFilter>
181 filter_iterator<TFilter,SolvableIterator> filterEnd( const TFilter & filter_r ) const
182 { return make_filter_iterator( filter_r, solvablesEnd(), solvablesEnd() ); }
186 /** Conainer of all \ref Solvable providing \c cap_r. */
187 WhatProvides whatProvides( Capability cap_r ) const
188 { return WhatProvides( cap_r ); }
191 /** \name Requested locales. */
193 /** Set the default language for retrieving translated texts.
194 * Updated when calling \ref ZConfig::setTextLocale.
196 void setTextLocale( const Locale & locale_r );
198 /** Set the requested locales.
199 * Languages to be supported by the system, e.g. language specific
200 * packages to be installed.
202 void setRequestedLocales( const LocaleSet & locales_r );
204 /** Add one \ref Locale to the set of requested locales.
205 * Return \c true if \c locale_r was newly added to the set.
207 bool addRequestedLocale( const Locale & locale_r );
209 /** Erase one \ref Locale from the set of requested locales.
210 * Return \c false if \c locale_r was not found in the set.
212 bool eraseRequestedLocale( const Locale & locale_r );
214 /** Return the requested locales.
215 * \see \ref setRequestedLocales
217 const LocaleSet & getRequestedLocales() const;
219 /** Whether this \ref Locale is in the set of requested locales. */
220 bool isRequestedLocale( const Locale & locale_r ) const;
223 /** Start tracking changes based on this \a locales_r. */
224 void initRequestedLocales( const LocaleSet & locales_r );
226 /** Added since last initRequestedLocales. */
227 const LocaleSet & getAddedRequestedLocales() const;
229 /** Removed since last initRequestedLocales.*/
230 const LocaleSet & getRemovedRequestedLocales() const;
233 /** Get the set of available locales.
234 * This is computed from the package data so it actually
235 * represents all locales packages claim to support.
237 const LocaleSet & getAvailableLocales() const;
239 /** Whether this \ref Locale is in the set of available locales. */
240 bool isAvailableLocale( const Locale & locale_r ) const;
244 /** \name Multiversion install.
245 * Whether the pool contains packages which are multiversion installable.
246 * \see \ref Solvable::multiversionInstall
247 * \see \ref ZConfig::multiversionSpec
250 typedef SolvableSet MultiversionList;
251 const MultiversionList & multiversion() const;
252 /** \deprecated Legacy, use multiversion().empty() instead. */
253 ZYPP_DEPRECATED bool multiversionEmpty() const { return multiversion().empty(); }
257 /** \name Autoinstalled */
259 /** Get ident list of all autoinstalled solvables. */
260 Queue autoInstalled() const;
261 /** Set ident list of all autoinstalled solvables. */
262 void setAutoInstalled( const Queue & autoInstalled_r );
266 /** Expert backdoor. */
267 detail::CPool * get() const;
272 ///////////////////////////////////////////////////////////////////
274 /** \relates Pool Stream output */
275 std::ostream & operator<<( std::ostream & str, const Pool & obj );
278 inline bool operator==( const Pool & lhs, const Pool & rhs )
279 { return lhs.get() == rhs.get(); }
282 inline bool operator!=( const Pool & lhs, const Pool & rhs )
283 { return lhs.get() != rhs.get(); }
285 /** Create solv file content digest for zypper bash completion */
286 void updateSolvFileIndex( const Pathname & solvfile_r );
288 /////////////////////////////////////////////////////////////////
290 ///////////////////////////////////////////////////////////////////
291 /////////////////////////////////////////////////////////////////
293 ///////////////////////////////////////////////////////////////////
294 #endif // ZYPP_SAT_POOL_H