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