]> git.lyx.org Git - lyx.git/blob - src/support/docstream.h
Output docbook as utf8. Probably quite a bit more work needed, but then help form...
[lyx.git] / src / support / docstream.h
1 // -*- C++ -*-
2 /**
3  * \file docstream.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Georg Baum
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_DOCSTREAM_H
13 #define LYX_DOCSTREAM_H
14
15 #include "support/docstring.h"
16
17 #include <fstream>
18 #include <sstream>
19
20 namespace lyx {
21
22 /// Base class for UCS4 input streams
23 typedef std::basic_istream<char_type> idocstream;
24
25 /** Base class for UCS4 output streams.
26     If you want to output a single UCS4 character, use \code
27     os.put(c);
28     \endcode, not \code
29     os << c;
30     \endcode . The latter will not output the character, but the code point
31     as number. This is because we can't overload operator<< (our character
32     type is not a real type but a typedef). Narrow characters of type char
33     can be output as usual.
34  */
35 typedef std::basic_ostream<char_type> odocstream;
36
37 /// File stream for reading UTF8-encoded files with automatic conversion to
38 /// UCS4.
39 class idocfstream : public std::basic_ifstream<char_type> {
40         typedef std::basic_ifstream<char_type> base;
41 public:
42         idocfstream();
43         explicit idocfstream(const char* s,
44                 std::ios_base::openmode mode = std::ios_base::in);
45         ~idocfstream() {}
46 };
47
48 /// File stream for writing UTF8-encoded files with automatic conversion from
49 /// UCS4.
50 class odocfstream : public std::basic_ofstream<char_type> {
51         typedef std::basic_ofstream<char_type> base;
52 public:
53         odocfstream();
54         explicit odocfstream(const char* s,
55                 std::ios_base::openmode mode = std::ios_base::out|std::ios_base::trunc);
56         ~odocfstream() {}
57 };
58
59 /// UCS4 input stringstream
60 typedef std::basic_istringstream<char_type> idocstringstream;
61
62 /// UCS4 output stringstream
63 typedef std::basic_ostringstream<char_type> odocstringstream;
64
65 inline
66 odocstream & operator<<(odocstream & os, char c)
67 {
68     os.put(c);
69     return os;
70 }
71
72 }
73
74 #endif