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;
59 /** The repos name (alias).
60 * \todo FIXME why is this not called alias if it <b>is</b> alias?
62 std::string name() const;
64 /** Whether \ref Repository contains solvables. */
65 bool solvablesEmpty() const;
67 /** Number of solvables in \ref Repository. */
68 size_type solvablesSize() const;
70 /** Iterator to the first \ref Solvable. */
71 SolvableIterator solvablesBegin() const;
73 /** Iterator behind the last \ref Solvable. */
74 SolvableIterator solvablesEnd() const;
77 /** Return any associated \ref RepoInfo. */
78 RepoInfo info() const;
80 /** Set \ref RepoInfo for this repository.
81 * \throws Exception if this is \ref noRepository
82 * \throws Exception if the \ref RepoInfo::alias
83 * does not match the \ref Repository::name.
85 void setInfo( const RepoInfo & info_r );
87 /** Remove any \ref RepoInfo set for this repository. */
91 /** Remove this \ref Repository from it's \ref Pool. */
94 /** Functor calling \ref eraseFromPool. */
98 /** Return next Repository in \ref Pool (or \ref noRepository). */
99 Repository nextInPool() const;
102 /** \name Repository content manipulating methods.
103 * \todo maybe a separate Repository/Solvable content manip interface
104 * provided by the pool.
107 /** Load \ref Solvables from a solv-file.
108 * In case of an exception the repository remains in the \ref Pool.
109 * \throws Exception if this is \ref noRepository
110 * \throws Exception if loading the solv-file fails.
111 * \see \ref Pool::addRepoSolv and \ref Repository::EraseFromPool
113 void addSolv( const Pathname & file_r );
115 /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
116 sat::Solvable::IdType addSolvables( unsigned count_r );
117 /** \overload Add only one new \ref Solvable. */
118 sat::Solvable::IdType addSolvable()
119 { return addSolvables( 1 ); }
123 /** Expert backdoor. */
124 ::_Repo * get() const;
125 /** Expert backdoor. */
126 IdType id() const { return _id; }
128 friend base::SafeBool<Repository>::operator bool_type() const;
129 bool boolTest() const { return get(); }
133 ///////////////////////////////////////////////////////////////////
135 /** \relates Repository Stream output */
136 std::ostream & operator<<( std::ostream & str, const Repository & obj );
138 /** \relates Repository */
139 inline bool operator==( const Repository & lhs, const Repository & rhs )
140 { return lhs.get() == rhs.get(); }
142 /** \relates Repository */
143 inline bool operator!=( const Repository & lhs, const Repository & rhs )
144 { return lhs.get() != rhs.get(); }
146 /** \relates Repository */
147 inline bool operator<( const Repository & lhs, const Repository & rhs )
148 { return lhs.get() < rhs.get(); }
150 ///////////////////////////////////////////////////////////////////
152 // CLASS NAME : Repository::EraseFromPool
154 /** Functor removing \ref Repository from it's \ref Pool.
156 * E.g. used as dispose function in. \ref AutoDispose
157 * to provide a convenient and exception safe temporary
161 * MIL << "1 " << satpool << endl;
163 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
164 * *tmprepo = satpool.reposInsert( "A" );
165 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
166 * DBG << "2 " << satpool << endl;
167 * // Calling 'tmprepo.resetDispose();' here
168 * // would keep the Repo.
170 * MIL << "3 " << satpool << endl;
173 * 1 sat::pool(){0repos|2slov}
174 * 2 sat::pool(){1repos|2612slov}
175 * 3 sat::pool(){0repos|2slov}
177 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
178 * before, will automatically remove the \ref Repo from it's \ref Pool.
180 struct Repository::EraseFromPool
182 void operator()( Repository repository_r ) const
183 { repository_r.eraseFromPool(); }
185 ///////////////////////////////////////////////////////////////////
186 ///////////////////////////////////////////////////////////////////
188 { /////////////////////////////////////////////////////////////////
189 ///////////////////////////////////////////////////////////////////
191 // CLASS NAME : RepositoryIterator
194 class RepositoryIterator : public boost::iterator_adaptor<
195 RepositoryIterator // Derived
197 , Repository // Value
198 , boost::forward_traversal_tag // CategoryOrTraversal
199 , Repository // Reference
204 : RepositoryIterator::iterator_adaptor_( 0 )
207 explicit RepositoryIterator( ::_Repo ** p )
208 : RepositoryIterator::iterator_adaptor_( p )
212 friend class boost::iterator_core_access;
214 Repository dereference() const
215 { return Repository( *base() ); }
217 ///////////////////////////////////////////////////////////////////
218 ///////////////////////////////////////////////////////////////////
220 // CLASS NAME : ByRepository
222 /** Functor filtering \ref Solvable by \ref Repository.*/
226 ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
227 ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
230 bool operator()( const sat::Solvable & slv_r ) const
231 { return slv_r.repository() == _repository; }
234 Repository _repository;
236 ///////////////////////////////////////////////////////////////////
237 /////////////////////////////////////////////////////////////////
238 } // namespace detail
239 ///////////////////////////////////////////////////////////////////
241 /////////////////////////////////////////////////////////////////
243 ///////////////////////////////////////////////////////////////////
244 #endif // ZYPP_SAT_REPOSITORY_H