stdio_filebuf.h

00001 // File descriptor layer for filebuf -*- C++ -*-
00002 
00003 // Copyright (C) 2002 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 #include <fstream>
00031 
00032 namespace __gnu_cxx
00033 {
00034   template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
00035     class stdio_filebuf : public std::basic_filebuf<_CharT, _Traits>
00036     {
00037     public:
00038       // Types:
00039       typedef _CharT                                char_type;
00040       typedef _Traits                               traits_type;
00041       typedef typename traits_type::int_type        int_type;
00042       typedef typename traits_type::pos_type        pos_type;
00043       typedef typename traits_type::off_type        off_type;
00044       
00045     protected:
00046       // Stack-based buffer for unbuffered input.
00047       char_type         _M_unbuf[4];
00048       
00049     public:
00050       stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
00051             int_type __size);
00052 
00053       stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
00054             int_type __size = static_cast<int_type>(BUFSIZ));
00055 
00056       virtual
00057       ~stdio_filebuf();
00058 
00059       int
00060       fd()
00061       { return _M_file.fd(); }
00062     };
00063 
00064   template<typename _CharT, typename _Traits>
00065     stdio_filebuf<_CharT, _Traits>::~stdio_filebuf()
00066     { }
00067 
00068   template<typename _CharT, typename _Traits>
00069     stdio_filebuf<_CharT, _Traits>::
00070     stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
00071           int_type __size)
00072     {
00073       _M_file.sys_open(__fd, __mode, __del);
00074       if (this->is_open())
00075     {
00076       _M_mode = __mode;
00077       _M_buf_size_opt = __size;
00078       
00079       if (__size > 0 && __size < 4)
00080         {
00081           _M_buf = _M_unbuf;
00082           _M_buf_size = __size;
00083         }
00084       else
00085         _M_allocate_internal_buffer();
00086       
00087       _M_set_indeterminate();
00088     }
00089     }
00090 
00091   template<typename _CharT, typename _Traits>
00092     stdio_filebuf<_CharT, _Traits>::
00093     stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
00094           int_type __size)
00095     {
00096       _M_file.sys_open(__f, __mode);
00097       if (this->is_open())
00098     {
00099       _M_mode = __mode;
00100       _M_buf_size_opt = __size;
00101       
00102       if (__size > 0 && __size < 4)
00103         {
00104           _M_buf = _M_unbuf;
00105           _M_buf_size = __size;
00106         }
00107       else
00108         _M_allocate_internal_buffer();
00109       
00110       _M_set_indeterminate();
00111     }
00112     }
00113 } // namespace __gnu_cxx

Generated on Wed May 1 19:19:34 2002 for libstdc++-v3 Source by doxygen1.2.15