]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/streambuf.tcc
*: Use headername alias to associate private includes to public includes.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / streambuf.tcc
CommitLineData
725dc051
BK
1// Stream buffer classes -*- C++ -*-
2
748086b7
JJ
3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4// 2006, 2009 Free Software Foundation, Inc.
725dc051
BK
5//
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
748086b7 9// Free Software Foundation; either version 3, or (at your option)
725dc051
BK
10// any later version.
11
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.
16
748086b7
JJ
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.
20
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/>.
725dc051 25
f910786b 26/** @file bits/streambuf.tcc
0aa06b18 27 * This is an internal header file, included by other library headers.
f910786b 28 * Do not attempt to use it directly. @headername{streambuf}
0aa06b18
BK
29 */
30
725dc051
BK
31//
32// ISO C++ 14882: 27.5 Stream buffers
33//
34
3d7c150e
BK
35#ifndef _STREAMBUF_TCC
36#define _STREAMBUF_TCC 1
725dc051 37
3b794528
BK
38#pragma GCC system_header
39
3cbc7af0
BK
40_GLIBCXX_BEGIN_NAMESPACE(std)
41
725dc051
BK
42 template<typename _CharT, typename _Traits>
43 streamsize
44 basic_streambuf<_CharT, _Traits>::
45 xsgetn(char_type* __s, streamsize __n)
46 {
725dc051 47 streamsize __ret = 0;
13187a45 48 while (__ret < __n)
725dc051 49 {
cdcdee12 50 const streamsize __buf_len = this->egptr() - this->gptr();
002bd606 51 if (__buf_len)
725dc051 52 {
cdcdee12
PC
53 const streamsize __remaining = __n - __ret;
54 const streamsize __len = std::min(__buf_len, __remaining);
71b46021 55 traits_type::copy(__s, this->gptr(), __len);
13187a45
BK
56 __ret += __len;
57 __s += __len;
71b46021 58 this->gbump(__len);
13187a45 59 }
ed6814f7 60
13187a45
BK
61 if (__ret < __n)
62 {
ed6814f7 63 const int_type __c = this->uflow();
49433044 64 if (!traits_type::eq_int_type(__c, traits_type::eof()))
5fa9abc3
BK
65 {
66 traits_type::assign(*__s++, traits_type::to_char_type(__c));
67 ++__ret;
68 }
69 else
13187a45 70 break;
725dc051
BK
71 }
72 }
73 return __ret;
74 }
75
725dc051
BK
76 template<typename _CharT, typename _Traits>
77 streamsize
78 basic_streambuf<_CharT, _Traits>::
79 xsputn(const char_type* __s, streamsize __n)
80 {
81 streamsize __ret = 0;
13187a45 82 while (__ret < __n)
725dc051 83 {
cdcdee12 84 const streamsize __buf_len = this->epptr() - this->pptr();
002bd606 85 if (__buf_len)
725dc051 86 {
cdcdee12
PC
87 const streamsize __remaining = __n - __ret;
88 const streamsize __len = std::min(__buf_len, __remaining);
71b46021 89 traits_type::copy(this->pptr(), __s, __len);
13187a45
BK
90 __ret += __len;
91 __s += __len;
71b46021 92 this->pbump(__len);
13187a45
BK
93 }
94
95 if (__ret < __n)
96 {
002bd606 97 int_type __c = this->overflow(traits_type::to_int_type(*__s));
49433044 98 if (!traits_type::eq_int_type(__c, traits_type::eof()))
5fa9abc3
BK
99 {
100 ++__ret;
101 ++__s;
102 }
103 else
13187a45 104 break;
725dc051
BK
105 }
106 }
107 return __ret;
108 }
109
725dc051
BK
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
2bf8accc 112 // standard.
725dc051
BK
113 template<typename _CharT, typename _Traits>
114 streamsize
6f4d3d86
PC
115 __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
116 basic_streambuf<_CharT, _Traits>* __sbout,
117 bool& __ineof)
0992fb51 118 {
725dc051 119 streamsize __ret = 0;
6f4d3d86 120 __ineof = true;
fb8d4638
PC
121 typename _Traits::int_type __c = __sbin->sgetc();
122 while (!_Traits::eq_int_type(__c, _Traits::eof()))
6cf5465d 123 {
2bf8accc
PC
124 __c = __sbout->sputc(_Traits::to_char_type(__c));
125 if (_Traits::eq_int_type(__c, _Traits::eof()))
6f4d3d86
PC
126 {
127 __ineof = false;
128 break;
129 }
2bf8accc
PC
130 ++__ret;
131 __c = __sbin->snextc();
6cf5465d 132 }
725dc051
BK
133 return __ret;
134 }
a32e3c09 135
6f4d3d86
PC
136 template<typename _CharT, typename _Traits>
137 inline streamsize
138 __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
139 basic_streambuf<_CharT, _Traits>* __sbout)
140 {
141 bool __ineof;
142 return __copy_streambufs_eof(__sbin, __sbout, __ineof);
143 }
144
a32e3c09 145 // Inhibit implicit instantiations for required instantiations,
ed6814f7 146 // which are defined via explicit instantiations elsewhere.
a32e3c09 147 // NB: This syntax is a GNU extension.
3d7c150e 148#if _GLIBCXX_EXTERN_TEMPLATE
a32e3c09
BK
149 extern template class basic_streambuf<char>;
150 extern template
151 streamsize
6f4d3d86
PC
152 __copy_streambufs(basic_streambuf<char>*,
153 basic_streambuf<char>*);
154 extern template
155 streamsize
156 __copy_streambufs_eof(basic_streambuf<char>*,
157 basic_streambuf<char>*, bool&);
a32e3c09 158
3d7c150e 159#ifdef _GLIBCXX_USE_WCHAR_T
a32e3c09
BK
160 extern template class basic_streambuf<wchar_t>;
161 extern template
162 streamsize
6f4d3d86
PC
163 __copy_streambufs(basic_streambuf<wchar_t>*,
164 basic_streambuf<wchar_t>*);
165 extern template
166 streamsize
167 __copy_streambufs_eof(basic_streambuf<wchar_t>*,
168 basic_streambuf<wchar_t>*, bool&);
5112ae3a 169#endif
1bc8b0ad 170#endif
3cbc7af0
BK
171
172_GLIBCXX_END_NAMESPACE
725dc051 173
ed6814f7 174#endif