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
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 
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 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(basic_streambuf<_CharT, _Traits>* __sbin,
00121               basic_streambuf<_CharT, _Traits>* __sbout)
00122     {
00123       streamsize __ret = 0;
00124       typename _Traits::int_type __c = __sbin->sgetc();
00125       while (!_Traits::eq_int_type(__c, _Traits::eof()))
00126     {
00127       __c = __sbout->sputc(_Traits::to_char_type(__c));
00128       if (_Traits::eq_int_type(__c, _Traits::eof()))
00129         break;
00130       ++__ret;
00131       __c = __sbin->snextc();
00132     }
00133       return __ret;
00134     }
00135 
00136   // Inhibit implicit instantiations for required instantiations,
00137   // which are defined via explicit instantiations elsewhere.
00138   // NB:  This syntax is a GNU extension.
00139 #if _GLIBCXX_EXTERN_TEMPLATE
00140   extern template class basic_streambuf<char>;
00141   extern template
00142     streamsize
00143     __copy_streambufs(basic_streambuf<char>*, basic_streambuf<char>*);
00144 
00145 #ifdef _GLIBCXX_USE_WCHAR_T
00146   extern template class basic_streambuf<wchar_t>;
00147   extern template
00148     streamsize
00149     __copy_streambufs(basic_streambuf<wchar_t>*, basic_streambuf<wchar_t>*);
00150 #endif
00151 #endif
00152 } // namespace std
00153 
00154 #endif

Generated on Tue Feb 2 16:56:42 2010 for GNU C++ STL by  doxygen 1.4.7