1 // Stream buffer classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4 // 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 2, 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 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file streambuf.tcc
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
37 // ISO C++ 14882: 27.5 Stream buffers
40 #ifndef _STREAMBUF_TCC
41 #define _STREAMBUF_TCC 1
43 #pragma GCC system_header
45 _GLIBCXX_BEGIN_NAMESPACE(std)
47 template<typename _CharT, typename _Traits>
49 basic_streambuf<_CharT, _Traits>::
50 xsgetn(char_type* __s, streamsize __n)
55 const streamsize __buf_len = this->egptr() - this->gptr();
58 const streamsize __remaining = __n - __ret;
59 const streamsize __len = std::min(__buf_len, __remaining);
60 traits_type::copy(__s, this->gptr(), __len);
68 const int_type __c = this->uflow();
69 if (!traits_type::eq_int_type(__c, traits_type::eof()))
71 traits_type::assign(*__s++, traits_type::to_char_type(__c));
81 template<typename _CharT, typename _Traits>
83 basic_streambuf<_CharT, _Traits>::
84 xsputn(const char_type* __s, streamsize __n)
89 const streamsize __buf_len = this->epptr() - this->pptr();
92 const streamsize __remaining = __n - __ret;
93 const streamsize __len = std::min(__buf_len, __remaining);
94 traits_type::copy(this->pptr(), __s, __len);
102 int_type __c = this->overflow(traits_type::to_int_type(*__s));
103 if (!traits_type::eq_int_type(__c, traits_type::eof()))
115 // Conceivably, this could be used to implement buffer-to-buffer
116 // copies, if this was ever desired in an un-ambiguous way by the
118 template<typename _CharT, typename _Traits>
120 __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
121 basic_streambuf<_CharT, _Traits>* __sbout,
124 streamsize __ret = 0;
126 typename _Traits::int_type __c = __sbin->sgetc();
127 while (!_Traits::eq_int_type(__c, _Traits::eof()))
129 __c = __sbout->sputc(_Traits::to_char_type(__c));
130 if (_Traits::eq_int_type(__c, _Traits::eof()))
136 __c = __sbin->snextc();
141 template<typename _CharT, typename _Traits>
143 __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
144 basic_streambuf<_CharT, _Traits>* __sbout)
147 return __copy_streambufs_eof(__sbin, __sbout, __ineof);
150 // Inhibit implicit instantiations for required instantiations,
151 // which are defined via explicit instantiations elsewhere.
152 // NB: This syntax is a GNU extension.
153 #if _GLIBCXX_EXTERN_TEMPLATE
154 extern template class basic_streambuf<char>;
157 __copy_streambufs(basic_streambuf<char>*,
158 basic_streambuf<char>*);
161 __copy_streambufs_eof(basic_streambuf<char>*,
162 basic_streambuf<char>*, bool&);
164 #ifdef _GLIBCXX_USE_WCHAR_T
165 extern template class basic_streambuf<wchar_t>;
168 __copy_streambufs(basic_streambuf<wchar_t>*,
169 basic_streambuf<wchar_t>*);
172 __copy_streambufs_eof(basic_streambuf<wchar_t>*,
173 basic_streambuf<wchar_t>*, bool&);
177 _GLIBCXX_END_NAMESPACE