Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/cxxtools/include/cxxtools/hdstream.h

00001 /*
00002  * Copyright (C) 2003 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6