addf838a493f32b2a97716ae5690e99c78d1c145
[platform/upstream/libzypp.git] / zypp / parser / susetags / ContentFileReader.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/parser/susetags/ContentFileReader.h
10  *
11 */
12 #ifndef ZYPP_PARSER_SUSETAGS_CONTENTFILEREADER_H
13 #define ZYPP_PARSER_SUSETAGS_CONTENTFILEREADER_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/NonCopyable.h"
19 #include "zypp/base/Function.h"
20 #include "zypp/base/InputStream.h"
21
22 #include "zypp/ProgressData.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27
28   ///////////////////////////////////////////////////////////////////
29   namespace parser
30   { /////////////////////////////////////////////////////////////////
31     ///////////////////////////////////////////////////////////////////
32     namespace susetags
33     { /////////////////////////////////////////////////////////////////
34
35       class RepoIndex;
36       DEFINE_PTR_TYPE(RepoIndex);
37
38       ///////////////////////////////////////////////////////////////////
39       //
40       //        CLASS NAME : ContentFileReader
41       //
42       /** Parse repoindex part from a \c content file.
43        * This is all the downloader needs.
44       */
45       class ContentFileReader : private base::NonCopyable
46       {
47         public:
48           typedef function<void(const RepoIndex_Ptr &)> RepoIndexConsumer;
49
50         public:
51           /** Default ctor */
52           ContentFileReader();
53           /** Dtor */
54           virtual ~ContentFileReader();
55           /** Parse the stream.
56            * \throw ParseException on errors.
57            * \throw AbortRequestException on user request.
58            * Invokes \ref consume for each tag. \ref consume might throw
59            * other exceptions as well.
60            */
61           virtual void parse( const InputStream & imput_r,
62                               const ProgressData::ReceiverFnc & fnc_r = ProgressData::ReceiverFnc() );
63
64         public:
65           /** Consumer to call when repo index was parsed. */
66           void setRepoIndexConsumer( const RepoIndexConsumer & fnc_r )
67           { _repoIndexConsumer = fnc_r; }
68
69         protected:
70           /** Called when start parsing. */
71           virtual void beginParse();
72           /** Called when the parse is done. */
73           virtual void endParse();
74
75         protected:
76           /** Called when user(callback) request to abort.
77            * \throws AbortRequestException unless overloaded.
78            */
79           virtual void userRequestedAbort( unsigned lineNo_r );
80
81         protected:
82           /** Prefix exception message with line information. */
83           std::string errPrefix( unsigned lineNo_r,
84                                  const std::string & msg_r = std::string(),
85                                  const std::string & line_r = "-" ) const;
86
87         private:
88           class Impl;
89           RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
90           RepoIndexConsumer _repoIndexConsumer;
91       };
92       ///////////////////////////////////////////////////////////////////
93
94       /////////////////////////////////////////////////////////////////
95     } // namespace susetags
96     ///////////////////////////////////////////////////////////////////
97     /////////////////////////////////////////////////////////////////
98   } // namespace parser
99   ///////////////////////////////////////////////////////////////////
100   /////////////////////////////////////////////////////////////////
101 } // namespace zypp
102 ///////////////////////////////////////////////////////////////////
103 #endif // ZYPP_PARSER_SUSETAGS_CONTENTFILEREADER_H