00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CXXTOOLS_ICONVSTREAM_H
00023 #define CXXTOOLS_ICONVSTREAM_H
00024
00025 #include <iostream>
00026 #include <iconv.h>
00027
00028 namespace cxxtools
00029 {
00030
00035 class iconvstreambuf : public std::streambuf
00036 {
00037 std::ostream* sink;
00038 iconv_t cd;
00039 char buffer[256];
00040
00041 public:
00042 iconvstreambuf()
00043 : sink(0),
00044 cd((iconv_t)-1)
00045 { }
00046 ~iconvstreambuf()
00047 { close(); }
00048
00049 iconvstreambuf* open(std::ostream& sink_,
00050 const char* tocode, const char* fromcode);
00051 iconvstreambuf* close() throw();
00052
00054 int_type overflow(int_type c);
00056 int_type underflow();
00058 int sync();
00059
00060 };
00061
00081 class iconvstream : public std::ostream
00082 {
00083 iconvstreambuf streambuf;
00084
00085 public:
00086 iconvstream(std::ostream& sink, const char* tocode, const char* fromcode)
00087 : std::ostream(0)
00088 {
00089 init(&streambuf);
00090 open(sink, tocode, fromcode);
00091 }
00092 iconvstream()
00093 : std::ostream(0)
00094 {
00095 init(&streambuf);
00096 }
00097
00098 void open(std::ostream& sink_,
00099 const char* tocode, const char* fromcode);
00100 void close() throw()
00101 { streambuf.close(); }
00102 };
00103
00104 }
00105
00106 #endif // CXXTOOLS_ICONVSTREAM_H
00107