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_BASE64STREAM_H
00030 #define CXXTOOLS_BASE64STREAM_H
00031
00032 #include <iostream>
00033
00034 namespace cxxtools
00035 {
00036
00037 class Base64stream_streambuf : public std::streambuf
00038 {
00039 std::streambuf* sinksource;
00040 char obuffer[3];
00041 char decodebuf[3];
00042 unsigned count;
00043 bool indecode;
00044 bool eofflag;
00045
00046 public:
00047 Base64stream_streambuf(std::streambuf* sinksource_)
00048 : sinksource(sinksource_),
00049 count(0),
00050 indecode(false),
00051 eofflag(false)
00052 { }
00053 ~Base64stream_streambuf()
00054 { if (indecode) end(); }
00055
00056 void end();
00057 void reset() { eofflag = false; }
00058
00059 protected:
00060 std::streambuf::int_type overflow(std::streambuf::int_type ch);
00061 std::streambuf::int_type underflow();
00062 int sync();
00063
00064 private:
00065 void putChar(char ch);
00066 int getval();
00067 };
00068
00079 class Base64ostream : public std::ostream
00080 {
00081 Base64stream_streambuf streambuf;
00082
00083 public:
00086 Base64ostream(std::ostream& out)
00087 : std::ostream(0),
00088 streambuf(out.rdbuf())
00089 {
00090 init(&streambuf);
00091 }
00093 Base64ostream(std::streambuf* sb)
00094 : std::ostream(0),
00095 streambuf(sb)
00096 {
00097 init(&streambuf);
00098 }
00099
00101 void end() { streambuf.end(); }
00102 };
00103
00112 class Base64istream : public std::istream
00113 {
00114 Base64stream_streambuf streambuf;
00115
00116 public:
00117 Base64istream(std::istream& in)
00118 : std::istream(0),
00119 streambuf(in.rdbuf())
00120 { init(&streambuf); }
00121 Base64istream(std::streambuf* sb)
00122 : std::istream(0),
00123 streambuf(sb)
00124 { init(&streambuf); }
00125
00128 void reset() { streambuf.reset(); }
00129 };
00130
00131 }
00132
00133 #endif // CXXTOOLS_BASE64STREAM_H
00134