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