1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Repository.h
12 #ifndef ZYPP_SAT_REPOSITORY_H
13 #define ZYPP_SAT_REPOSITORY_H
16 #include "zypp/base/SafeBool.h"
17 #include "zypp/Pathname.h"
18 #include "zypp/sat/detail/PoolMember.h"
19 #include "zypp/sat/Solvable.h"
20 #include "zypp/RepoInfo.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : Repository
31 class Repository : protected sat::detail::PoolMember,
32 private base::SafeBool<Repository>
35 typedef filter_iterator<detail::ByRepository, sat::detail::SolvableIterator> SolvableIterator;
36 typedef sat::detail::size_type size_type;
37 typedef sat::detail::RepoIdType IdType;
40 /** Default ctor creates \ref noRepository.*/
42 : _id( sat::detail::noRepoId ) {}
44 /** \ref PoolImpl ctor. */
45 explicit Repository( IdType id_r )
49 /** Represents no \ref Repository. */
50 static const Repository noRepository;
52 /** Evaluate \ref Repository in a boolean context (\c != \c noRepository). */
53 using base::SafeBool<Repository>::operator bool_type;
55 /** Return whether this is the system repository. */
56 bool isSystemRepo() const;
60 * Short unique, convenience string to refer to a repo.
63 * If you are looking for a label to display
64 * see \ref info() which provides \ref RepoInfo::name()
65 * ie: "openSUSE 10.3 Main repository"
68 std::string alias() const;
71 * Short unique, convenience string to refer to a repo.
74 * The sat solver uses name for what we know as alias
75 * In rpm repositories, name is a label string
76 * ie: "openSUSE 10.3 Main repository"
78 * We know follow rpm conventions and ignore satsolver
81 * Use \ref alias() instead
83 ZYPP_DEPRECATED std::string name() const
87 /** Whether \ref Repository contains solvables. */
88 bool solvablesEmpty() const;
90 /** Number of solvables in \ref Repository. */
91 size_type solvablesSize() const;
93 /** Iterator to the first \ref Solvable. */
94 SolvableIterator solvablesBegin() const;
96 /** Iterator behind the last \ref Solvable. */
97 SolvableIterator solvablesEnd() const;
100 /** Return any associated \ref RepoInfo. */
101 RepoInfo info() const;
103 /** Set \ref RepoInfo for this repository.
104 * \throws Exception if this is \ref noRepository
105 * \throws Exception if the \ref RepoInfo::alias
106 * does not match the \ref Repository::name.
108 void setInfo( const RepoInfo & info_r );
110 /** Remove any \ref RepoInfo set for this repository. */
114 /** Remove this \ref Repository from it's \ref Pool. */
115 void eraseFromPool();
117 /** Functor calling \ref eraseFromPool. */
118 struct EraseFromPool;
121 /** Return next Repository in \ref Pool (or \ref noRepository). */
122 Repository nextInPool() const;
125 /** \name Repository content manipulating methods.
126 * \todo maybe a separate Repository/Solvable content manip interface
127 * provided by the pool.
130 /** Load \ref Solvables from a solv-file.
131 * In case of an exception the repository remains in the \ref Pool.
132 * \throws Exception if this is \ref noRepository
133 * \throws Exception if loading the solv-file fails.
134 * \see \ref Pool::addRepoSolv and \ref Repository::EraseFromPool
136 void addSolv( const Pathname & file_r );
138 /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
139 sat::Solvable::IdType addSolvables( unsigned count_r );
140 /** \overload Add only one new \ref Solvable. */
141 sat::Solvable::IdType addSolvable()
142 { return addSolvables( 1 ); }
146 /** Expert backdoor. */
147 ::_Repo * get() const;
148 /** Expert backdoor. */
149 IdType id() const { return _id; }
151 friend base::SafeBool<Repository>::operator bool_type() const;
152 bool boolTest() const { return get(); }
156 ///////////////////////////////////////////////////////////////////
158 /** \relates Repository Stream output */
159 std::ostream & operator<<( std::ostream & str, const Repository & obj );
161 /** \relates Repository */
162 inline bool operator==( const Repository & lhs, const Repository & rhs )
163 { return lhs.get() == rhs.get(); }
165 /** \relates Repository */
166 inline bool operator!=( const Repository & lhs, const Repository & rhs )
167 { return lhs.get() != rhs.get(); }
169 /** \relates Repository */
170 inline bool operator<( const Repository & lhs, const Repository & rhs )
171 { return lhs.get() < rhs.get(); }
173 ///////////////////////////////////////////////////////////////////
175 // CLASS NAME : Repository::EraseFromPool
177 /** Functor removing \ref Repository from it's \ref Pool.
179 * E.g. used as dispose function in. \ref AutoDispose
180 * to provide a convenient and exception safe temporary
184 * MIL << "1 " << satpool << endl;
186 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
187 * *tmprepo = satpool.reposInsert( "A" );
188 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
189 * DBG << "2 " << satpool << endl;
190 * // Calling 'tmprepo.resetDispose();' here
191 * // would keep the Repo.
193 * MIL << "3 " << satpool << endl;
196 * 1 sat::pool(){0repos|2slov}
197 * 2 sat::pool(){1repos|2612slov}
198 * 3 sat::pool(){0repos|2slov}
200 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
201 * before, will automatically remove the \ref Repo from it's \ref Pool.
203 struct Repository::EraseFromPool
205 void operator()( Repository repository_r ) const
206 { repository_r.eraseFromPool(); }
208 ///////////////////////////////////////////////////////////////////
209 ///////////////////////////////////////////////////////////////////
211 { /////////////////////////////////////////////////////////////////
212 ///////////////////////////////////////////////////////////////////
214 // CLASS NAME : RepositoryIterator
217 class RepositoryIterator : public boost::iterator_adaptor<
218 RepositoryIterator // Derived
220 , Repository // Value
221 , boost::forward_traversal_tag // CategoryOrTraversal
222 , Repository // Reference
227 : RepositoryIterator::iterator_adaptor_( 0 )
230 explicit RepositoryIterator( ::_Repo ** p )
231 : RepositoryIterator::iterator_adaptor_( p )
235 friend class boost::iterator_core_access;
237 Repository dereference() const
238 { return Repository( *base() ); }
240 ///////////////////////////////////////////////////////////////////
241 ///////////////////////////////////////////////////////////////////
243 // CLASS NAME : ByRepository
245 /** Functor filtering \ref Solvable by \ref Repository.*/
249 ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
250 ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
253 bool operator()( const sat::Solvable & slv_r ) const
254 { return slv_r.repository() == _repository; }
257 Repository _repository;
259 ///////////////////////////////////////////////////////////////////
260 /////////////////////////////////////////////////////////////////
261 } // namespace detail
262 ///////////////////////////////////////////////////////////////////
264 /////////////////////////////////////////////////////////////////
266 ///////////////////////////////////////////////////////////////////
267 #endif // ZYPP_SAT_REPOSITORY_H