]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // Stream buffer classes -*- C++ -*- |
2 | ||
a5544970 | 3 | // Copyright (C) 1997-2019 Free Software Foundation, Inc. |
725dc051 BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
725dc051 BK |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
725dc051 | 24 | |
f910786b | 25 | /** @file bits/streambuf.tcc |
0aa06b18 | 26 | * This is an internal header file, included by other library headers. |
f910786b | 27 | * Do not attempt to use it directly. @headername{streambuf} |
0aa06b18 BK |
28 | */ |
29 | ||
725dc051 BK |
30 | // |
31 | // ISO C++ 14882: 27.5 Stream buffers | |
32 | // | |
33 | ||
3d7c150e BK |
34 | #ifndef _STREAMBUF_TCC |
35 | #define _STREAMBUF_TCC 1 | |
725dc051 | 36 | |
3b794528 BK |
37 | #pragma GCC system_header |
38 | ||
12ffa228 BK |
39 | namespace std _GLIBCXX_VISIBILITY(default) |
40 | { | |
41 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 42 | |
725dc051 BK |
43 | template<typename _CharT, typename _Traits> |
44 | streamsize | |
45 | basic_streambuf<_CharT, _Traits>:: | |
46 | xsgetn(char_type* __s, streamsize __n) | |
47 | { | |
725dc051 | 48 | streamsize __ret = 0; |
13187a45 | 49 | while (__ret < __n) |
725dc051 | 50 | { |
cdcdee12 | 51 | const streamsize __buf_len = this->egptr() - this->gptr(); |
002bd606 | 52 | if (__buf_len) |
725dc051 | 53 | { |
cdcdee12 PC |
54 | const streamsize __remaining = __n - __ret; |
55 | const streamsize __len = std::min(__buf_len, __remaining); | |
71b46021 | 56 | traits_type::copy(__s, this->gptr(), __len); |
13187a45 BK |
57 | __ret += __len; |
58 | __s += __len; | |
1139a735 | 59 | this->__safe_gbump(__len); |
13187a45 | 60 | } |
ed6814f7 | 61 | |
13187a45 BK |
62 | if (__ret < __n) |
63 | { | |
ed6814f7 | 64 | const int_type __c = this->uflow(); |
49433044 | 65 | if (!traits_type::eq_int_type(__c, traits_type::eof())) |
5fa9abc3 BK |
66 | { |
67 | traits_type::assign(*__s++, traits_type::to_char_type(__c)); | |
68 | ++__ret; | |
69 | } | |
70 | else | |
13187a45 | 71 | break; |
725dc051 BK |
72 | } |
73 | } | |
74 | return __ret; | |
75 | } | |
76 | ||
725dc051 BK |
77 | template<typename _CharT, typename _Traits> |
78 | streamsize | |
79 | basic_streambuf<_CharT, _Traits>:: | |
80 | xsputn(const char_type* __s, streamsize __n) | |
81 | { | |
82 | streamsize __ret = 0; | |
13187a45 | 83 | while (__ret < __n) |
725dc051 | 84 | { |
cdcdee12 | 85 | const streamsize __buf_len = this->epptr() - this->pptr(); |
002bd606 | 86 | if (__buf_len) |
725dc051 | 87 | { |
cdcdee12 PC |
88 | const streamsize __remaining = __n - __ret; |
89 | const streamsize __len = std::min(__buf_len, __remaining); | |
71b46021 | 90 | traits_type::copy(this->pptr(), __s, __len); |
13187a45 BK |
91 | __ret += __len; |
92 | __s += __len; | |
1139a735 | 93 | this->__safe_pbump(__len); |
13187a45 BK |
94 | } |
95 | ||
96 | if (__ret < __n) | |
97 | { | |
002bd606 | 98 | int_type __c = this->overflow(traits_type::to_int_type(*__s)); |
49433044 | 99 | if (!traits_type::eq_int_type(__c, traits_type::eof())) |
5fa9abc3 BK |
100 | { |
101 | ++__ret; | |
102 | ++__s; | |
103 | } | |
104 | else | |
13187a45 | 105 | break; |
725dc051 BK |
106 | } |
107 | } | |
108 | return __ret; | |
109 | } | |
110 | ||
725dc051 BK |
111 | // Conceivably, this could be used to implement buffer-to-buffer |
112 | // copies, if this was ever desired in an un-ambiguous way by the | |
2bf8accc | 113 | // standard. |
725dc051 BK |
114 | template<typename _CharT, typename _Traits> |
115 | streamsize | |
6f4d3d86 PC |
116 | __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin, |
117 | basic_streambuf<_CharT, _Traits>* __sbout, | |
118 | bool& __ineof) | |
0992fb51 | 119 | { |
725dc051 | 120 | streamsize __ret = 0; |
6f4d3d86 | 121 | __ineof = true; |
fb8d4638 PC |
122 | typename _Traits::int_type __c = __sbin->sgetc(); |
123 | while (!_Traits::eq_int_type(__c, _Traits::eof())) | |
6cf5465d | 124 | { |
2bf8accc PC |
125 | __c = __sbout->sputc(_Traits::to_char_type(__c)); |
126 | if (_Traits::eq_int_type(__c, _Traits::eof())) | |
6f4d3d86 PC |
127 | { |
128 | __ineof = false; | |
129 | break; | |
130 | } | |
2bf8accc PC |
131 | ++__ret; |
132 | __c = __sbin->snextc(); | |
6cf5465d | 133 | } |
725dc051 BK |
134 | return __ret; |
135 | } | |
a32e3c09 | 136 | |
6f4d3d86 PC |
137 | template<typename _CharT, typename _Traits> |
138 | inline streamsize | |
139 | __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin, | |
140 | basic_streambuf<_CharT, _Traits>* __sbout) | |
141 | { | |
142 | bool __ineof; | |
143 | return __copy_streambufs_eof(__sbin, __sbout, __ineof); | |
144 | } | |
145 | ||
a32e3c09 | 146 | // Inhibit implicit instantiations for required instantiations, |
ed6814f7 | 147 | // which are defined via explicit instantiations elsewhere. |
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 | 171 | |
12ffa228 | 172 | _GLIBCXX_END_NAMESPACE_VERSION |
ed4f96af | 173 | } // namespace std |
725dc051 | 174 | |
ed6814f7 | 175 | #endif |