Merge branch 'local_services' of gitorious.org:~duncan/opensuse/duncans-libzypp
[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     class RepoFileReader
43     {
44       friend std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
45     public:
46       
47      /**
48       * Callback definition.
49       * First parameter is a \ref RepoInfo object with the resource
50       * second parameter is the resource type.
51       *
52       * Return false from the callback to get a \ref AbortRequestException
53       * to be thrown and the processing to be cancelled.
54       */
55       typedef function< bool( const RepoInfo & )> ProcessRepo;
56       
57       /** Implementation  */
58       class Impl;
59
60     public:
61      /**
62       * \short Constructor. Creates the reader and start reading.
63       *
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
67       *
68       * \throws AbortRequestException If the callback returns false
69       * \throws Exception If a error occurs at reading / parsing
70       *
71       */
72       RepoFileReader( const Pathname & repo_file,
73                       const ProcessRepo & callback,
74                       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
75
76      /**
77       * \short Constructor. Creates the reader and start reading.
78       *
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
82       *
83       * \throws AbortRequestException If the callback returns false
84       * \throws Exception If a error occurs at reading / parsing
85       *
86       */
87       RepoFileReader( const InputStream &is,
88                       const ProcessRepo & callback,
89                       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
90      
91       /**
92        * Dtor
93        */
94       ~RepoFileReader();
95     private:
96       ProcessRepo _callback;
97     };
98     ///////////////////////////////////////////////////////////////////
99
100     /** \relates RepoFileReader Stream output */
101     std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj );
102
103     /////////////////////////////////////////////////////////////////
104   } // namespace parser
105   ///////////////////////////////////////////////////////////////////
106   /////////////////////////////////////////////////////////////////
107 } // namespace zypp
108 ///////////////////////////////////////////////////////////////////
109 #endif // ZYPP_REPO_REPOFILEREADER_H