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