Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/io/fdstreambuf.h

Go to the documentation of this file.
00001 
00002 //  Copyright (C) 2000--2001  Petter Urkedal (petter.urkedal@matfys.lth.se)
00003 
00004 //  This file 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 file 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 //  As a special exception, you may use this file as part of a free
00019 //  software library without restriction.  Specifically, if other files
00020 //  instantiate templates or use macros or inline functions from this
00021 //  file, or you compile this file and link it with other files to
00022 //  produce an executable, this file does not by itself cause the
00023 //  resulting executable to be covered by the GNU General Public
00024 //  License.  This exception does not however invalidate any other
00025 //  reasons why the executable file might be covered by the GNU General
00026 //  Public License.
00027 
00028 //  $Id: fdstreambuf.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00029 
00030 
00031 #ifndef MORE_BITS_FDSTREAMBUF_H
00032 #define MORE_BITS_FDSTREAMBUF_H
00033 
00034 
00035 #include <ios>
00036 #include <iosfwd>
00037 #include <streambuf>
00038 
00039 //#define MORE_BITS_FDSTREAMBUF_INLINE_STORAGE 1
00040 
00041 namespace more {
00042 namespace io {
00043 
00044   ///\if bits
00045   namespace bits {
00046 
00047     template<typename CharT, typename Traits>
00048       struct basic_fdstreambuf
00049           : std::basic_streambuf<CharT, Traits>
00050       {
00051           typedef CharT char_type;
00052           typedef Traits traits_type;
00053           typedef typename Traits::int_type int_type;
00054           typedef typename Traits::pos_type pos_type;
00055           typedef typename Traits::off_type off_type;
00056 
00057           basic_fdstreambuf(int fd_in_ = -1, int fd_out_ = -1)
00058               : fd_in(fd_in_), fd_out(fd_out_) {
00059 #ifdef MORE_BITS_FDSTREAMBUF_INLINE_STORAGE
00060               setg(buf_get, buf_get, buf_get);
00061               setp(buf_put, buf_put+nbuf_put);
00062 #else
00063               setg(0, 0, 0);
00064               setp(0, 0);
00065 #endif
00066           }
00067           virtual ~basic_fdstreambuf();
00068 
00069           void set_fd_in(int fd) { setg(eback(), eback(), eback()); fd_in = fd; }
00070           void set_fd_out(int fd) { sync(); fd_out = fd; }
00071           void set_fd_io(int fd) {
00072               setg(eback(), eback(), eback());
00073               sync();
00074               fd_in = fd_out = fd;
00075           }
00076 
00077         protected:
00078           virtual int sync();
00079           virtual int_type overflow(int_type = traits_type::eof());
00080           virtual int_type underflow();
00081 
00082         private:
00083           int fd_in, fd_out;
00084           static const int nbuf_put = 512;
00085           static const int nbuf_get = 512;
00086 #ifdef MORE_BITS_FDSTREAMBUF_INLINE_STORAGE
00087           char buf_put[nbuf_put];
00088           char buf_get[nbuf_get];
00089 #endif
00090       };
00091 
00092     typedef basic_fdstreambuf< char, std::char_traits<char> > fdstreambuf;
00093   }
00094   ///\endif
00095 
00096 }
00097 }
00098 
00099 #endif

Generated on Sat Sep 7 19:11:16 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.