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"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////
40 * Explicitly shared singleton \ref Pool::instance.
42 class Pool : protected detail::PoolMember
45 typedef detail::SolvableIterator SolvableIterator;
46 typedef zypp::detail::RepositoryIterator RepositoryIterator;
47 typedef detail::size_type size_type;
50 /** Singleton ctor. */
51 static Pool instance()
54 /** Ctor from \ref PoolMember. */
55 Pool( const detail::PoolMember & )
59 /** Internal array size for stats only. */
60 size_type capacity() const;
62 /** Housekeeping data serial number. */
63 const SerialNumber & serial() const;
65 /** Update housekeeping data if necessary (e.g. whatprovides). */
69 /** Whether \ref Pool contains repos. */
70 bool reposEmpty() const;
72 /** Number of repos in \ref Pool. */
73 size_type reposSize() const;
75 /** Iterator to the first \ref Repository. */
76 RepositoryIterator reposBegin() const;
78 /** Iterator behind the last \ref Repository. */
79 RepositoryIterator reposEnd() const;
81 /** Return a \ref Repository named \c name_r.
82 * It a such a \ref Repository does not already exist
83 * a new empty \ref Repository is created.
85 Repository reposInsert( const std::string & name_r );
87 /** Find a \ref Repository named \c name_r.
88 * Returns \ref norepository if there is no such \ref Repository.
90 Repository reposFind( const std::string & name_r ) const;
92 /** Remove a \ref Repository named \c name_r.
93 * \see \ref Repository::eraseFromPool
95 void reposErase( const std::string & name_r )
96 { reposFind( name_r ).eraseFromPool(); }
99 /** Reserved system repository name \c @System. */
100 static const std::string & systemRepoName();
102 /** Return the system repository if it is on the pool. */
103 Repository findSystemRepo() const
104 { return reposFind( systemRepoName() ); }
106 /** Return the system repository, create it if missing. */
107 Repository systemRepo()
108 { return reposInsert( systemRepoName() ); }
111 /** Load \ref Solvables from a solv-file into a \ref Repository named \c name_r.
112 * In case of an exception the \ref Repository is removed from the \ref Pool.
113 * \throws Exception if loading the solv-file fails.
114 * \see \ref Repository::EraseFromPool
116 Repository addRepoSolv( const Pathname & file_r, const std::string & name_r );
117 /** \overload Using the files basename as \ref Repository name. */
118 Repository addRepoSolv( const Pathname & file_r );
119 /** \overload Using the \ref RepoInfo::alias \ref Repo name.
120 * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
122 Repository addRepoSolv( const Pathname & file_r, const RepoInfo & info_r );
125 /** Whether \ref Pool contains solvables. */
126 bool solvablesEmpty() const;
128 /** Number of solvables in \ref Pool. */
129 size_type solvablesSize() const;
131 /** Iterator to the first \ref Solvable. */
132 SolvableIterator solvablesBegin() const;
134 /** Iterator behind the last \ref Solvable. */
135 SolvableIterator solvablesEnd() const;
138 /** \name Iterate all Solvables matching a \c _Filter. */
140 template<class _Filter>
141 filter_iterator<_Filter,SolvableIterator> filterBegin( const _Filter & filter_r ) const
142 { return make_filter_iterator( filter_r, solvablesBegin(), solvablesEnd() ); }
144 template<class _Filter>
145 filter_iterator<_Filter,SolvableIterator> filterEnd( const _Filter & filter_r ) const
146 { return make_filter_iterator( filter_r, solvablesEnd(), solvablesEnd() ); }
150 /** Conainer of all \ref Solvable providing \c cap_r. */
151 WhatProvides whatProvides( Capability cap_r ) const
152 { return WhatProvides( cap_r ); }
155 /** \name Requested locales. */
157 /** Set the requested locales.
158 * Languages to be supported by the system, e.g. language specific
159 * packages to be installed.
161 void setRequestedLocales( const LocaleSet & locales_r );
163 /** Add one \ref Locale to the set of requested locales.
164 * Return \c true if \c locale_r was newly added to the set.
166 bool addRequestedLocale( const Locale & locale_r );
168 /** Erase one \ref Locale from the set of requested locales.
169 * Return \c false if \c locale_r was not found in the set.
171 bool eraseRequestedLocale( const Locale & locale_r );
173 /** Return the requested locales.
174 * \see \ref setRequestedLocales
176 const LocaleSet & getRequestedLocales() const;
178 /** Wheter this \ref Locale is in the set of requested locales. */
179 bool isRequestedLocale( const Locale & locale_r ) const;
181 /** Get the set of available locales.
182 * This is computed from the package data so it actually
183 * represents all locales packages claim to support.
185 const LocaleSet & getAvailableLocales() const;
187 /** Wheter this \ref Locale is in the set of available locales. */
188 bool isAvailableLocale( const Locale & locale_r ) const;
192 /** Expert backdoor. */
193 ::_Pool * get() const;
198 ///////////////////////////////////////////////////////////////////
200 /** \relates Pool Stream output */
201 std::ostream & operator<<( std::ostream & str, const Pool & obj );
204 inline bool operator==( const Pool & lhs, const Pool & rhs )
205 { return lhs.get() == rhs.get(); }
208 inline bool operator!=( const Pool & lhs, const Pool & rhs )
209 { return lhs.get() != rhs.get(); }
211 /////////////////////////////////////////////////////////////////
213 ///////////////////////////////////////////////////////////////////
214 /////////////////////////////////////////////////////////////////
216 ///////////////////////////////////////////////////////////////////
217 #endif // ZYPP_SAT_POOL_H