1 /* parserinputbuffer.h
2  * this file is part of libxml++
3  *
4  * copyright (C) 2003 by libxml++ developer's team
5  *
6  * this file is covered by the GNU Lesser General Public License,
7  * which should be included with libxml++ as the file COPYING.
8  */
9 
10 #ifndef __LIBXMLPP_PARSERINPUTBUFFER_H
11 #define __LIBXMLPP_PARSERINPUTBUFFER_H
12 
13 #include <string>
14 #include <libxml++/noncopyable.h>
15 
16 extern "C"
17 {
18   struct _xmlParserInputBuffer;
19 }
20 
21 namespace xmlpp
22 {
23   struct ParserInputBufferCallback;
24 
25   /** Base class for xmlParserInputBuffer wrapper
26    *
27    * It can be derived from to create a new output buffer.
28    * A child class has to override do_write(), and possibly
29    * do_close() if some actions are required before buffer closing.
30    */
31   class ParserInputBuffer: public NonCopyable
32   {
33     public:
34       ParserInputBuffer();
35       ~ParserInputBuffer() override;
36 
37     public:
38       /** gives an access to the underlying libxml structure to the children
39        */
40       _xmlParserInputBuffer* cobj();
41 
42       /** gives an access to the underlying libxml structure to the children
43        */
44       const _xmlParserInputBuffer* cobj() const;
45 
46     private:
47       int on_read(char * buffer, int len);
48       bool on_close();
49 
50       /** Function called when some data are read from the buffer.
51        * @param buffer The datas encoded in the charset given to the constructor
52        * @param len bytes to read
53        * @return Number of bytes read
54        *
55        * This function MUST be overriden in derived classes.
56        */
57       virtual int do_read(char * buffer, int len) = 0;
58 
59       /** Function called before closing the buffer.
60        * Derived classes should override it if some actions are required before
61        * closing the buffer, instead of doing them in the destructor.
62        */
63       virtual bool do_close();
64 
65       /**
66        * Underlying libxml2 structure.
67        */
68       _xmlParserInputBuffer* impl_;
69 
70       friend struct ParserInputBufferCallback;
71   };
72 
73 }
74 
75 #endif
76