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