Vaucanson  1.4.1
ios.hh
Go to the documentation of this file.
1 // ios.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2004, 2005, 2006, 2008, 2009 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 
18 #ifndef VCSN_XML_INTERNAL_IOS_HH
19 # define VCSN_XML_INTERNAL_IOS_HH
20 
29 # include <iostream>
30 
31 # include <xercesc/dom/DOM.hpp>
32 # include <xercesc/util/BinInputStream.hpp>
33 # include <xercesc/sax/InputSource.hpp>
34 # include <xercesc/framework/XMLFormatter.hpp>
35 
37 # if (XERCES_VERSION_MAJOR == 2)
38 # define XMLSize_t unsigned int
39 # define XERCES_FILEPOS XMLSize_t
40 # elif (XERCES_VERSION_MAJOR > 2)
41 # define XERCES_FILEPOS XMLFilePos
42 # else
43 # error "Unsupported Xerces-C++ major version (too old)."
44 # endif
45 
46 XERCES_CPP_NAMESPACE_BEGIN
47 
55 template<class Ostream>
56 class XMLPARSER_EXPORT XMLXercesStream : public XMLFormatTarget
57 {
58 public:
59 
62  XMLXercesStream(std::ostream& os) : os_(os) {};
63  ~XMLXercesStream() {};
65 
69  virtual void writeChars(const XMLByte* const toWrite,
70  const XMLSize_t,
71  XMLFormatter* const);
72 
73  virtual void flush() {};
74 
75 private:
80  XMLXercesStream& operator=(const XMLXercesStream&);
81 
82  Ostream& os_;
83 };
84 
85 XERCES_CPP_NAMESPACE_END
86 
87 namespace vcsn
88 {
89  namespace xml
90  {
91  class BinCxxInputStream : public xercesc::BinInputStream
92  {
93  private:
94  std::istream* _in;
95  unsigned int _pos;
96 
97  public:
98  BinCxxInputStream(std::istream* in) : _in(in), _pos(0) { }
99  virtual XERCES_FILEPOS curPos() const;
100  virtual XMLSize_t readBytes(XMLByte *const toFill,
101  const XMLSize_t maxToRead);
102  virtual const XMLCh* getContentType () const { return 0; }
103  };
104 
105  class CxxInputSource : public xercesc::InputSource
106  {
107  private:
108  std::istream* _in;
109 
110  public:
111  CxxInputSource(std::istream* in) : InputSource(), _in(in) {}
112  virtual BinCxxInputStream* makeStream() const;
113  };
114 
115  void print_xml(std::ostream& out,
116  xercesc::DOMImplementation* impl,
117  xercesc::DOMElement* root);
118 
119  } // ! xml
120 
121 } // ! vcsn
122 
123 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
124 # include <vaucanson/xml/internal/ios.hxx>
125 # endif // !VCSN_USE_INTERFACE_ONLY || VCSN_USE_LIB
126 
127 #endif // ! VCSN_XML_IOS_HH