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 // 2006, 2009  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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /** @file streambuf.tcc
00027  *  This is an internal header file, included by other library headers.
00028  *  You should not attempt to use it directly.
00029  */
00030 
00031 //
00032 // ISO C++ 14882: 27.5  Stream buffers
00033 //
00034 
00035 #ifndef _STREAMBUF_TCC
00036 #define _STREAMBUF_TCC 1
00037 
00038 #pragma GCC system_header
00039 
00040 _GLIBCXX_BEGIN_NAMESPACE(std)
00041 
00042   template<typename _CharT, typename _Traits>
00043     streamsize
00044     basic_streambuf<_CharT, _Traits>::
00045     xsgetn(char_type* __s, streamsize __n)
00046     {
00047       streamsize __ret = 0;
00048       while (__ret < __n)
00049     {
00050       const streamsize __buf_len = this->egptr() - this->gptr();
00051       if (__buf_len)
00052         {
00053           const streamsize __remaining = __n - __ret;
00054           const streamsize __len = std::min(__buf_len, __remaining);
00055           traits_type::copy(__s, this->gptr(), __len);
00056           __ret += __len;
00057           __s += __len;
00058           this->gbump(__len);
00059         }
00060 
00061       if (__ret < __n)
00062         {
00063           const int_type __c = this->uflow();
00064           if (!traits_type::eq_int_type(__c, traits_type::eof()))
00065         {
00066           traits_type::assign(*__s++, traits_type::to_char_type(__c));
00067           ++__ret;
00068         }
00069           else
00070         break;
00071         }
00072     }
00073       return __ret;
00074     }
00075 
00076   template<typename _CharT, typename _Traits>
00077     streamsize
00078     basic_streambuf<_CharT, _Traits>::
00079     xsputn(const char_type* __s, streamsize __n)
00080     {
00081       streamsize __ret = 0;
00082       while (__ret < __n)
00083     {
00084       const streamsize __buf_len = this->epptr() - this->pptr();
00085       if (__buf_len)
00086         {
00087           const streamsize __remaining = __n - __ret;
00088           const streamsize __len = std::min(__buf_len, __remaining);
00089           traits_type::copy(this->pptr(), __s, __len);
00090           __ret += __len;
00091           __s += __len;
00092           this->pbump(__len);
00093         }
00094 
00095       if (__ret < __n)
00096         {
00097           int_type __c = this->overflow(traits_type::to_int_type(*__s));
00098           if (!traits_type::eq_int_type(__c, traits_type::eof()))
00099         {
00100           ++__ret;
00101           ++__s;
00102         }
00103           else
00104         break;
00105         }
00106     }
00107       return __ret;
00108     }
00109 
00110   // Conceivably, this could be used to implement buffer-to-buffer
00111   // copies, if this was ever desired in an un-ambiguous way by the
00112   // standard.
00113   template<typename _CharT, typename _Traits>
00114     streamsize
00115     __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
00116               basic_streambuf<_CharT, _Traits>* __sbout,
00117               bool& __ineof)
00118     {
00119       streamsize __ret = 0;
00120       __ineof = true;
00121       typename _Traits::int_type __c = __sbin->sgetc();
00122       while (!_Traits::eq_int_type(__c, _Traits::eof()))
00123     {
00124       __c = __sbout->sputc(_Traits::to_char_type(__c));
00125       if (_Traits::eq_int_type(__c, _Traits::eof()))
00126         {
00127           __ineof = false;
00128           break;
00129         }
00130       ++__ret;
00131       __c = __sbin->snextc();
00132     }
00133       return __ret;
00134     }
00135 
00136   template<typename _CharT, typename _Traits>
00137     inline streamsize
00138     __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
00139               basic_streambuf<_CharT, _Traits>* __sbout)
00140     {
00141       bool __ineof;
00142       return __copy_streambufs_eof(__sbin, __sbout, __ineof);
00143     }
00144 
00145   // Inhibit implicit instantiations for required instantiations,
00146   // which are defined via explicit instantiations elsewhere.
00147   // NB:  This syntax is a GNU extension.
00148 #if _GLIBCXX_EXTERN_TEMPLATE
00149   extern template class basic_streambuf<char>;
00150   extern template
00151     streamsize
00152     __copy_streambufs(basic_streambuf<char>*,
00153               basic_streambuf<char>*);
00154   extern template
00155     streamsize
00156     __copy_streambufs_eof(basic_streambuf<char>*,
00157               basic_streambuf<char>*, bool&);
00158 
00159 #ifdef _GLIBCXX_USE_WCHAR_T
00160   extern template class basic_streambuf<wchar_t>;
00161   extern template
00162     streamsize
00163     __copy_streambufs(basic_streambuf<wchar_t>*,
00164               basic_streambuf<wchar_t>*);
00165   extern template
00166     streamsize
00167     __copy_streambufs_eof(basic_streambuf<wchar_t>*,
00168               basic_streambuf<wchar_t>*, bool&);
00169 #endif
00170 #endif
00171 
00172 _GLIBCXX_END_NAMESPACE
00173 
00174 #endif

Generated on Tue Apr 21 13:13:33 2009 for libstdc++ by  doxygen 1.5.8