1 // Stream buffer classes -*- C++ -*-
 
    3 // Copyright (C) 1997-2014 Free Software Foundation, Inc.
 
    5 // This file is part of the GNU ISO C++ Library.  This library is free
 
    6 // software; you can redistribute it and/or modify it under the
 
    7 // terms of the GNU General Public License as published by the
 
    8 // Free Software Foundation; either version 3, or (at your option)
 
   11 // This library is distributed in the hope that it will be useful,
 
   12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
   13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
   14 // GNU General Public License for more details.
 
   16 // Under Section 7 of GPL version 3, you are granted additional
 
   17 // permissions described in the GCC Runtime Library Exception, version
 
   18 // 3.1, as published by the Free Software Foundation.
 
   20 // You should have received a copy of the GNU General Public License and
 
   21 // a copy of the GCC Runtime Library Exception along with this program;
 
   22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
   23 // <http://www.gnu.org/licenses/>.
 
   25 /** @file bits/streambuf.tcc
 
   26  *  This is an internal header file, included by other library headers.
 
   27  *  Do not attempt to use it directly. @headername{streambuf}
 
   31 // ISO C++ 14882: 27.5  Stream buffers
 
   34 #ifndef _STREAMBUF_TCC
 
   35 #define _STREAMBUF_TCC 1
 
   37 #pragma GCC system_header
 
   39 namespace std _GLIBCXX_VISIBILITY(default)
 
   41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   43   template<typename _CharT, typename _Traits>
 
   45     basic_streambuf<_CharT, _Traits>::
 
   46     xsgetn(char_type* __s, streamsize __n)
 
   51      const streamsize __buf_len = this->egptr() - this->gptr();
 
   54          const streamsize __remaining = __n - __ret;
 
   55          const streamsize __len = std::min(__buf_len, __remaining);
 
   56          traits_type::copy(__s, this->gptr(), __len);
 
   59          this->__safe_gbump(__len);
 
   64          const int_type __c = this->uflow();
 
   65          if (!traits_type::eq_int_type(__c, traits_type::eof()))
 
   67          traits_type::assign(*__s++, traits_type::to_char_type(__c));
 
   77   template<typename _CharT, typename _Traits>
 
   79     basic_streambuf<_CharT, _Traits>::
 
   80     xsputn(const char_type* __s, streamsize __n)
 
   85      const streamsize __buf_len = this->epptr() - this->pptr();
 
   88          const streamsize __remaining = __n - __ret;
 
   89          const streamsize __len = std::min(__buf_len, __remaining);
 
   90          traits_type::copy(this->pptr(), __s, __len);
 
   93          this->__safe_pbump(__len);
 
   98          int_type __c = this->overflow(traits_type::to_int_type(*__s));
 
   99          if (!traits_type::eq_int_type(__c, traits_type::eof()))
 
  111   // Conceivably, this could be used to implement buffer-to-buffer
 
  112   // copies, if this was ever desired in an un-ambiguous way by the
 
  114   template<typename _CharT, typename _Traits>
 
  116     __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
 
  117              basic_streambuf<_CharT, _Traits>* __sbout,
 
  120       streamsize __ret = 0;
 
  122       typename _Traits::int_type __c = __sbin->sgetc();
 
  123       while (!_Traits::eq_int_type(__c, _Traits::eof()))
 
  125      __c = __sbout->sputc(_Traits::to_char_type(__c));
 
  126      if (_Traits::eq_int_type(__c, _Traits::eof()))
 
  132      __c = __sbin->snextc();
 
  137   template<typename _CharT, typename _Traits>
 
  139     __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
 
  140              basic_streambuf<_CharT, _Traits>* __sbout)
 
  143       return __copy_streambufs_eof(__sbin, __sbout, __ineof);
 
  146   // Inhibit implicit instantiations for required instantiations,
 
  147   // which are defined via explicit instantiations elsewhere.
 
  148 #if _GLIBCXX_EXTERN_TEMPLATE
 
  149   extern template class basic_streambuf<char>;
 
  152     __copy_streambufs(basic_streambuf<char>*,
 
  153              basic_streambuf<char>*);
 
  156     __copy_streambufs_eof(basic_streambuf<char>*,
 
  157              basic_streambuf<char>*, bool&);
 
  159 #ifdef _GLIBCXX_USE_WCHAR_T
 
  160   extern template class basic_streambuf<wchar_t>;
 
  163     __copy_streambufs(basic_streambuf<wchar_t>*,
 
  164              basic_streambuf<wchar_t>*);
 
  167     __copy_streambufs_eof(basic_streambuf<wchar_t>*,
 
  168              basic_streambuf<wchar_t>*, bool&);
 
  172 _GLIBCXX_END_NAMESPACE_VERSION