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_HDSTREAM_H
00030 #define CXXTOOLS_HDSTREAM_H
00031
00032 #include <iostream>
00033
00034 namespace cxxtools
00035 {
00036
00037 class Hdstreambuf : public std::streambuf
00038 {
00039 static const unsigned BUFFERSIZE = 16;
00040
00041 std::streambuf::int_type overflow(std::streambuf::int_type ch);
00042 std::streambuf::int_type underflow();
00043 int sync();
00044
00045 char Buffer[BUFFERSIZE];
00046 std::streambuf* Dest;
00047 unsigned offset;
00048
00049 public:
00050 Hdstreambuf(std::streambuf* dest)
00051 : Dest(dest),
00052 offset(0)
00053 {
00054 setp(Buffer, Buffer + BUFFERSIZE);
00055 }
00056
00057 unsigned getOffset() const { return offset; }
00058 void setOffset(unsigned offset_) { offset = offset_; }
00059 };
00060
00066 class Hdostream : public std::ostream
00067 {
00068 typedef std::ostream base_class;
00069 Hdstreambuf streambuf;
00070
00071 public:
00072 Hdostream()
00073 : base_class(0),
00074 streambuf(std::cout.rdbuf())
00075 {
00076 init(&streambuf);
00077 }
00078 Hdostream(std::ostream& out)
00079 : base_class(0),
00080 streambuf(out.rdbuf())
00081 {
00082 init(&streambuf);
00083 }
00084
00085 unsigned getOffset() const { return streambuf.getOffset(); }
00086 void setOffset(unsigned offset_) { streambuf.setOffset(offset_); }
00087 };
00088
00089 }
00090
00091 #endif // CXXTOOLS_HDSTREAM_H