4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef LYX_DOCSTREAM_H
13 #define LYX_DOCSTREAM_H
15 #include "support/docstring.h"
17 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
18 // Ugly workaround for MSVC10 STL bug:
19 // std::numpunct has a hardcoded dllimport in definition, but we wanna it with 32 bit
20 // so we can't import it and must define it but then the compiler complains.
21 #include "support/numpunct_lyx_char_type.h"
29 class iconv_codecvt_facet_exception : public std::exception {
31 virtual ~iconv_codecvt_facet_exception() throw() {}
32 virtual const char * what() const throw();
35 /// Base class for UCS4 input streams
36 typedef std::basic_istream<char_type> idocstream;
38 /** Base class for UCS4 output streams.
39 If you want to output a single UCS4 character, use \code
43 \endcode . The latter will not output the character, but the code point
44 as number if USE_WCHAR_T is not defined. This is because we can't overload
45 operator<< (our character type is not always a real type but sometimes a
46 typedef). Narrow characters of type char can be output as usual.
48 typedef std::basic_ostream<char_type> odocstream;
50 /// File stream for reading UTF8-encoded files with automatic conversion to
52 class ifdocstream : public std::basic_ifstream<char_type> {
53 typedef std::basic_ifstream<char_type> base;
56 explicit ifdocstream(const char* s,
57 std::ios_base::openmode mode = std::ios_base::in,
58 std::string const & encoding = "UTF-8");
62 /// File stream for writing files in 8bit encoding \p encoding with automatic
63 /// conversion from UCS4.
65 class ofdocstream : public std::basic_ofstream<char_type> {
66 typedef std::basic_ofstream<char_type> base;
69 explicit ofdocstream(const char* s,
70 std::ios_base::openmode mode = std::ios_base::out|std::ios_base::trunc,
71 std::string const & encoding = "UTF-8");
74 void reset(std::string const & encoding);
79 /// UCS4 input stringstream
80 typedef std::basic_istringstream<char_type> idocstringstream;
82 /// UCS4 output manipulator
83 typedef odocstream & (*odocstream_manip)(odocstream &);
86 /// Helper struct for changing stream encoding
88 SetEnc(std::string const & e) : encoding(e) {}
92 /// Helper function for changing stream encoding
93 SetEnc setEncoding(std::string const & encoding);
95 /** Change the encoding of \p os to \p e.encoding.
96 \p e.encoding must be a valid iconv name of an 8bit encoding.
97 This does nothing if the stream is not a file stream, since only
98 file streams do have an associated 8bit encoding.
100 os << setEncoding("ISO-8859-1");
103 odocstream & operator<<(odocstream & os, SetEnc e);
104 idocstream & operator<<(idocstream & os, SetEnc e);