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"
21 #include "zypp/Date.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : Repository
37 class Repository : protected sat::detail::PoolMember,
38 private base::SafeBool<Repository>
41 typedef filter_iterator<detail::ByRepository, sat::detail::SolvableIterator> SolvableIterator;
42 typedef sat::detail::size_type size_type;
43 typedef sat::detail::RepoIdType IdType;
46 /** Default ctor creates \ref noRepository.*/
48 : _id( sat::detail::noRepoId ) {}
50 /** \ref PoolImpl ctor. */
51 explicit Repository( IdType id_r )
55 /** Represents no \ref Repository. */
56 static const Repository noRepository;
58 #ifndef SWIG // Swig treats it as syntax error
59 /** Evaluate \ref Repository in a boolean context (\c != \c noRepository). */
60 using base::SafeBool<Repository>::operator bool_type;
62 /** Return whether this is the system repository. */
63 bool isSystemRepo() const;
67 * Short unique, convenience string to refer to a repo.
70 * If you are looking for a label to display
71 * see \ref info() which provides \ref RepoInfo::name()
72 * ie: "openSUSE 10.3 Main repository"
75 std::string alias() const;
78 * Short unique, convenience string to refer to a repo.
81 * The sat solver uses name for what we know as alias
82 * In rpm repositories, name is a label string
83 * ie: "openSUSE 10.3 Main repository"
85 * We know follow rpm conventions and ignore satsolver
88 * Use \ref alias() instead
90 ZYPP_DEPRECATED std::string name() const
94 * Timestamp when this repository was generated
96 * Usually this value is calculated as the newer
97 * timestamp from the timestamp of all the resources
98 * that conform the repository's metadata.
100 * For example in a rpm-md repository, it would be
101 * the resource specified in the xml file whith
102 * the newest timestamp attribute (which is the
103 * timestamp of the file in the server ).
105 * The timestamp is 0 if the repository does not
106 * specify when it was generated.
109 zypp::Date generatedTimestamp() const;
112 * Suggested expiration timestamp.
114 * Repositories can define an amount of time
115 * they expire, with the generated timestamp as
116 * the base point of time.
118 * Note that is the responsability of the repository
119 * to freshen the generated timestamp to tell the
120 * client that the repo is alive and updating the
123 * The timestamp is 0 if the repository does not specify
124 * an expiration date.
127 zypp::Date suggestedExpirationTimestamp() const;
130 * The suggested expiration date of this repository
134 bool maybeOutdated() const;
136 /** Whether \ref Repository contains solvables. */
137 bool solvablesEmpty() const;
139 /** Number of solvables in \ref Repository. */
140 size_type solvablesSize() const;
142 /** Iterator to the first \ref Solvable. */
143 SolvableIterator solvablesBegin() const;
145 /** Iterator behind the last \ref Solvable. */
146 SolvableIterator solvablesEnd() const;
149 /** Return any associated \ref RepoInfo. */
150 RepoInfo info() const;
152 /** Set \ref RepoInfo for this repository.
153 * \throws Exception if this is \ref noRepository
154 * \throws Exception if the \ref RepoInfo::alias
155 * does not match the \ref Repository::name.
157 void setInfo( const RepoInfo & info_r );
159 /** Remove any \ref RepoInfo set for this repository. */
163 /** Remove this \ref Repository from it's \ref Pool. */
164 void eraseFromPool();
166 /** Functor calling \ref eraseFromPool. */
167 struct EraseFromPool;
170 /** Return next Repository in \ref Pool (or \ref noRepository). */
171 Repository nextInPool() const;
174 /** \name Repository content manipulating methods.
175 * \todo maybe a separate Repository/Solvable content manip interface
176 * provided by the pool.
179 /** Load \ref Solvables from a solv-file.
180 * In case of an exception the repository remains in the \ref Pool.
181 * \throws Exception if this is \ref noRepository
182 * \throws Exception if loading the solv-file fails.
183 * \see \ref Pool::addRepoSolv and \ref Repository::EraseFromPool
185 void addSolv( const Pathname & file_r );
187 /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
188 sat::Solvable::IdType addSolvables( unsigned count_r );
189 /** \overload Add only one new \ref Solvable. */
190 sat::Solvable::IdType addSolvable()
191 { return addSolvables( 1 ); }
195 /** Expert backdoor. */
196 ::_Repo * get() const;
197 /** Expert backdoor. */
198 IdType id() const { return _id; }
200 #ifndef SWIG // Swig treats it as syntax error
201 friend base::SafeBool<Repository>::operator bool_type() const;
203 bool boolTest() const { return get(); }
207 ///////////////////////////////////////////////////////////////////
209 /** \relates Repository Stream output */
210 std::ostream & operator<<( std::ostream & str, const Repository & obj );
212 /** \relates Repository */
213 inline bool operator==( const Repository & lhs, const Repository & rhs )
214 { return lhs.get() == rhs.get(); }
216 /** \relates Repository */
217 inline bool operator!=( const Repository & lhs, const Repository & rhs )
218 { return lhs.get() != rhs.get(); }
220 /** \relates Repository */
221 inline bool operator<( const Repository & lhs, const Repository & rhs )
222 { return lhs.get() < rhs.get(); }
224 ///////////////////////////////////////////////////////////////////
226 // CLASS NAME : Repository::EraseFromPool
228 /** Functor removing \ref Repository from it's \ref Pool.
230 * E.g. used as dispose function in. \ref AutoDispose
231 * to provide a convenient and exception safe temporary
235 * MIL << "1 " << satpool << endl;
237 * AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
238 * *tmprepo = satpool.reposInsert( "A" );
239 * tmprepo->addSolv( "sl10.1-beta7-packages.solv" );
240 * DBG << "2 " << satpool << endl;
241 * // Calling 'tmprepo.resetDispose();' here
242 * // would keep the Repo.
244 * MIL << "3 " << satpool << endl;
247 * 1 sat::pool(){0repos|2slov}
248 * 2 sat::pool(){1repos|2612slov}
249 * 3 sat::pool(){0repos|2slov}
251 * Leaving the block without calling <tt>tmprepo.resetDispose();</tt>
252 * before, will automatically remove the \ref Repo from it's \ref Pool.
254 struct Repository::EraseFromPool
256 void operator()( Repository repository_r ) const
257 { repository_r.eraseFromPool(); }
259 ///////////////////////////////////////////////////////////////////
260 ///////////////////////////////////////////////////////////////////
262 { /////////////////////////////////////////////////////////////////
263 ///////////////////////////////////////////////////////////////////
265 // CLASS NAME : RepositoryIterator
268 class RepositoryIterator : public boost::iterator_adaptor<
269 RepositoryIterator // Derived
271 , Repository // Value
272 , boost::forward_traversal_tag // CategoryOrTraversal
273 , Repository // Reference
278 : RepositoryIterator::iterator_adaptor_( 0 )
281 explicit RepositoryIterator( ::_Repo ** p )
282 : RepositoryIterator::iterator_adaptor_( p )
286 friend class boost::iterator_core_access;
288 Repository dereference() const
289 { return Repository( *base() ); }
291 ///////////////////////////////////////////////////////////////////
292 ///////////////////////////////////////////////////////////////////
294 // CLASS NAME : ByRepository
296 /** Functor filtering \ref Solvable by \ref Repository.*/
300 ByRepository( const Repository & repository_r ) : _repository( repository_r ) {}
301 ByRepository( sat::detail::RepoIdType id_r ) : _repository( id_r ) {}
304 bool operator()( const sat::Solvable & slv_r ) const
305 { return slv_r.repository() == _repository; }
308 Repository _repository;
310 ///////////////////////////////////////////////////////////////////
311 /////////////////////////////////////////////////////////////////
312 } // namespace detail
313 ///////////////////////////////////////////////////////////////////
315 /////////////////////////////////////////////////////////////////
317 ///////////////////////////////////////////////////////////////////
318 #endif // ZYPP_SAT_REPOSITORY_H