~ubuntu-branches/ubuntu/precise/libxml++2.6/precise

« back to all changes in this revision

Viewing changes to libxml++/io/parserinputbuffer.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-03-13 15:46:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050313154633-iubyqdtu6y3p8915
Tags: 2.10.0-0ubuntu2
added doxygen to the build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* document.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
#include <libxml++/io/parserinputbuffer.h>
 
11
#include <libxml++/exceptions/internal_error.h>
 
12
 
 
13
#include <libxml/globals.h> //Needed by libxml/xmlIO.h
 
14
#include <libxml/xmlIO.h>
 
15
 
 
16
namespace xmlpp
 
17
{
 
18
 
 
19
  struct ParserInputBufferCallback
 
20
  {
 
21
    static int on_read(void * context, char * buffer, int len)
 
22
    {
 
23
      ParserInputBuffer * tmp = static_cast<ParserInputBuffer*>(context);
 
24
      return tmp->do_read(buffer, len);
 
25
    }
 
26
 
 
27
    static int on_close(void * context)
 
28
    {
 
29
      ParserInputBuffer * tmp = static_cast<ParserInputBuffer*>(context);
 
30
      return tmp->do_close();
 
31
    }
 
32
  };
 
33
 
 
34
 
 
35
  ParserInputBuffer::ParserInputBuffer()
 
36
  {
 
37
    impl_ = xmlParserInputBufferCreateIO(
 
38
        &ParserInputBufferCallback::on_read,
 
39
        &ParserInputBufferCallback::on_close,
 
40
        static_cast<void*>(this),
 
41
        XML_CHAR_ENCODING_NONE);
 
42
    if(impl_ == NULL)
 
43
    {
 
44
      throw internal_error("Cannot initialise underlying xmlParserInputBuffer");
 
45
    }
 
46
  }
 
47
 
 
48
  ParserInputBuffer::~ParserInputBuffer()
 
49
  {
 
50
  }
 
51
 
 
52
  bool ParserInputBuffer::on_close()
 
53
  {
 
54
    bool result = do_close();
 
55
    // the underlying structure is being freed by libxml, the pointer will soon be
 
56
    // invalid.
 
57
    impl_ = 0;
 
58
 
 
59
    return result;
 
60
  }
 
61
 
 
62
  int ParserInputBuffer::on_read(
 
63
      char * buffer,
 
64
      int len)
 
65
  {
 
66
    return do_read(buffer, len);
 
67
  }
 
68
 
 
69
  bool ParserInputBuffer::do_close()
 
70
  {
 
71
    return true;
 
72
  }
 
73
 
 
74
  _xmlParserInputBuffer* ParserInputBuffer::cobj()
 
75
  {
 
76
    return impl_;
 
77
  }
 
78
 
 
79
  const _xmlParserInputBuffer* ParserInputBuffer::cobj() const
 
80
  {
 
81
    return impl_;
 
82
  }
 
83
 
 
84
};