1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/repo/RepoFileReader.h
12 #ifndef ZYPP_REPO_REPOFILEREADER_H
13 #define ZYPP_REPO_REPOFILEREADER_H
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/InputStream.h"
19 #include "zypp/RepoInfo.h"
20 #include "zypp/ProgressData.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
30 * \short Read repository data from a .repo file
32 * After each repo is read, a \ref RepoInfo is prepared and \ref _callback
33 * is called with the object passed in.
35 * The \ref _callback is provided on construction.
38 * RepoFileReader reader(repo_file,
39 * bind( &SomeClass::callbackfunc, &SomeClassInstance, _1, _2 ) );
42 * \note Multiple baseurls in a repo file are supported using this style:
44 * baseurl=http://server.a/path/to/repo
45 * http://server.b/path/to/repo
46 * http://server.c/path/to/repo
48 * Repeating the \c baseurl= tag on each line is also accepted, but when the
49 * file has to be written, the preferred style is used.
53 friend std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
57 * Callback definition.
58 * First parameter is a \ref RepoInfo object with the resource
59 * second parameter is the resource type.
61 * Return false from the callback to get a \ref AbortRequestException
62 * to be thrown and the processing to be cancelled.
64 typedef function< bool( const RepoInfo & )> ProcessRepo;
71 * \short Constructor. Creates the reader and start reading.
73 * \param repo_file A valid .repo file
74 * \param callback Callback that will be called for each repository.
75 * \param progress Optional progress function. \see ProgressData
77 * \throws AbortRequestException If the callback returns false
78 * \throws Exception If a error occurs at reading / parsing
81 RepoFileReader( const Pathname & repo_file,
82 const ProcessRepo & callback,
83 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
86 * \short Constructor. Creates the reader and start reading.
88 * \param is A valid input stream
89 * \param callback Callback that will be called for each repository.
90 * \param progress Optional progress function. \see ProgressData
92 * \throws AbortRequestException If the callback returns false
93 * \throws Exception If a error occurs at reading / parsing
96 RepoFileReader( const InputStream &is,
97 const ProcessRepo & callback,
98 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
105 ProcessRepo _callback;
107 ///////////////////////////////////////////////////////////////////
109 /** \relates RepoFileReader Stream output */
110 std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
112 /////////////////////////////////////////////////////////////////
113 } // namespace parser
114 ///////////////////////////////////////////////////////////////////
115 /////////////////////////////////////////////////////////////////
117 ///////////////////////////////////////////////////////////////////
118 #endif // ZYPP_REPO_REPOFILEREADER_H