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 ) );
44 friend std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
48 * Callback definition.
49 * First parameter is a \ref RepoInfo object with the resource
50 * second parameter is the resource type.
52 * Return false from the callback to get a \ref AbortRequestException
53 * to be thrown and the processing to be cancelled.
55 typedef function< bool( const RepoInfo & )> ProcessRepo;
62 * \short Constructor. Creates the reader and start reading.
64 * \param repo_file A valid .repo file
65 * \param callback Callback that will be called for each repository.
66 * \param progress Optional progress function. \see ProgressData
68 * \throws AbortRequestException If the callback returns false
69 * \throws Exception If a error occurs at reading / parsing
72 RepoFileReader( const Pathname & repo_file,
73 const ProcessRepo & callback,
74 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
77 * \short Constructor. Creates the reader and start reading.
79 * \param is A valid input stream
80 * \param callback Callback that will be called for each repository.
81 * \param progress Optional progress function. \see ProgressData
83 * \throws AbortRequestException If the callback returns false
84 * \throws Exception If a error occurs at reading / parsing
87 RepoFileReader( const InputStream &is,
88 const ProcessRepo & callback,
89 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
96 ProcessRepo _callback;
98 ///////////////////////////////////////////////////////////////////
100 /** \relates RepoFileReader Stream output */
101 std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
103 /////////////////////////////////////////////////////////////////
104 } // namespace parser
105 ///////////////////////////////////////////////////////////////////
106 /////////////////////////////////////////////////////////////////
108 ///////////////////////////////////////////////////////////////////
109 #endif // ZYPP_REPO_REPOFILEREADER_H