]>
Commit | Line | Data |
---|---|---|
a32e3c09 BK |
1 | // istream 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/istream.tcc |
0aa06b18 | 26 | * This is an internal header file, included by other library headers. |
f910786b | 27 | * Do not attempt to use it directly. @headername{istream} |
0aa06b18 BK |
28 | */ |
29 | ||
725dc051 | 30 | // |
479864fe | 31 | // ISO C++ 14882: 27.6.1 Input streams |
725dc051 BK |
32 | // |
33 | ||
3d7c150e BK |
34 | #ifndef _ISTREAM_TCC |
35 | #define _ISTREAM_TCC 1 | |
36 | ||
3b794528 BK |
37 | #pragma GCC system_header |
38 | ||
7c3e9502 | 39 | #include <bits/cxxabi_forced.h> |
d05f74f1 | 40 | |
12ffa228 BK |
41 | namespace std _GLIBCXX_VISIBILITY(default) |
42 | { | |
43 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 44 | |
725dc051 BK |
45 | template<typename _CharT, typename _Traits> |
46 | basic_istream<_CharT, _Traits>::sentry:: | |
26c691a8 | 47 | sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false) |
725dc051 | 48 | { |
6f0398bb | 49 | ios_base::iostate __err = ios_base::goodbit; |
ed6814f7 | 50 | if (__in.good()) |
c2830789 JW |
51 | __try |
52 | { | |
53 | if (__in.tie()) | |
54 | __in.tie()->flush(); | |
55 | if (!__noskip && bool(__in.flags() & ios_base::skipws)) | |
56 | { | |
57 | const __int_type __eof = traits_type::eof(); | |
58 | __streambuf_type* __sb = __in.rdbuf(); | |
59 | __int_type __c = __sb->sgetc(); | |
60 | ||
61 | const __ctype_type& __ct = __check_facet(__in._M_ctype); | |
62 | while (!traits_type::eq_int_type(__c, __eof) | |
63 | && __ct.is(ctype_base::space, | |
64 | traits_type::to_char_type(__c))) | |
65 | __c = __sb->snextc(); | |
66 | ||
67 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
68 | // 195. Should basic_istream::sentry's constructor ever | |
69 | // set eofbit? | |
70 | if (traits_type::eq_int_type(__c, __eof)) | |
71 | __err |= ios_base::eofbit; | |
72 | } | |
73 | } | |
74 | __catch(__cxxabiv1::__forced_unwind&) | |
75 | { | |
76 | __in._M_setstate(ios_base::badbit); | |
77 | __throw_exception_again; | |
78 | } | |
79 | __catch(...) | |
80 | { __in._M_setstate(ios_base::badbit); } | |
13187a45 | 81 | |
48f499cf | 82 | if (__in.good() && __err == ios_base::goodbit) |
13187a45 BK |
83 | _M_ok = true; |
84 | else | |
85 | { | |
48f499cf | 86 | __err |= ios_base::failbit; |
6b98580b | 87 | __in.setstate(__err); |
13187a45 | 88 | } |
725dc051 BK |
89 | } |
90 | ||
725dc051 | 91 | template<typename _CharT, typename _Traits> |
49d5c016 PC |
92 | template<typename _ValueT> |
93 | basic_istream<_CharT, _Traits>& | |
94 | basic_istream<_CharT, _Traits>:: | |
95 | _M_extract(_ValueT& __v) | |
96 | { | |
97 | sentry __cerb(*this, false); | |
880b527f | 98 | if (__cerb) |
49d5c016 | 99 | { |
6f0398bb | 100 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 101 | __try |
49d5c016 PC |
102 | { |
103 | const __num_get_type& __ng = __check_facet(this->_M_num_get); | |
104 | __ng.get(*this, 0, *this, __err, __v); | |
105 | } | |
bc2631e0 | 106 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 | 107 | { |
6f0398bb | 108 | this->_M_setstate(ios_base::badbit); |
d05f74f1 JM |
109 | __throw_exception_again; |
110 | } | |
bc2631e0 | 111 | __catch(...) |
49d5c016 PC |
112 | { this->_M_setstate(ios_base::badbit); } |
113 | if (__err) | |
114 | this->setstate(__err); | |
115 | } | |
116 | return *this; | |
117 | } | |
725dc051 | 118 | |
e7968bd8 PC |
119 | template<typename _CharT, typename _Traits> |
120 | basic_istream<_CharT, _Traits>& | |
121 | basic_istream<_CharT, _Traits>:: | |
122 | operator>>(short& __n) | |
123 | { | |
124 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
125 | // 118. basic_istream uses nonexistent num_get member functions. | |
6f0398bb | 126 | sentry __cerb(*this, false); |
880b527f | 127 | if (__cerb) |
e7968bd8 | 128 | { |
6f0398bb PC |
129 | ios_base::iostate __err = ios_base::goodbit; |
130 | __try | |
131 | { | |
132 | long __l; | |
133 | const __num_get_type& __ng = __check_facet(this->_M_num_get); | |
134 | __ng.get(*this, 0, *this, __err, __l); | |
135 | ||
136 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
137 | // 696. istream::operator>>(int&) broken. | |
138 | if (__l < __gnu_cxx::__numeric_traits<short>::__min) | |
139 | { | |
140 | __err |= ios_base::failbit; | |
141 | __n = __gnu_cxx::__numeric_traits<short>::__min; | |
142 | } | |
143 | else if (__l > __gnu_cxx::__numeric_traits<short>::__max) | |
144 | { | |
145 | __err |= ios_base::failbit; | |
146 | __n = __gnu_cxx::__numeric_traits<short>::__max; | |
147 | } | |
148 | else | |
149 | __n = short(__l); | |
150 | } | |
151 | __catch(__cxxabiv1::__forced_unwind&) | |
152 | { | |
153 | this->_M_setstate(ios_base::badbit); | |
154 | __throw_exception_again; | |
155 | } | |
156 | __catch(...) | |
157 | { this->_M_setstate(ios_base::badbit); } | |
158 | if (__err) | |
159 | this->setstate(__err); | |
e7968bd8 PC |
160 | } |
161 | return *this; | |
162 | } | |
6f0398bb | 163 | |
e7968bd8 PC |
164 | template<typename _CharT, typename _Traits> |
165 | basic_istream<_CharT, _Traits>& | |
166 | basic_istream<_CharT, _Traits>:: | |
167 | operator>>(int& __n) | |
168 | { | |
169 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
170 | // 118. basic_istream uses nonexistent num_get member functions. | |
6f0398bb | 171 | sentry __cerb(*this, false); |
880b527f | 172 | if (__cerb) |
e7968bd8 | 173 | { |
6f0398bb PC |
174 | ios_base::iostate __err = ios_base::goodbit; |
175 | __try | |
176 | { | |
177 | long __l; | |
178 | const __num_get_type& __ng = __check_facet(this->_M_num_get); | |
179 | __ng.get(*this, 0, *this, __err, __l); | |
180 | ||
181 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
182 | // 696. istream::operator>>(int&) broken. | |
183 | if (__l < __gnu_cxx::__numeric_traits<int>::__min) | |
184 | { | |
185 | __err |= ios_base::failbit; | |
186 | __n = __gnu_cxx::__numeric_traits<int>::__min; | |
187 | } | |
188 | else if (__l > __gnu_cxx::__numeric_traits<int>::__max) | |
189 | { | |
190 | __err |= ios_base::failbit; | |
191 | __n = __gnu_cxx::__numeric_traits<int>::__max; | |
192 | } | |
193 | else | |
194 | __n = int(__l); | |
195 | } | |
196 | __catch(__cxxabiv1::__forced_unwind&) | |
197 | { | |
198 | this->_M_setstate(ios_base::badbit); | |
199 | __throw_exception_again; | |
200 | } | |
201 | __catch(...) | |
202 | { this->_M_setstate(ios_base::badbit); } | |
203 | if (__err) | |
204 | this->setstate(__err); | |
e7968bd8 PC |
205 | } |
206 | return *this; | |
207 | } | |
208 | ||
725dc051 | 209 | template<typename _CharT, typename _Traits> |
ed6814f7 | 210 | basic_istream<_CharT, _Traits>& |
725dc051 BK |
211 | basic_istream<_CharT, _Traits>:: |
212 | operator>>(__streambuf_type* __sbout) | |
213 | { | |
6f0398bb | 214 | ios_base::iostate __err = ios_base::goodbit; |
12841eb3 | 215 | sentry __cerb(*this, false); |
880b527f | 216 | if (__cerb && __sbout) |
12841eb3 | 217 | { |
bc2631e0 | 218 | __try |
12841eb3 | 219 | { |
6f4d3d86 PC |
220 | bool __ineof; |
221 | if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof)) | |
12841eb3 | 222 | __err |= ios_base::failbit; |
6f4d3d86 PC |
223 | if (__ineof) |
224 | __err |= ios_base::eofbit; | |
12841eb3 | 225 | } |
bc2631e0 | 226 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
227 | { |
228 | this->_M_setstate(ios_base::failbit); | |
229 | __throw_exception_again; | |
230 | } | |
bc2631e0 | 231 | __catch(...) |
12841eb3 BK |
232 | { this->_M_setstate(ios_base::failbit); } |
233 | } | |
234 | else if (!__sbout) | |
235 | __err |= ios_base::failbit; | |
6b98580b BK |
236 | if (__err) |
237 | this->setstate(__err); | |
12841eb3 | 238 | return *this; |
725dc051 BK |
239 | } |
240 | ||
241 | template<typename _CharT, typename _Traits> | |
31bfa177 | 242 | typename basic_istream<_CharT, _Traits>::int_type |
725dc051 BK |
243 | basic_istream<_CharT, _Traits>:: |
244 | get(void) | |
245 | { | |
246 | const int_type __eof = traits_type::eof(); | |
247 | int_type __c = __eof; | |
248 | _M_gcount = 0; | |
6f0398bb | 249 | ios_base::iostate __err = ios_base::goodbit; |
725dc051 | 250 | sentry __cerb(*this, true); |
880b527f | 251 | if (__cerb) |
725dc051 | 252 | { |
bc2631e0 | 253 | __try |
bfa1e6b1 BK |
254 | { |
255 | __c = this->rdbuf()->sbumpc(); | |
256 | // 27.6.1.1 paragraph 3 | |
f13a69ec | 257 | if (!traits_type::eq_int_type(__c, __eof)) |
bfa1e6b1 BK |
258 | _M_gcount = 1; |
259 | else | |
12841eb3 | 260 | __err |= ios_base::eofbit; |
bfa1e6b1 | 261 | } |
bc2631e0 | 262 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
263 | { |
264 | this->_M_setstate(ios_base::badbit); | |
265 | __throw_exception_again; | |
266 | } | |
bc2631e0 | 267 | __catch(...) |
12841eb3 | 268 | { this->_M_setstate(ios_base::badbit); } |
725dc051 | 269 | } |
12841eb3 BK |
270 | if (!_M_gcount) |
271 | __err |= ios_base::failbit; | |
6b98580b BK |
272 | if (__err) |
273 | this->setstate(__err); | |
725dc051 BK |
274 | return __c; |
275 | } | |
276 | ||
277 | template<typename _CharT, typename _Traits> | |
278 | basic_istream<_CharT, _Traits>& | |
279 | basic_istream<_CharT, _Traits>:: | |
280 | get(char_type& __c) | |
281 | { | |
282 | _M_gcount = 0; | |
6f0398bb | 283 | ios_base::iostate __err = ios_base::goodbit; |
725dc051 | 284 | sentry __cerb(*this, true); |
880b527f | 285 | if (__cerb) |
725dc051 | 286 | { |
bc2631e0 | 287 | __try |
bfa1e6b1 | 288 | { |
3adf6cad | 289 | const int_type __cb = this->rdbuf()->sbumpc(); |
bfa1e6b1 | 290 | // 27.6.1.1 paragraph 3 |
12841eb3 | 291 | if (!traits_type::eq_int_type(__cb, traits_type::eof())) |
bfa1e6b1 BK |
292 | { |
293 | _M_gcount = 1; | |
12841eb3 | 294 | __c = traits_type::to_char_type(__cb); |
bfa1e6b1 BK |
295 | } |
296 | else | |
12841eb3 | 297 | __err |= ios_base::eofbit; |
bfa1e6b1 | 298 | } |
bc2631e0 | 299 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
300 | { |
301 | this->_M_setstate(ios_base::badbit); | |
302 | __throw_exception_again; | |
303 | } | |
bc2631e0 | 304 | __catch(...) |
12841eb3 | 305 | { this->_M_setstate(ios_base::badbit); } |
725dc051 | 306 | } |
12841eb3 BK |
307 | if (!_M_gcount) |
308 | __err |= ios_base::failbit; | |
6b98580b BK |
309 | if (__err) |
310 | this->setstate(__err); | |
725dc051 BK |
311 | return *this; |
312 | } | |
313 | ||
314 | template<typename _CharT, typename _Traits> | |
315 | basic_istream<_CharT, _Traits>& | |
316 | basic_istream<_CharT, _Traits>:: | |
317 | get(char_type* __s, streamsize __n, char_type __delim) | |
318 | { | |
319 | _M_gcount = 0; | |
6f0398bb | 320 | ios_base::iostate __err = ios_base::goodbit; |
725dc051 | 321 | sentry __cerb(*this, true); |
880b527f | 322 | if (__cerb) |
725dc051 | 323 | { |
bc2631e0 | 324 | __try |
bfa1e6b1 BK |
325 | { |
326 | const int_type __idelim = traits_type::to_int_type(__delim); | |
327 | const int_type __eof = traits_type::eof(); | |
328 | __streambuf_type* __sb = this->rdbuf(); | |
ed6814f7 BI |
329 | int_type __c = __sb->sgetc(); |
330 | ||
331 | while (_M_gcount + 1 < __n | |
f13a69ec BK |
332 | && !traits_type::eq_int_type(__c, __eof) |
333 | && !traits_type::eq_int_type(__c, __idelim)) | |
bfa1e6b1 BK |
334 | { |
335 | *__s++ = traits_type::to_char_type(__c); | |
336 | ++_M_gcount; | |
b1c5b5a0 | 337 | __c = __sb->snextc(); |
bfa1e6b1 | 338 | } |
f13a69ec | 339 | if (traits_type::eq_int_type(__c, __eof)) |
12841eb3 | 340 | __err |= ios_base::eofbit; |
bfa1e6b1 | 341 | } |
bc2631e0 | 342 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
343 | { |
344 | this->_M_setstate(ios_base::badbit); | |
345 | __throw_exception_again; | |
346 | } | |
bc2631e0 | 347 | __catch(...) |
12841eb3 | 348 | { this->_M_setstate(ios_base::badbit); } |
725dc051 | 349 | } |
75a25e3f PC |
350 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
351 | // 243. get and getline when sentry reports failure. | |
352 | if (__n > 0) | |
353 | *__s = char_type(); | |
725dc051 | 354 | if (!_M_gcount) |
12841eb3 | 355 | __err |= ios_base::failbit; |
6b98580b BK |
356 | if (__err) |
357 | this->setstate(__err); | |
725dc051 BK |
358 | return *this; |
359 | } | |
360 | ||
361 | template<typename _CharT, typename _Traits> | |
362 | basic_istream<_CharT, _Traits>& | |
363 | basic_istream<_CharT, _Traits>:: | |
364 | get(__streambuf_type& __sb, char_type __delim) | |
365 | { | |
366 | _M_gcount = 0; | |
6f0398bb | 367 | ios_base::iostate __err = ios_base::goodbit; |
725dc051 | 368 | sentry __cerb(*this, true); |
880b527f | 369 | if (__cerb) |
725dc051 | 370 | { |
bc2631e0 | 371 | __try |
bfa1e6b1 BK |
372 | { |
373 | const int_type __idelim = traits_type::to_int_type(__delim); | |
ed6814f7 | 374 | const int_type __eof = traits_type::eof(); |
42ca0438 BK |
375 | __streambuf_type* __this_sb = this->rdbuf(); |
376 | int_type __c = __this_sb->sgetc(); | |
f13a69ec | 377 | char_type __c2 = traits_type::to_char_type(__c); |
ed6814f7 BI |
378 | |
379 | while (!traits_type::eq_int_type(__c, __eof) | |
380 | && !traits_type::eq_int_type(__c, __idelim) | |
f13a69ec | 381 | && !traits_type::eq_int_type(__sb.sputc(__c2), __eof)) |
bfa1e6b1 BK |
382 | { |
383 | ++_M_gcount; | |
42ca0438 | 384 | __c = __this_sb->snextc(); |
f13a69ec | 385 | __c2 = traits_type::to_char_type(__c); |
bfa1e6b1 | 386 | } |
f13a69ec | 387 | if (traits_type::eq_int_type(__c, __eof)) |
12841eb3 | 388 | __err |= ios_base::eofbit; |
bfa1e6b1 | 389 | } |
bc2631e0 | 390 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
391 | { |
392 | this->_M_setstate(ios_base::badbit); | |
393 | __throw_exception_again; | |
394 | } | |
bc2631e0 | 395 | __catch(...) |
12841eb3 | 396 | { this->_M_setstate(ios_base::badbit); } |
725dc051 BK |
397 | } |
398 | if (!_M_gcount) | |
12841eb3 | 399 | __err |= ios_base::failbit; |
6b98580b BK |
400 | if (__err) |
401 | this->setstate(__err); | |
725dc051 BK |
402 | return *this; |
403 | } | |
404 | ||
405 | template<typename _CharT, typename _Traits> | |
406 | basic_istream<_CharT, _Traits>& | |
407 | basic_istream<_CharT, _Traits>:: | |
408 | getline(char_type* __s, streamsize __n, char_type __delim) | |
409 | { | |
410 | _M_gcount = 0; | |
6f0398bb | 411 | ios_base::iostate __err = ios_base::goodbit; |
725dc051 | 412 | sentry __cerb(*this, true); |
880b527f | 413 | if (__cerb) |
adb31ad6 | 414 | { |
bc2631e0 | 415 | __try |
adb31ad6 PC |
416 | { |
417 | const int_type __idelim = traits_type::to_int_type(__delim); | |
418 | const int_type __eof = traits_type::eof(); | |
419 | __streambuf_type* __sb = this->rdbuf(); | |
420 | int_type __c = __sb->sgetc(); | |
421 | ||
422 | while (_M_gcount + 1 < __n | |
423 | && !traits_type::eq_int_type(__c, __eof) | |
424 | && !traits_type::eq_int_type(__c, __idelim)) | |
425 | { | |
426 | *__s++ = traits_type::to_char_type(__c); | |
427 | __c = __sb->snextc(); | |
428 | ++_M_gcount; | |
429 | } | |
430 | if (traits_type::eq_int_type(__c, __eof)) | |
431 | __err |= ios_base::eofbit; | |
432 | else | |
433 | { | |
434 | if (traits_type::eq_int_type(__c, __idelim)) | |
435 | { | |
436 | __sb->sbumpc(); | |
437 | ++_M_gcount; | |
438 | } | |
439 | else | |
440 | __err |= ios_base::failbit; | |
441 | } | |
442 | } | |
bc2631e0 | 443 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
444 | { |
445 | this->_M_setstate(ios_base::badbit); | |
446 | __throw_exception_again; | |
447 | } | |
bc2631e0 | 448 | __catch(...) |
adb31ad6 PC |
449 | { this->_M_setstate(ios_base::badbit); } |
450 | } | |
75a25e3f PC |
451 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
452 | // 243. get and getline when sentry reports failure. | |
453 | if (__n > 0) | |
454 | *__s = char_type(); | |
725dc051 | 455 | if (!_M_gcount) |
adb31ad6 | 456 | __err |= ios_base::failbit; |
6b98580b | 457 | if (__err) |
adb31ad6 | 458 | this->setstate(__err); |
725dc051 BK |
459 | return *this; |
460 | } | |
ed6814f7 | 461 | |
80dddedc PC |
462 | // We provide three overloads, since the first two are much simpler |
463 | // than the general case. Also, the latter two can thus adopt the | |
464 | // same "batchy" strategy used by getline above. | |
465 | template<typename _CharT, typename _Traits> | |
466 | basic_istream<_CharT, _Traits>& | |
467 | basic_istream<_CharT, _Traits>:: | |
468 | ignore(void) | |
469 | { | |
470 | _M_gcount = 0; | |
471 | sentry __cerb(*this, true); | |
880b527f | 472 | if (__cerb) |
80dddedc | 473 | { |
6f0398bb | 474 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 475 | __try |
80dddedc PC |
476 | { |
477 | const int_type __eof = traits_type::eof(); | |
478 | __streambuf_type* __sb = this->rdbuf(); | |
479 | ||
480 | if (traits_type::eq_int_type(__sb->sbumpc(), __eof)) | |
481 | __err |= ios_base::eofbit; | |
482 | else | |
483 | _M_gcount = 1; | |
484 | } | |
bc2631e0 | 485 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
486 | { |
487 | this->_M_setstate(ios_base::badbit); | |
488 | __throw_exception_again; | |
489 | } | |
bc2631e0 | 490 | __catch(...) |
80dddedc PC |
491 | { this->_M_setstate(ios_base::badbit); } |
492 | if (__err) | |
493 | this->setstate(__err); | |
494 | } | |
495 | return *this; | |
496 | } | |
497 | ||
498 | template<typename _CharT, typename _Traits> | |
499 | basic_istream<_CharT, _Traits>& | |
500 | basic_istream<_CharT, _Traits>:: | |
501 | ignore(streamsize __n) | |
502 | { | |
80dddedc PC |
503 | _M_gcount = 0; |
504 | sentry __cerb(*this, true); | |
880b527f | 505 | if (__cerb && __n > 0) |
adb31ad6 | 506 | { |
6f0398bb | 507 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 508 | __try |
adb31ad6 PC |
509 | { |
510 | const int_type __eof = traits_type::eof(); | |
511 | __streambuf_type* __sb = this->rdbuf(); | |
bea53dbf PC |
512 | int_type __c = __sb->sgetc(); |
513 | ||
1e156882 PC |
514 | // N.B. On LFS-enabled platforms streamsize is still 32 bits |
515 | // wide: if we want to implement the standard mandated behavior | |
516 | // for n == max() (see 27.6.1.3/24) we are at risk of signed | |
517 | // integer overflow: thus these contortions. Also note that, | |
518 | // by definition, when more than 2G chars are actually ignored, | |
519 | // _M_gcount (the return value of gcount, that is) cannot be | |
520 | // really correct, being unavoidably too small. | |
78593d78 | 521 | bool __large_ignore = false; |
bea53dbf PC |
522 | while (true) |
523 | { | |
524 | while (_M_gcount < __n | |
525 | && !traits_type::eq_int_type(__c, __eof)) | |
526 | { | |
527 | ++_M_gcount; | |
528 | __c = __sb->snextc(); | |
529 | } | |
6725add5 | 530 | if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max |
bea53dbf | 531 | && !traits_type::eq_int_type(__c, __eof)) |
78593d78 | 532 | { |
6725add5 PC |
533 | _M_gcount = |
534 | __gnu_cxx::__numeric_traits<streamsize>::__min; | |
78593d78 PC |
535 | __large_ignore = true; |
536 | } | |
bea53dbf PC |
537 | else |
538 | break; | |
539 | } | |
adb31ad6 | 540 | |
78593d78 | 541 | if (__large_ignore) |
6725add5 | 542 | _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max; |
78593d78 | 543 | |
a141a5af | 544 | if (traits_type::eq_int_type(__c, __eof)) |
adb31ad6 PC |
545 | __err |= ios_base::eofbit; |
546 | } | |
bc2631e0 | 547 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
548 | { |
549 | this->_M_setstate(ios_base::badbit); | |
550 | __throw_exception_again; | |
551 | } | |
bc2631e0 | 552 | __catch(...) |
adb31ad6 PC |
553 | { this->_M_setstate(ios_base::badbit); } |
554 | if (__err) | |
555 | this->setstate(__err); | |
556 | } | |
80dddedc PC |
557 | return *this; |
558 | } | |
559 | ||
725dc051 BK |
560 | template<typename _CharT, typename _Traits> |
561 | basic_istream<_CharT, _Traits>& | |
562 | basic_istream<_CharT, _Traits>:: | |
563 | ignore(streamsize __n, int_type __delim) | |
564 | { | |
565 | _M_gcount = 0; | |
566 | sentry __cerb(*this, true); | |
880b527f | 567 | if (__cerb && __n > 0) |
adb31ad6 | 568 | { |
6f0398bb | 569 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 570 | __try |
adb31ad6 PC |
571 | { |
572 | const int_type __eof = traits_type::eof(); | |
573 | __streambuf_type* __sb = this->rdbuf(); | |
bea53dbf PC |
574 | int_type __c = __sb->sgetc(); |
575 | ||
1e156882 | 576 | // See comment above. |
78593d78 | 577 | bool __large_ignore = false; |
bea53dbf PC |
578 | while (true) |
579 | { | |
580 | while (_M_gcount < __n | |
581 | && !traits_type::eq_int_type(__c, __eof) | |
582 | && !traits_type::eq_int_type(__c, __delim)) | |
583 | { | |
584 | ++_M_gcount; | |
585 | __c = __sb->snextc(); | |
586 | } | |
6725add5 | 587 | if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max |
bea53dbf PC |
588 | && !traits_type::eq_int_type(__c, __eof) |
589 | && !traits_type::eq_int_type(__c, __delim)) | |
78593d78 | 590 | { |
6725add5 PC |
591 | _M_gcount = |
592 | __gnu_cxx::__numeric_traits<streamsize>::__min; | |
78593d78 PC |
593 | __large_ignore = true; |
594 | } | |
bea53dbf PC |
595 | else |
596 | break; | |
597 | } | |
adb31ad6 | 598 | |
78593d78 | 599 | if (__large_ignore) |
6725add5 | 600 | _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max; |
78593d78 | 601 | |
a141a5af | 602 | if (traits_type::eq_int_type(__c, __eof)) |
adb31ad6 | 603 | __err |= ios_base::eofbit; |
a141a5af | 604 | else if (traits_type::eq_int_type(__c, __delim)) |
bea53dbf | 605 | { |
6725add5 PC |
606 | if (_M_gcount |
607 | < __gnu_cxx::__numeric_traits<streamsize>::__max) | |
78593d78 | 608 | ++_M_gcount; |
bea53dbf PC |
609 | __sb->sbumpc(); |
610 | } | |
adb31ad6 | 611 | } |
bc2631e0 | 612 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
613 | { |
614 | this->_M_setstate(ios_base::badbit); | |
615 | __throw_exception_again; | |
616 | } | |
bc2631e0 | 617 | __catch(...) |
adb31ad6 PC |
618 | { this->_M_setstate(ios_base::badbit); } |
619 | if (__err) | |
620 | this->setstate(__err); | |
621 | } | |
725dc051 BK |
622 | return *this; |
623 | } | |
ed6814f7 | 624 | |
725dc051 | 625 | template<typename _CharT, typename _Traits> |
31bfa177 | 626 | typename basic_istream<_CharT, _Traits>::int_type |
725dc051 BK |
627 | basic_istream<_CharT, _Traits>:: |
628 | peek(void) | |
629 | { | |
630 | int_type __c = traits_type::eof(); | |
631 | _M_gcount = 0; | |
632 | sentry __cerb(*this, true); | |
880b527f | 633 | if (__cerb) |
725dc051 | 634 | { |
6f0398bb | 635 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 636 | __try |
e5012ba5 PC |
637 | { |
638 | __c = this->rdbuf()->sgetc(); | |
639 | if (traits_type::eq_int_type(__c, traits_type::eof())) | |
12841eb3 | 640 | __err |= ios_base::eofbit; |
e5012ba5 | 641 | } |
bc2631e0 | 642 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
643 | { |
644 | this->_M_setstate(ios_base::badbit); | |
645 | __throw_exception_again; | |
646 | } | |
bc2631e0 | 647 | __catch(...) |
12841eb3 | 648 | { this->_M_setstate(ios_base::badbit); } |
6b98580b BK |
649 | if (__err) |
650 | this->setstate(__err); | |
ed6814f7 | 651 | } |
725dc051 BK |
652 | return __c; |
653 | } | |
654 | ||
655 | template<typename _CharT, typename _Traits> | |
656 | basic_istream<_CharT, _Traits>& | |
657 | basic_istream<_CharT, _Traits>:: | |
658 | read(char_type* __s, streamsize __n) | |
659 | { | |
660 | _M_gcount = 0; | |
661 | sentry __cerb(*this, true); | |
880b527f | 662 | if (__cerb) |
725dc051 | 663 | { |
6f0398bb | 664 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 665 | __try |
725dc051 | 666 | { |
6280bdbe | 667 | _M_gcount = this->rdbuf()->sgetn(__s, __n); |
b2e4f4fd | 668 | if (_M_gcount != __n) |
12841eb3 | 669 | __err |= (ios_base::eofbit | ios_base::failbit); |
ed6814f7 | 670 | } |
bc2631e0 | 671 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
672 | { |
673 | this->_M_setstate(ios_base::badbit); | |
674 | __throw_exception_again; | |
675 | } | |
bc2631e0 | 676 | __catch(...) |
12841eb3 | 677 | { this->_M_setstate(ios_base::badbit); } |
6b98580b BK |
678 | if (__err) |
679 | this->setstate(__err); | |
725dc051 | 680 | } |
725dc051 BK |
681 | return *this; |
682 | } | |
ed6814f7 | 683 | |
725dc051 | 684 | template<typename _CharT, typename _Traits> |
ed6814f7 | 685 | streamsize |
725dc051 BK |
686 | basic_istream<_CharT, _Traits>:: |
687 | readsome(char_type* __s, streamsize __n) | |
688 | { | |
725dc051 BK |
689 | _M_gcount = 0; |
690 | sentry __cerb(*this, true); | |
880b527f | 691 | if (__cerb) |
725dc051 | 692 | { |
6f0398bb | 693 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 694 | __try |
725dc051 | 695 | { |
112615e7 | 696 | // Cannot compare int_type with streamsize generically. |
32da6208 PC |
697 | const streamsize __num = this->rdbuf()->in_avail(); |
698 | if (__num > 0) | |
6280bdbe | 699 | _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n)); |
32da6208 | 700 | else if (__num == -1) |
12841eb3 | 701 | __err |= ios_base::eofbit; |
36ce7daa | 702 | } |
bc2631e0 | 703 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
704 | { |
705 | this->_M_setstate(ios_base::badbit); | |
706 | __throw_exception_again; | |
707 | } | |
bc2631e0 | 708 | __catch(...) |
12841eb3 | 709 | { this->_M_setstate(ios_base::badbit); } |
6b98580b BK |
710 | if (__err) |
711 | this->setstate(__err); | |
725dc051 | 712 | } |
725dc051 BK |
713 | return _M_gcount; |
714 | } | |
ed6814f7 | 715 | |
725dc051 BK |
716 | template<typename _CharT, typename _Traits> |
717 | basic_istream<_CharT, _Traits>& | |
718 | basic_istream<_CharT, _Traits>:: | |
719 | putback(char_type __c) | |
720 | { | |
f5677b15 PC |
721 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
722 | // 60. What is a formatted input function? | |
23cac885 | 723 | _M_gcount = 0; |
2ca2a899 PC |
724 | // Clear eofbit per N3168. |
725 | this->clear(this->rdstate() & ~ios_base::eofbit); | |
725dc051 | 726 | sentry __cerb(*this, true); |
880b527f | 727 | if (__cerb) |
725dc051 | 728 | { |
6f0398bb | 729 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 730 | __try |
bfa1e6b1 BK |
731 | { |
732 | const int_type __eof = traits_type::eof(); | |
733 | __streambuf_type* __sb = this->rdbuf(); | |
ed6814f7 | 734 | if (!__sb |
f13a69ec | 735 | || traits_type::eq_int_type(__sb->sputbackc(__c), __eof)) |
12841eb3 | 736 | __err |= ios_base::badbit; |
bfa1e6b1 | 737 | } |
bc2631e0 | 738 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
739 | { |
740 | this->_M_setstate(ios_base::badbit); | |
741 | __throw_exception_again; | |
742 | } | |
bc2631e0 | 743 | __catch(...) |
12841eb3 | 744 | { this->_M_setstate(ios_base::badbit); } |
6b98580b BK |
745 | if (__err) |
746 | this->setstate(__err); | |
725dc051 | 747 | } |
725dc051 BK |
748 | return *this; |
749 | } | |
ed6814f7 | 750 | |
725dc051 BK |
751 | template<typename _CharT, typename _Traits> |
752 | basic_istream<_CharT, _Traits>& | |
753 | basic_istream<_CharT, _Traits>:: | |
754 | unget(void) | |
755 | { | |
f5677b15 PC |
756 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
757 | // 60. What is a formatted input function? | |
725dc051 | 758 | _M_gcount = 0; |
2ca2a899 PC |
759 | // Clear eofbit per N3168. |
760 | this->clear(this->rdstate() & ~ios_base::eofbit); | |
725dc051 | 761 | sentry __cerb(*this, true); |
880b527f | 762 | if (__cerb) |
725dc051 | 763 | { |
6f0398bb | 764 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 765 | __try |
bfa1e6b1 BK |
766 | { |
767 | const int_type __eof = traits_type::eof(); | |
768 | __streambuf_type* __sb = this->rdbuf(); | |
ed6814f7 | 769 | if (!__sb |
f13a69ec | 770 | || traits_type::eq_int_type(__sb->sungetc(), __eof)) |
12841eb3 | 771 | __err |= ios_base::badbit; |
bfa1e6b1 | 772 | } |
bc2631e0 | 773 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
774 | { |
775 | this->_M_setstate(ios_base::badbit); | |
776 | __throw_exception_again; | |
777 | } | |
bc2631e0 | 778 | __catch(...) |
12841eb3 | 779 | { this->_M_setstate(ios_base::badbit); } |
6b98580b BK |
780 | if (__err) |
781 | this->setstate(__err); | |
725dc051 | 782 | } |
725dc051 BK |
783 | return *this; |
784 | } | |
ed6814f7 | 785 | |
725dc051 BK |
786 | template<typename _CharT, typename _Traits> |
787 | int | |
788 | basic_istream<_CharT, _Traits>:: | |
789 | sync(void) | |
790 | { | |
12841eb3 | 791 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
6894ddcf | 792 | // DR60. Do not change _M_gcount. |
f13a69ec | 793 | int __ret = -1; |
725dc051 | 794 | sentry __cerb(*this, true); |
880b527f | 795 | if (__cerb) |
725dc051 | 796 | { |
6f0398bb | 797 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 798 | __try |
bfa1e6b1 BK |
799 | { |
800 | __streambuf_type* __sb = this->rdbuf(); | |
f13a69ec BK |
801 | if (__sb) |
802 | { | |
803 | if (__sb->pubsync() == -1) | |
12841eb3 | 804 | __err |= ios_base::badbit; |
ed6814f7 | 805 | else |
f13a69ec BK |
806 | __ret = 0; |
807 | } | |
bfa1e6b1 | 808 | } |
bc2631e0 | 809 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
810 | { |
811 | this->_M_setstate(ios_base::badbit); | |
812 | __throw_exception_again; | |
813 | } | |
bc2631e0 | 814 | __catch(...) |
12841eb3 | 815 | { this->_M_setstate(ios_base::badbit); } |
6b98580b BK |
816 | if (__err) |
817 | this->setstate(__err); | |
725dc051 BK |
818 | } |
819 | return __ret; | |
820 | } | |
ed6814f7 | 821 | |
725dc051 BK |
822 | template<typename _CharT, typename _Traits> |
823 | typename basic_istream<_CharT, _Traits>::pos_type | |
824 | basic_istream<_CharT, _Traits>:: | |
825 | tellg(void) | |
826 | { | |
12841eb3 | 827 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
d8c30611 | 828 | // DR60. Do not change _M_gcount. |
725dc051 | 829 | pos_type __ret = pos_type(-1); |
2ca2a899 PC |
830 | sentry __cerb(*this, true); |
831 | if (__cerb) | |
d05f74f1 | 832 | { |
2ca2a899 PC |
833 | __try |
834 | { | |
835 | if (!this->fail()) | |
836 | __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, | |
837 | ios_base::in); | |
838 | } | |
839 | __catch(__cxxabiv1::__forced_unwind&) | |
840 | { | |
841 | this->_M_setstate(ios_base::badbit); | |
842 | __throw_exception_again; | |
843 | } | |
844 | __catch(...) | |
845 | { this->_M_setstate(ios_base::badbit); } | |
d05f74f1 | 846 | } |
725dc051 BK |
847 | return __ret; |
848 | } | |
849 | ||
725dc051 BK |
850 | template<typename _CharT, typename _Traits> |
851 | basic_istream<_CharT, _Traits>& | |
852 | basic_istream<_CharT, _Traits>:: | |
853 | seekg(pos_type __pos) | |
854 | { | |
12841eb3 | 855 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
6894ddcf | 856 | // DR60. Do not change _M_gcount. |
2ca2a899 PC |
857 | // Clear eofbit per N3168. |
858 | this->clear(this->rdstate() & ~ios_base::eofbit); | |
859 | sentry __cerb(*this, true); | |
860 | if (__cerb) | |
725dc051 | 861 | { |
2ca2a899 PC |
862 | ios_base::iostate __err = ios_base::goodbit; |
863 | __try | |
12841eb3 | 864 | { |
2ca2a899 PC |
865 | if (!this->fail()) |
866 | { | |
867 | // 136. seekp, seekg setting wrong streams? | |
868 | const pos_type __p = this->rdbuf()->pubseekpos(__pos, | |
869 | ios_base::in); | |
870 | ||
871 | // 129. Need error indication from seekp() and seekg() | |
872 | if (__p == pos_type(off_type(-1))) | |
873 | __err |= ios_base::failbit; | |
874 | } | |
12841eb3 | 875 | } |
2ca2a899 PC |
876 | __catch(__cxxabiv1::__forced_unwind&) |
877 | { | |
878 | this->_M_setstate(ios_base::badbit); | |
879 | __throw_exception_again; | |
880 | } | |
881 | __catch(...) | |
882 | { this->_M_setstate(ios_base::badbit); } | |
883 | if (__err) | |
884 | this->setstate(__err); | |
725dc051 BK |
885 | } |
886 | return *this; | |
887 | } | |
888 | ||
889 | template<typename _CharT, typename _Traits> | |
890 | basic_istream<_CharT, _Traits>& | |
891 | basic_istream<_CharT, _Traits>:: | |
892 | seekg(off_type __off, ios_base::seekdir __dir) | |
893 | { | |
12841eb3 | 894 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
6894ddcf | 895 | // DR60. Do not change _M_gcount. |
2ca2a899 PC |
896 | // Clear eofbit per N3168. |
897 | this->clear(this->rdstate() & ~ios_base::eofbit); | |
898 | sentry __cerb(*this, true); | |
899 | if (__cerb) | |
725dc051 | 900 | { |
2ca2a899 PC |
901 | ios_base::iostate __err = ios_base::goodbit; |
902 | __try | |
12841eb3 | 903 | { |
2ca2a899 PC |
904 | if (!this->fail()) |
905 | { | |
906 | // 136. seekp, seekg setting wrong streams? | |
907 | const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir, | |
908 | ios_base::in); | |
c849c938 | 909 | |
2ca2a899 PC |
910 | // 129. Need error indication from seekp() and seekg() |
911 | if (__p == pos_type(off_type(-1))) | |
912 | __err |= ios_base::failbit; | |
913 | } | |
12841eb3 | 914 | } |
2ca2a899 PC |
915 | __catch(__cxxabiv1::__forced_unwind&) |
916 | { | |
917 | this->_M_setstate(ios_base::badbit); | |
918 | __throw_exception_again; | |
919 | } | |
920 | __catch(...) | |
921 | { this->_M_setstate(ios_base::badbit); } | |
922 | if (__err) | |
923 | this->setstate(__err); | |
725dc051 BK |
924 | } |
925 | return *this; | |
926 | } | |
927 | ||
928 | // 27.6.1.2.3 Character extraction templates | |
929 | template<typename _CharT, typename _Traits> | |
930 | basic_istream<_CharT, _Traits>& | |
931 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) | |
932 | { | |
ed6814f7 | 933 | typedef basic_istream<_CharT, _Traits> __istream_type; |
3adf6cad PC |
934 | typedef typename __istream_type::int_type __int_type; |
935 | ||
bcd0cabb | 936 | typename __istream_type::sentry __cerb(__in, false); |
880b527f | 937 | if (__cerb) |
725dc051 | 938 | { |
6f0398bb | 939 | ios_base::iostate __err = ios_base::goodbit; |
bc2631e0 | 940 | __try |
bfa1e6b1 | 941 | { |
3adf6cad | 942 | const __int_type __cb = __in.rdbuf()->sbumpc(); |
12841eb3 BK |
943 | if (!_Traits::eq_int_type(__cb, _Traits::eof())) |
944 | __c = _Traits::to_char_type(__cb); | |
945 | else | |
946 | __err |= (ios_base::eofbit | ios_base::failbit); | |
bfa1e6b1 | 947 | } |
bc2631e0 | 948 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
949 | { |
950 | __in._M_setstate(ios_base::badbit); | |
951 | __throw_exception_again; | |
952 | } | |
bc2631e0 | 953 | __catch(...) |
12841eb3 | 954 | { __in._M_setstate(ios_base::badbit); } |
6b98580b BK |
955 | if (__err) |
956 | __in.setstate(__err); | |
725dc051 | 957 | } |
725dc051 BK |
958 | return __in; |
959 | } | |
960 | ||
961 | template<typename _CharT, typename _Traits> | |
962 | basic_istream<_CharT, _Traits>& | |
963 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s) | |
964 | { | |
ed6814f7 | 965 | typedef basic_istream<_CharT, _Traits> __istream_type; |
11202768 | 966 | typedef basic_streambuf<_CharT, _Traits> __streambuf_type; |
ed6814f7 BI |
967 | typedef typename _Traits::int_type int_type; |
968 | typedef _CharT char_type; | |
969 | typedef ctype<_CharT> __ctype_type; | |
725dc051 | 970 | |
12841eb3 | 971 | streamsize __extracted = 0; |
6f0398bb | 972 | ios_base::iostate __err = ios_base::goodbit; |
bcd0cabb | 973 | typename __istream_type::sentry __cerb(__in, false); |
880b527f | 974 | if (__cerb) |
725dc051 | 975 | { |
bc2631e0 | 976 | __try |
bfa1e6b1 BK |
977 | { |
978 | // Figure out how many characters to extract. | |
979 | streamsize __num = __in.width(); | |
1e64c2fc | 980 | if (__num <= 0) |
6725add5 | 981 | __num = __gnu_cxx::__numeric_traits<streamsize>::__max; |
ed6814f7 | 982 | |
2803847d BK |
983 | const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); |
984 | ||
40e5b283 | 985 | const int_type __eof = _Traits::eof(); |
bfa1e6b1 | 986 | __streambuf_type* __sb = __in.rdbuf(); |
42ca0438 | 987 | int_type __c = __sb->sgetc(); |
ed6814f7 BI |
988 | |
989 | while (__extracted < __num - 1 | |
112615e7 | 990 | && !_Traits::eq_int_type(__c, __eof) |
ed6814f7 | 991 | && !__ct.is(ctype_base::space, |
2803847d | 992 | _Traits::to_char_type(__c))) |
bfa1e6b1 | 993 | { |
1deba98b | 994 | *__s++ = _Traits::to_char_type(__c); |
bfa1e6b1 | 995 | ++__extracted; |
42ca0438 | 996 | __c = __sb->snextc(); |
bfa1e6b1 | 997 | } |
112615e7 | 998 | if (_Traits::eq_int_type(__c, __eof)) |
12841eb3 | 999 | __err |= ios_base::eofbit; |
725dc051 | 1000 | |
f5677b15 PC |
1001 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1002 | // 68. Extractors for char* should store null at end | |
bfa1e6b1 | 1003 | *__s = char_type(); |
bfa1e6b1 BK |
1004 | __in.width(0); |
1005 | } | |
bc2631e0 | 1006 | __catch(__cxxabiv1::__forced_unwind&) |
d05f74f1 JM |
1007 | { |
1008 | __in._M_setstate(ios_base::badbit); | |
1009 | __throw_exception_again; | |
1010 | } | |
bc2631e0 | 1011 | __catch(...) |
12841eb3 | 1012 | { __in._M_setstate(ios_base::badbit); } |
725dc051 BK |
1013 | } |
1014 | if (!__extracted) | |
12841eb3 | 1015 | __err |= ios_base::failbit; |
6b98580b BK |
1016 | if (__err) |
1017 | __in.setstate(__err); | |
725dc051 BK |
1018 | return __in; |
1019 | } | |
1020 | ||
1021 | // 27.6.1.4 Standard basic_istream manipulators | |
1022 | template<typename _CharT, typename _Traits> | |
11202768 PC |
1023 | basic_istream<_CharT, _Traits>& |
1024 | ws(basic_istream<_CharT, _Traits>& __in) | |
725dc051 | 1025 | { |
ed6814f7 | 1026 | typedef basic_istream<_CharT, _Traits> __istream_type; |
11202768 | 1027 | typedef basic_streambuf<_CharT, _Traits> __streambuf_type; |
ed6814f7 | 1028 | typedef typename __istream_type::int_type __int_type; |
11202768 | 1029 | typedef ctype<_CharT> __ctype_type; |
725dc051 | 1030 | |
2803847d | 1031 | const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); |
ed6814f7 | 1032 | const __int_type __eof = _Traits::eof(); |
42ca0438 BK |
1033 | __streambuf_type* __sb = __in.rdbuf(); |
1034 | __int_type __c = __sb->sgetc(); | |
725dc051 | 1035 | |
ed6814f7 | 1036 | while (!_Traits::eq_int_type(__c, __eof) |
2803847d | 1037 | && __ct.is(ctype_base::space, _Traits::to_char_type(__c))) |
42ca0438 | 1038 | __c = __sb->snextc(); |
112615e7 BK |
1039 | |
1040 | if (_Traits::eq_int_type(__c, __eof)) | |
12841eb3 | 1041 | __in.setstate(ios_base::eofbit); |
725dc051 BK |
1042 | return __in; |
1043 | } | |
1044 | ||
a32e3c09 | 1045 | // Inhibit implicit instantiations for required instantiations, |
ed6814f7 | 1046 | // which are defined via explicit instantiations elsewhere. |
3d7c150e | 1047 | #if _GLIBCXX_EXTERN_TEMPLATE |
a32e3c09 BK |
1048 | extern template class basic_istream<char>; |
1049 | extern template istream& ws(istream&); | |
1050 | extern template istream& operator>>(istream&, char&); | |
1051 | extern template istream& operator>>(istream&, char*); | |
1052 | extern template istream& operator>>(istream&, unsigned char&); | |
1053 | extern template istream& operator>>(istream&, signed char&); | |
1054 | extern template istream& operator>>(istream&, unsigned char*); | |
1055 | extern template istream& operator>>(istream&, signed char*); | |
1056 | ||
f12409e6 PC |
1057 | extern template istream& istream::_M_extract(unsigned short&); |
1058 | extern template istream& istream::_M_extract(unsigned int&); | |
1059 | extern template istream& istream::_M_extract(long&); | |
1060 | extern template istream& istream::_M_extract(unsigned long&); | |
1061 | extern template istream& istream::_M_extract(bool&); | |
1062 | #ifdef _GLIBCXX_USE_LONG_LONG | |
1063 | extern template istream& istream::_M_extract(long long&); | |
1064 | extern template istream& istream::_M_extract(unsigned long long&); | |
1065 | #endif | |
1066 | extern template istream& istream::_M_extract(float&); | |
1067 | extern template istream& istream::_M_extract(double&); | |
1068 | extern template istream& istream::_M_extract(long double&); | |
1069 | extern template istream& istream::_M_extract(void*&); | |
1070 | ||
98599ff8 BK |
1071 | extern template class basic_iostream<char>; |
1072 | ||
3d7c150e | 1073 | #ifdef _GLIBCXX_USE_WCHAR_T |
a32e3c09 BK |
1074 | extern template class basic_istream<wchar_t>; |
1075 | extern template wistream& ws(wistream&); | |
1076 | extern template wistream& operator>>(wistream&, wchar_t&); | |
1077 | extern template wistream& operator>>(wistream&, wchar_t*); | |
98599ff8 | 1078 | |
f12409e6 PC |
1079 | extern template wistream& wistream::_M_extract(unsigned short&); |
1080 | extern template wistream& wistream::_M_extract(unsigned int&); | |
1081 | extern template wistream& wistream::_M_extract(long&); | |
1082 | extern template wistream& wistream::_M_extract(unsigned long&); | |
1083 | extern template wistream& wistream::_M_extract(bool&); | |
1084 | #ifdef _GLIBCXX_USE_LONG_LONG | |
1085 | extern template wistream& wistream::_M_extract(long long&); | |
1086 | extern template wistream& wistream::_M_extract(unsigned long long&); | |
1087 | #endif | |
1088 | extern template wistream& wistream::_M_extract(float&); | |
1089 | extern template wistream& wistream::_M_extract(double&); | |
1090 | extern template wistream& wistream::_M_extract(long double&); | |
1091 | extern template wistream& wistream::_M_extract(void*&); | |
1092 | ||
98599ff8 | 1093 | extern template class basic_iostream<wchar_t>; |
3522a91b | 1094 | #endif |
1bc8b0ad | 1095 | #endif |
3cbc7af0 | 1096 | |
12ffa228 | 1097 | _GLIBCXX_END_NAMESPACE_VERSION |
ed4f96af | 1098 | } // namespace std |
3d7c150e BK |
1099 | |
1100 | #endif |