1 // Stream buffer classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 // 2006, 2009 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file bits/streambuf.tcc
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{streambuf}
32 // ISO C++ 14882: 27.5 Stream buffers
35 #ifndef _STREAMBUF_TCC
36 #define _STREAMBUF_TCC 1
38 #pragma GCC system_header
40 _GLIBCXX_BEGIN_NAMESPACE(std)
42 template<typename _CharT, typename _Traits>
44 basic_streambuf<_CharT, _Traits>::
45 xsgetn(char_type* __s, streamsize __n)
50 const streamsize __buf_len = this->egptr() - this->gptr();
53 const streamsize __remaining = __n - __ret;
54 const streamsize __len = std::min(__buf_len, __remaining);
55 traits_type::copy(__s, this->gptr(), __len);
63 const int_type __c = this->uflow();
64 if (!traits_type::eq_int_type(__c, traits_type::eof()))
66 traits_type::assign(*__s++, traits_type::to_char_type(__c));
76 template<typename _CharT, typename _Traits>
78 basic_streambuf<_CharT, _Traits>::
79 xsputn(const char_type* __s, streamsize __n)
84 const streamsize __buf_len = this->epptr() - this->pptr();
87 const streamsize __remaining = __n - __ret;
88 const streamsize __len = std::min(__buf_len, __remaining);
89 traits_type::copy(this->pptr(), __s, __len);
97 int_type __c = this->overflow(traits_type::to_int_type(*__s));
98 if (!traits_type::eq_int_type(__c, traits_type::eof()))
110 // Conceivably, this could be used to implement buffer-to-buffer
111 // copies, if this was ever desired in an un-ambiguous way by the
113 template<typename _CharT, typename _Traits>
115 __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
116 basic_streambuf<_CharT, _Traits>* __sbout,
119 streamsize __ret = 0;
121 typename _Traits::int_type __c = __sbin->sgetc();
122 while (!_Traits::eq_int_type(__c, _Traits::eof()))
124 __c = __sbout->sputc(_Traits::to_char_type(__c));
125 if (_Traits::eq_int_type(__c, _Traits::eof()))
131 __c = __sbin->snextc();
136 template<typename _CharT, typename _Traits>
138 __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
139 basic_streambuf<_CharT, _Traits>* __sbout)
142 return __copy_streambufs_eof(__sbin, __sbout, __ineof);
145 // Inhibit implicit instantiations for required instantiations,
146 // which are defined via explicit instantiations elsewhere.
147 // NB: This syntax is a GNU extension.
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