streambuf.tcc

00001 // Stream buffer classes -*- C++ -*- 00002 00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 // 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 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 size_t __buf_len = this->egptr() - this->gptr(); 00051 if (__buf_len) 00052 { 00053 const size_t __remaining = __n - __ret; 00054 const size_t __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 size_t __buf_len = this->epptr() - this->pptr(); 00085 if (__buf_len) 00086 { 00087 const size_t __remaining = __n - __ret; 00088 const size_t __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. If so, then checks for __ios being zero would be 00113 // necessary. 00114 template<typename _CharT, typename _Traits> 00115 streamsize 00116 __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin, 00117 basic_streambuf<_CharT, _Traits>* __sbout) 00118 { 00119 streamsize __ret = 0; 00120 typename _Traits::int_type __c = __sbin->sgetc(); 00121 while (!_Traits::eq_int_type(__c, _Traits::eof())) 00122 { 00123 const size_t __n = __sbin->egptr() - __sbin->gptr(); 00124 if (__n > 1) 00125 { 00126 const size_t __wrote = __sbout->sputn(__sbin->gptr(), __n); 00127 __sbin->gbump(__wrote); 00128 __ret += __wrote; 00129 if (__wrote < __n) 00130 break; 00131 __c = __sbin->underflow(); 00132 } 00133 else 00134 { 00135 __c = __sbout->sputc(_Traits::to_char_type(__c)); 00136 if (_Traits::eq_int_type(__c, _Traits::eof())) 00137 break; 00138 ++__ret; 00139 __c = __sbin->snextc(); 00140 } 00141 } 00142 return __ret; 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>*, basic_streambuf<char>*); 00153 00154 #ifdef _GLIBCXX_USE_WCHAR_T 00155 extern template class basic_streambuf<wchar_t>; 00156 extern template 00157 streamsize 00158 __copy_streambufs(basic_streambuf<wchar_t>*, basic_streambuf<wchar_t>*); 00159 #endif 00160 #endif 00161 } // namespace std 00162 00163 #endif

Generated on Wed Jun 9 11:19:21 2004 for libstdc++-v3 Source by doxygen 1.3.7