Imported Upstream version 15.19.0
[platform/upstream/libzypp.git] / zypp / sat / Pool.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Pool.h
10  *
11 */
12 #ifndef ZYPP_SAT_POOL_H
13 #define ZYPP_SAT_POOL_H
14
15 #include <iosfwd>
16
17 #include "zypp/Pathname.h"
18
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"
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28
29   class SerialNumber;
30   class RepoInfo;
31
32   ///////////////////////////////////////////////////////////////////
33   namespace sat
34   { /////////////////////////////////////////////////////////////////
35
36     ///////////////////////////////////////////////////////////////////
37     //
38     //  CLASS NAME : Pool
39     //
40     /** Global sat-pool.
41      *
42      * Explicitly shared singleton \ref Pool::instance.
43      */
44     class Pool : protected detail::PoolMember
45     {
46       public:
47         typedef detail::SolvableIterator SolvableIterator;
48         typedef zypp::detail::RepositoryIterator     RepositoryIterator;
49         typedef detail::size_type        size_type;
50
51       public:
52         /** Singleton ctor. */
53         static Pool instance()
54         { return Pool(); }
55
56         /** Ctor from \ref PoolMember. */
57         Pool( const detail::PoolMember & )
58         {}
59
60       public:
61         /** Internal array size for stats only. */
62         size_type capacity() const;
63
64         /** Housekeeping data serial number. */
65         const SerialNumber & serial() const;
66
67         /** Update housekeeping data if necessary (e.g. whatprovides). */
68         void prepare() const;
69
70         /** \ref prepare plus some expensive checks done before solving only. */
71         void prepareForSolving() const;
72
73         /** Get rootdir (for file conflicts check) */
74         Pathname rootDir() const;
75
76         /** Set rootdir (for file conflicts check) */
77         void rootDir( const Pathname & root_r );
78
79       public:
80         /** Whether \ref Pool contains repos. */
81         bool reposEmpty() const;
82
83         /** Number of repos in \ref Pool. */
84         size_type reposSize() const;
85
86         /** Iterator to the first \ref Repository. */
87         RepositoryIterator reposBegin() const;
88
89         /** Iterator behind the last \ref Repository. */
90         RepositoryIterator reposEnd() const;
91
92         /** Iterate the repositories. */
93         Iterable<RepositoryIterator> repos() const
94         { return makeIterable( reposBegin(), reposEnd() ); }
95
96         /** Return a \ref Repository named \c alias_r.
97          * It a such a \ref Repository does not already exist
98          * a new empty \ref Repository is created.
99          */
100         Repository reposInsert( const std::string & alias_r );
101
102         /** Find a \ref Repository named \c alias_r.
103          * Returns \ref norepository if there is no such \ref Repository.
104          */
105         Repository reposFind( const std::string & alias_r ) const;
106
107         /** Remove a \ref Repository named \c alias_r.
108          * \see \ref Repository::eraseFromPool
109          */
110         void reposErase( const std::string & alias_r )
111         { reposFind( alias_r ).eraseFromPool(); }
112
113       public:
114         /** Reserved system repository alias \c @System. */
115         static const std::string & systemRepoAlias();
116
117         /** Return the system repository if it is on the pool. */
118         Repository findSystemRepo() const;
119
120         /** Return the system repository, create it if missing. */
121         Repository systemRepo();
122
123       public:
124         /** Load \ref Solvables from a solv-file into a \ref Repository named \c name_r.
125          * In case of an exception the \ref Repository is removed from the \ref Pool.
126          * \throws Exception if loading the solv-file fails.
127          * \see \ref Repository::EraseFromPool
128         */
129         Repository addRepoSolv( const Pathname & file_r, const std::string & name_r );
130         /** \overload Using the files basename as \ref Repository name. */
131         Repository addRepoSolv( const Pathname & file_r );
132         /** \overload Using the \ref RepoInfo::alias \ref Repo name.
133          * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
134         */
135         Repository addRepoSolv( const Pathname & file_r, const RepoInfo & info_r );
136
137       public:
138         /** Load \ref Solvables from a helix-file into a \ref Repository named \c name_r.
139          * Supports loading of gzip compressed files (.gz). In case of an exception
140          * the \ref Repository is removed from the \ref Pool.
141          * \throws Exception if loading the helix-file fails.
142          * \see \ref Repository::EraseFromPool
143         */
144         Repository addRepoHelix( const Pathname & file_r, const std::string & name_r );
145         /** \overload Using the files basename as \ref Repository name. */
146         Repository addRepoHelix( const Pathname & file_r );
147         /** \overload Using the \ref RepoInfo::alias \ref Repo name.
148          * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
149         */
150         Repository addRepoHelix( const Pathname & file_r, const RepoInfo & info_r );
151
152       public:
153         /** Whether \ref Pool contains solvables. */
154         bool solvablesEmpty() const;
155
156         /** Number of solvables in \ref Pool. */
157         size_type solvablesSize() const;
158
159         /** Iterator to the first \ref Solvable. */
160         SolvableIterator solvablesBegin() const;
161
162         /** Iterator behind the last \ref Solvable. */
163         SolvableIterator solvablesEnd() const;
164
165         /** Iterate the solvables. */
166         Iterable<SolvableIterator> solvables() const
167         { return makeIterable( solvablesBegin(), solvablesEnd() ); }
168
169       public:
170         /** \name Iterate all Solvables matching a \c TFilter. */
171         //@{
172         template<class TFilter>
173         filter_iterator<TFilter,SolvableIterator> filterBegin( const TFilter & filter_r ) const
174         { return make_filter_iterator( filter_r, solvablesBegin(), solvablesEnd() ); }
175
176         template<class TFilter>
177         filter_iterator<TFilter,SolvableIterator> filterEnd( const TFilter & filter_r ) const
178         { return make_filter_iterator( filter_r, solvablesEnd(), solvablesEnd() ); }
179         //@}
180
181      public:
182         /** Conainer of all \ref Solvable providing \c cap_r.  */
183         WhatProvides whatProvides( Capability cap_r ) const
184         { return WhatProvides( cap_r ); }
185
186       public:
187         /** \name Requested locales. */
188         //@{
189         /** Set the default language for retrieving translated texts.
190          * Updated when calling \ref ZConfig::setTextLocale.
191          */
192         void setTextLocale( const Locale & locale_r );
193
194         /** Set the requested locales.
195          * Languages to be supported by the system, e.g. language specific
196          * packages to be installed.
197          */
198         void setRequestedLocales( const LocaleSet & locales_r );
199
200         /** Add one \ref Locale to the set of requested locales.
201          * Return \c true if \c locale_r was newly added to the set.
202         */
203         bool addRequestedLocale( const Locale & locale_r );
204
205         /** Erase one \ref Locale from the set of requested locales.
206         * Return \c false if \c locale_r was not found in the set.
207          */
208         bool eraseRequestedLocale( const Locale & locale_r );
209
210         /** Return the requested locales.
211          * \see \ref setRequestedLocales
212         */
213         const LocaleSet & getRequestedLocales() const;
214
215         /** Whether this \ref Locale is in the set of requested locales. */
216         bool isRequestedLocale( const Locale & locale_r ) const;
217
218
219         /** Start tracking changes based on this \a locales_r. */
220         void initRequestedLocales( const LocaleSet & locales_r );
221
222         /** Added since last initRequestedLocales. */
223         const LocaleSet & getAddedRequestedLocales() const;
224
225         /** Removed since last initRequestedLocales.*/
226         const LocaleSet & getRemovedRequestedLocales() const;
227
228
229         /** Get the set of available locales.
230          * This is computed from the package data so it actually
231          * represents all locales packages claim to support.
232          */
233         const LocaleSet & getAvailableLocales() const;
234
235         /** Whether this \ref Locale is in the set of available locales. */
236         bool isAvailableLocale( const Locale & locale_r ) const;
237         //@}
238
239       public:
240         /** \name Multiversion install.
241          * Whether the pool contains packages which are multiversion installable.
242          * \see \ref Solvable::multiversionInstall
243          * \see \ref ZConfig::multiversionSpec
244          */
245         //@{
246         typedef SolvableSet MultiversionList;
247         const MultiversionList & multiversion() const;
248         /** \deprecated Legacy, use multiversion().empty() instead. */
249         ZYPP_DEPRECATED bool multiversionEmpty() const { return multiversion().empty(); }
250         //@}
251
252       public:
253         /** \name Autoinstalled */
254         //@{
255         /** Get ident list of all autoinstalled solvables. */
256         Queue autoInstalled() const;
257         /** Set ident list of all autoinstalled solvables. */
258         void setAutoInstalled( const Queue & autoInstalled_r );
259         //@}
260
261       public:
262         /** Expert backdoor. */
263         detail::CPool * get() const;
264       private:
265         /** Default ctor */
266         Pool() {}
267     };
268     ///////////////////////////////////////////////////////////////////
269
270     /** \relates Pool Stream output */
271     std::ostream & operator<<( std::ostream & str, const Pool & obj );
272
273     /** \relates Pool */
274     inline bool operator==( const Pool & lhs, const Pool & rhs )
275     { return lhs.get() == rhs.get(); }
276
277     /** \relates Pool */
278     inline bool operator!=( const Pool & lhs, const Pool & rhs )
279     { return lhs.get() != rhs.get(); }
280
281     /** Create solv file content digest for zypper bash completion */
282     void updateSolvFileIndex( const Pathname & solvfile_r );
283
284     /////////////////////////////////////////////////////////////////
285   } // namespace sat
286   ///////////////////////////////////////////////////////////////////
287   /////////////////////////////////////////////////////////////////
288 } // namespace zypp
289 ///////////////////////////////////////////////////////////////////
290 #endif // ZYPP_SAT_POOL_H