add sat::WhatProvides to look for Solvable providing a Capability. (somtimes segfaults).
[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/sat/Repo.h"
21 #include "zypp/sat/WhatProvides.h"
22 #include "zypp/Locale.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 detail::RepoIterator     RepoIterator;
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       public:
70         /** Whether \ref Pool contains repos. */
71         bool reposEmpty() const;
72
73         /** Number of repos in \ref Pool. */
74         size_type reposSize() const;
75
76         /** Iterator to the first \ref Repo. */
77         RepoIterator reposBegin() const;
78
79         /** Iterator behind the last \ref Repo. */
80         RepoIterator reposEnd() const;
81
82         /** Return a \ref Repo named \c name_r.
83          * It a such a \ref Repo does not already exist
84          * a new empty \ref Repo is created.
85          */
86         Repo reposInsert( const std::string & name_r );
87
88         /** Find a \ref Repo named \c name_r.
89          * Returns \ref norepo if there is no such \ref Repo.
90          */
91         Repo reposFind( const std::string & name_r ) const;
92
93         /** Remove a \ref Repo named \c name_r.
94          * \see \ref Repo::eraseFromPool
95          */
96         void reposErase( const std::string & name_r )
97         { reposFind( name_r ).eraseFromPool(); }
98
99       public:
100         /** Reserved system repo name \c @System. */
101         static const std::string & systemRepoName();
102
103         /** Return the system repo. */
104         Repo systemRepo()
105         { return reposInsert( systemRepoName() ); }
106
107       public:
108         /** Load \ref Solvables from a solv-file into a \ref Repo named \c name_r.
109          * In case of an exception the \ref Repo is removed from the \ref Pool.
110          * \throws Exception if loading the solv-file fails.
111          * \see \ref Repo::EraseFromPool
112         */
113         Repo addRepoSolv( const Pathname & file_r, const std::string & name_r );
114         /** \overload Using the files basename as \ref Repo name. */
115         Repo addRepoSolv( const Pathname & file_r );
116         /** \overload Using the \ref RepoInfo::alias \ref Repo name.
117          * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
118         */
119         Repo addRepoSolv( const Pathname & file_r, const RepoInfo & info_r );
120
121       public:
122         /** Whether \ref Pool contains solvables. */
123         bool solvablesEmpty() const;
124
125         /** Number of solvables in \ref Pool. */
126         size_type solvablesSize() const;
127
128         /** Iterator to the first \ref Solvable. */
129         SolvableIterator solvablesBegin() const;
130
131         /** Iterator behind the last \ref Solvable. */
132         SolvableIterator solvablesEnd() const;
133
134       public:
135         /** Conainer of all \ref Solvable providing \c cap_r.  */
136         WhatProvides whatProvides( Capability cap_r ) const
137         { return WhatProvides( cap_r ); }
138
139       public:
140         /** \name Requested locales. */
141         //@{
142         /** Set the requested locales.
143          * Languages to be supported by the system, e.g. language specific
144          * packages to be installed.
145          */
146         void setRequestedLocales( const LocaleSet & locales_r );
147
148         /** Add one \ref Locale to the set of requested locales.
149          * Return \c true if \c locale_r was newly added to the set.
150         */
151         bool addRequestedLocale( const Locale & locale_r );
152
153         /** Erase one \ref Locale from the set of requested locales.
154         * Return \c false if \c locale_r was not found in the set.
155          */
156         bool eraseRequestedLocale( const Locale & locale_r );
157
158         /** Return the requested locales.
159          * \see \ref setRequestedLocales
160         */
161         const LocaleSet & getRequestedLocales() const;
162
163         /** Wheter this \ref Locale is in the set of requested locales. */
164         bool isRequestedLocale( const Locale & locale_r ) const;
165
166         /** Get the set of available locales.
167          * This is computed from the package data so it actually
168          * represents all locales packages claim to support.
169          */
170         const LocaleSet & getAvailableLocales() const;
171
172         /** Wheter this \ref Locale is in the set of available locales. */
173         bool isAvailableLocale( const Locale & locale_r ) const;
174         //@}
175
176       public:
177         /** Expert backdoor. */
178         ::_Pool * get() const;
179       private:
180         /** Default ctor */
181         Pool() {}
182     };
183     ///////////////////////////////////////////////////////////////////
184
185     /** \relates Pool Stream output */
186     std::ostream & operator<<( std::ostream & str, const Pool & obj );
187
188     /** \relates Pool */
189     inline bool operator==( const Pool & lhs, const Pool & rhs )
190     { return lhs.get() == rhs.get(); }
191
192     /** \relates Pool */
193     inline bool operator!=( const Pool & lhs, const Pool & rhs )
194     { return lhs.get() != rhs.get(); }
195
196     /////////////////////////////////////////////////////////////////
197   } // namespace sat
198   ///////////////////////////////////////////////////////////////////
199   /////////////////////////////////////////////////////////////////
200 } // namespace zypp
201 ///////////////////////////////////////////////////////////////////
202 #endif // ZYPP_SAT_POOL_H