# streambuf.tcc

Go to the documentation of this file.

    00001 // Stream buffer classes -*- C++ -*-
    00002
    00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    00004 // Free Software Foundation, Inc.
    00005 //
    00006 // This file is part of the GNU ISO C++ Library.  This library is free
    00007 // software; you can redistribute it and/or modify it under the
    00008 // terms of the GNU General Public License as published by the
    00009 // Free Software Foundation; either version 2, or (at your option)
    00010 // any later version.
    00011
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015 // GNU General Public License for more details.
    00016
    00017 // You should have received a copy of the GNU General Public License along
    00018 // with this library; see the file COPYING.  If not, write to the Free
    00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00020 // USA.
    00021
    00022 // As a special exception, you may use this file as part of a free software
    00023 // library without restriction.  Specifically, if other files instantiate
    00024 // templates or use macros or inline functions from this file, or you compile
    00025 // this file and link it with other files to produce an executable, this
    00026 // file does not by itself cause the resulting executable to be covered by
    00027 // the GNU General Public License.  This exception does not however
    00028 // invalidate any other reasons why the executable file might be covered by
    00029 // the GNU General Public License.
    00030
    00031 /** @file streambuf.tcc
    00032  *  This is an internal header file, included by other library headers.
    00033  *  You should not attempt to use it directly.
    00034  */
    00035
    00036 //
    00037 // ISO C++ 14882: 27.5  Stream buffers
    00038 //
    00039
    00040 #ifndef _STREAMBUF_TCC
    00041 #define _STREAMBUF_TCC 1
    00042
    00043 #pragma GCC system_header
    00044
    00045 _GLIBCXX_BEGIN_NAMESPACE(std)
    00046
    00047   template<typename _CharT, typename _Traits>
    00048     streamsize
    00049     basic_streambuf<_CharT, _Traits>::
    00050     xsgetn(char_type* __s, streamsize __n)
    00051     {
    00052       streamsize __ret = 0;
    00053       while (__ret < __n)
    00054     {
    00055       const streamsize __buf_len = this->egptr() - this->gptr();
    00056       if (__buf_len)
    00057         {
    00058           const streamsize __remaining = __n - __ret;
    00059           const streamsize __len = std::min(__buf_len, __remaining);
    00060           traits_type::copy(__s, this->gptr(), __len);
    00061           __ret += __len;
    00062           __s += __len;
    00063           this->gbump(__len);
    00064         }
    00065
    00066       if (__ret < __n)
    00067         {
    00068           const int_type __c = this->uflow();
    00069           if (!traits_type::eq_int_type(__c, traits_type::eof()))
    00070         {
    00071           traits_type::assign(*__s++, traits_type::to_char_type(__c));
    00072           ++__ret;
    00073         }
    00074           else
    00075         break;
    00076         }
    00077     }
    00078       return __ret;
    00079     }
    00080
    00081   template<typename _CharT, typename _Traits>
    00082     streamsize
    00083     basic_streambuf<_CharT, _Traits>::
    00084     xsputn(const char_type* __s, streamsize __n)
    00085     {
    00086       streamsize __ret = 0;
    00087       while (__ret < __n)
    00088     {
    00089       const streamsize __buf_len = this->epptr() - this->pptr();
    00090       if (__buf_len)
    00091         {
    00092           const streamsize __remaining = __n - __ret;
    00093           const streamsize __len = std::min(__buf_len, __remaining);
    00094           traits_type::copy(this->pptr(), __s, __len);
    00095           __ret += __len;
    00096           __s += __len;
    00097           this->pbump(__len);
    00098         }
    00099
    00100       if (__ret < __n)
    00101         {
    00102           int_type __c = this->overflow(traits_type::to_int_type(*__s));
    00103           if (!traits_type::eq_int_type(__c, traits_type::eof()))
    00104         {
    00105           ++__ret;
    00106           ++__s;
    00107         }
    00108           else
    00109         break;
    00110         }
    00111     }
    00112       return __ret;
    00113     }
    00114
    00115   // Conceivably, this could be used to implement buffer-to-buffer
    00116   // copies, if this was ever desired in an un-ambiguous way by the
    00117   // standard.
    00118   template<typename _CharT, typename _Traits>
    00119     streamsize
    00120     __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
    00121               basic_streambuf<_CharT, _Traits>* __sbout,
    00122               bool& __ineof)
    00123     {
    00124       streamsize __ret = 0;
    00125       __ineof = true;
    00126       typename _Traits::int_type __c = __sbin->sgetc();
    00127       while (!_Traits::eq_int_type(__c, _Traits::eof()))
    00128     {
    00129       __c = __sbout->sputc(_Traits::to_char_type(__c));
    00130       if (_Traits::eq_int_type(__c, _Traits::eof()))
    00131         {
    00132           __ineof = false;
    00133           break;
    00134         }
    00135       ++__ret;
    00136       __c = __sbin->snextc();
    00137     }
    00138       return __ret;
    00139     }
    00140
    00141   template<typename _CharT, typename _Traits>
    00142     inline streamsize
    00143     __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
    00144               basic_streambuf<_CharT, _Traits>* __sbout)
    00145     {
    00146       bool __ineof;
    00147       return __copy_streambufs_eof(__sbin, __sbout, __ineof);
    00148     }
    00149
    00150   // Inhibit implicit instantiations for required instantiations,
    00151   // which are defined via explicit instantiations elsewhere.
    00152   // NB:  This syntax is a GNU extension.
    00153 #if _GLIBCXX_EXTERN_TEMPLATE
    00154   extern template class basic_streambuf<char>;
    00155   extern template
    00156     streamsize
    00157     __copy_streambufs(basic_streambuf<char>*,
    00158               basic_streambuf<char>*);
    00159   extern template
    00160     streamsize
    00161     __copy_streambufs_eof(basic_streambuf<char>*,
    00162               basic_streambuf<char>*, bool&);
    00163
    00164 #ifdef _GLIBCXX_USE_WCHAR_T
    00165   extern template class basic_streambuf<wchar_t>;
    00166   extern template
    00167     streamsize
    00168     __copy_streambufs(basic_streambuf<wchar_t>*,
    00169               basic_streambuf<wchar_t>*);
    00170   extern template
    00171     streamsize
    00172     __copy_streambufs_eof(basic_streambuf<wchar_t>*,
    00173               basic_streambuf<wchar_t>*, bool&);
    00174 #endif
    00175 #endif
    00176
    00177 _GLIBCXX_END_NAMESPACE
    00178
    00179 #endif