iostream_decls.h

00001 /*
00002  *  Copyright (C) 2006  Helmut Grohne
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #ifndef LIBMUTH_IOSTREAM_DECLS_H
00020 #define LIBMUTH_IOSTREAM_DECLS_H
00021 
00022 #include <iostream>
00023 #include "basescheduler_decls.h"
00024 
00030 template<class C=char, class T=std::char_traits<C> >
00031                 class BasicScheduledStreambuf
00032                 : public std::basic_streambuf<C, T> {
00033         private:
00034                 typedef C char_type;
00035                 typedef T traits_type;
00036                 typedef typename traits_type::int_type int_type;
00037                 int fd;
00038                 BaseScheduler &sched;
00039                 std::ios_base::openmode mode;
00040                 std::streamsize ibufsize;
00041                 char_type *ibuf;
00042                 char_type *obuf;
00043         protected:
00044                 /* istreambuf */
00049                 int_type underflow();
00055                 int_type pbackfail(int_type ch);
00056                 /* ostreambuf */
00061                 int sync();
00067                 int_type overflow(int_type ch=traits_type::eof());
00068 #if 0
00069                 std::streamsize xsputn(const char_type *str, std::streamsize n);
00070 #endif
00071         public:
00080                 BasicScheduledStreambuf(int f, BaseScheduler &s,
00081                                 std::ios_base::openmode m = std::ios_base::in |
00082                                 std::ios_base::out, std::streamsize insize=4096,
00083                                 std::streamsize outsize=4096);
00084                 /* TODO: avoid copying */
00085                 ~BasicScheduledStreambuf();
00090                 operator int() const;
00091 };
00092 
00098 template<class C=char, class T=std::char_traits<C> > class BasicScheduledIStream
00099                 : public std::basic_istream<C, T> {
00100         private:
00101                 BasicScheduledStreambuf<C, T> streambuf;
00102         public:
00109                 BasicScheduledIStream(int f, BaseScheduler &s,
00110                                 std::streamsize size=4096);
00115                 operator int() const;
00116 };
00117 
00123 template<class C=char, class T=std::char_traits<C> > class BasicScheduledOStream
00124                 : public std::basic_ostream<C, T> {
00125         private:
00126                 BasicScheduledStreambuf<C, T> streambuf;
00127         public:
00134                 BasicScheduledOStream(int f, BaseScheduler &s,
00135                                 std::streamsize size=4096);
00140                 operator int() const;
00141 };
00142 
00148 template<class C=char, class T=std::char_traits<C> >
00149                 class BasicScheduledIOStream
00150                 : public std::basic_iostream<C, T> {
00151         private:
00152                 BasicScheduledStreambuf<C, T> streambuf;
00153         public:
00161                 BasicScheduledIOStream(int f, BaseScheduler &s,
00162                                 std::streamsize insize=4096,
00163                                 std::streamsize outsize=4096);
00168                 operator int() const;
00169 };
00170 
00171 typedef BasicScheduledStreambuf<> ScheduledStreambuf;
00172 typedef BasicScheduledIStream<> ScheduledIStream;
00173 typedef BasicScheduledOStream<> ScheduledOStream;
00174 typedef BasicScheduledIOStream<> ScheduledIOStream;
00175 
00176 #endif

Generated on Sat Feb 7 01:26:50 2009 by  doxygen 1.5.1