Imported Upstream version 14.30.0
[platform/upstream/libzypp.git] / zypp / parser / RepoFileReader.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/repo/RepoFileReader.h
10  *
11 */
12 #ifndef ZYPP_REPO_REPOFILEREADER_H
13 #define ZYPP_REPO_REPOFILEREADER_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/InputStream.h"
19 #include "zypp/RepoInfo.h"
20 #include "zypp/ProgressData.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25   ///////////////////////////////////////////////////////////////////
26   namespace parser
27   { /////////////////////////////////////////////////////////////////
28
29     /**
30      * \short Read repository data from a .repo file
31      *
32      * After each repo is read, a \ref RepoInfo is prepared and \ref _callback
33      * is called with the object passed in.
34      *
35      * The \ref _callback is provided on construction.
36      *
37      * \code
38      * RepoFileReader reader(repo_file,
39      *                bind( &SomeClass::callbackfunc, &SomeClassInstance, _1, _2 ) );
40      * \endcode
41      *
42      * \note Multiple baseurls in a repo file are supported using this style:
43      * \code
44      * baseurl=http://server.a/path/to/repo
45      *         http://server.b/path/to/repo
46      *         http://server.c/path/to/repo
47      * \endcode
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.
50      */
51     class RepoFileReader
52     {
53       friend std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
54     public:
55
56      /**
57       * Callback definition.
58       * First parameter is a \ref RepoInfo object with the resource
59       * second parameter is the resource type.
60       *
61       * Return false from the callback to get a \ref AbortRequestException
62       * to be thrown and the processing to be cancelled.
63       */
64       typedef function< bool( const RepoInfo & )> ProcessRepo;
65
66       /** Implementation  */
67       class Impl;
68
69     public:
70      /**
71       * \short Constructor. Creates the reader and start reading.
72       *
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
76       *
77       * \throws AbortRequestException If the callback returns false
78       * \throws Exception If a error occurs at reading / parsing
79       *
80       */
81       RepoFileReader( const Pathname & repo_file,
82                       const ProcessRepo & callback,
83                       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
84
85      /**
86       * \short Constructor. Creates the reader and start reading.
87       *
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
91       *
92       * \throws AbortRequestException If the callback returns false
93       * \throws Exception If a error occurs at reading / parsing
94       *
95       */
96       RepoFileReader( const InputStream &is,
97                       const ProcessRepo & callback,
98                       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
99
100       /**
101        * Dtor
102        */
103       ~RepoFileReader();
104     private:
105       ProcessRepo _callback;
106     };
107     ///////////////////////////////////////////////////////////////////
108
109     /** \relates RepoFileReader Stream output */
110     std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
111
112     /////////////////////////////////////////////////////////////////
113   } // namespace parser
114   ///////////////////////////////////////////////////////////////////
115   /////////////////////////////////////////////////////////////////
116 } // namespace zypp
117 ///////////////////////////////////////////////////////////////////
118 #endif // ZYPP_REPO_REPOFILEREADER_H