1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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.
32 // ISO C++ 14882: 27.6.2 Output streams
36 #define _ISTREAM_TCC 1
38 #pragma GCC system_header
41 #include <ostream> // For flush()
45 template<typename _CharT, typename _Traits>
46 basic_istream<_CharT, _Traits>::sentry::
47 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
53 if (!__noskipws && (__in.flags() & ios_base::skipws))
55 const __int_type __eof = traits_type::eof();
56 __streambuf_type* __sb = __in.rdbuf();
57 __int_type __c = __sb->sgetc();
59 __check_facet(__in._M_ctype);
60 while (!traits_type::eq_int_type(__c, __eof)
61 && __in._M_ctype->is(ctype_base::space,
62 traits_type::to_char_type(__c)))
65 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
66 //195. Should basic_istream::sentry's constructor ever set eofbit?
67 if (traits_type::eq_int_type(__c, __eof))
68 __in.setstate(ios_base::eofbit);
78 __in.setstate(ios_base::failbit);
82 template<typename _CharT, typename _Traits>
83 basic_istream<_CharT, _Traits>&
84 basic_istream<_CharT, _Traits>::
85 operator>>(__istream_type& (*__pf)(__istream_type&))
91 template<typename _CharT, typename _Traits>
92 basic_istream<_CharT, _Traits>&
93 basic_istream<_CharT, _Traits>::
94 operator>>(__ios_type& (*__pf)(__ios_type&))
100 template<typename _CharT, typename _Traits>
101 basic_istream<_CharT, _Traits>&
102 basic_istream<_CharT, _Traits>::
103 operator>>(ios_base& (*__pf)(ios_base&))
109 template<typename _CharT, typename _Traits>
110 basic_istream<_CharT, _Traits>&
111 basic_istream<_CharT, _Traits>::
112 operator>>(bool& __n)
114 sentry __cerb(*this, false);
119 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
120 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
121 this->setstate(__err);
125 // 27.6.1.2.1 Common requirements.
126 // Turn this on without causing an ios::failure to be thrown.
127 this->_M_setstate(ios_base::badbit);
128 if ((this->exceptions() & ios_base::badbit) != 0)
129 __throw_exception_again;
135 template<typename _CharT, typename _Traits>
136 basic_istream<_CharT, _Traits>&
137 basic_istream<_CharT, _Traits>::
138 operator>>(short& __n)
140 sentry __cerb(*this, false);
145 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
147 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __l);
148 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
149 // 118. basic_istream uses nonexistent num_get member functions.
150 if (!(__err & ios_base::failbit)
151 && (numeric_limits<short>::min() <= __l
152 && __l <= numeric_limits<short>::max()))
155 __err |= ios_base::failbit;
157 this->setstate(__err);
161 // 27.6.1.2.1 Common requirements.
162 // Turn this on without causing an ios::failure to be thrown.
163 this->_M_setstate(ios_base::badbit);
164 if ((this->exceptions() & ios_base::badbit) != 0)
165 __throw_exception_again;
171 template<typename _CharT, typename _Traits>
172 basic_istream<_CharT, _Traits>&
173 basic_istream<_CharT, _Traits>::
174 operator>>(unsigned short& __n)
176 sentry __cerb(*this, false);
181 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
182 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
183 this->setstate(__err);
187 // 27.6.1.2.1 Common requirements.
188 // Turn this on without causing an ios::failure to be thrown.
189 this->_M_setstate(ios_base::badbit);
190 if ((this->exceptions() & ios_base::badbit) != 0)
191 __throw_exception_again;
197 template<typename _CharT, typename _Traits>
198 basic_istream<_CharT, _Traits>&
199 basic_istream<_CharT, _Traits>::
202 sentry __cerb(*this, false);
207 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
209 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __l);
210 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
211 // 118. basic_istream uses nonexistent num_get member functions.
212 if (!(__err & ios_base::failbit)
213 && (numeric_limits<int>::min() <= __l
214 && __l <= numeric_limits<int>::max()))
217 __err |= ios_base::failbit;
219 this->setstate(__err);
223 // 27.6.1.2.1 Common requirements.
224 // Turn this on without causing an ios::failure to be thrown.
225 this->_M_setstate(ios_base::badbit);
226 if ((this->exceptions() & ios_base::badbit) != 0)
227 __throw_exception_again;
233 template<typename _CharT, typename _Traits>
234 basic_istream<_CharT, _Traits>&
235 basic_istream<_CharT, _Traits>::
236 operator>>(unsigned int& __n)
238 sentry __cerb(*this, false);
243 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
244 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
245 this->setstate(__err);
249 // 27.6.1.2.1 Common requirements.
250 // Turn this on without causing an ios::failure to be thrown.
251 this->_M_setstate(ios_base::badbit);
252 if ((this->exceptions() & ios_base::badbit) != 0)
253 __throw_exception_again;
259 template<typename _CharT, typename _Traits>
260 basic_istream<_CharT, _Traits>&
261 basic_istream<_CharT, _Traits>::
262 operator>>(long& __n)
264 sentry __cerb(*this, false);
269 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
270 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
271 this->setstate(__err);
275 // 27.6.1.2.1 Common requirements.
276 // Turn this on without causing an ios::failure to be thrown.
277 this->_M_setstate(ios_base::badbit);
278 if ((this->exceptions() & ios_base::badbit) != 0)
279 __throw_exception_again;
285 template<typename _CharT, typename _Traits>
286 basic_istream<_CharT, _Traits>&
287 basic_istream<_CharT, _Traits>::
288 operator>>(unsigned long& __n)
290 sentry __cerb(*this, false);
295 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
296 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
297 this->setstate(__err);
301 // 27.6.1.2.1 Common requirements.
302 // Turn this on without causing an ios::failure to be thrown.
303 this->_M_setstate(ios_base::badbit);
304 if ((this->exceptions() & ios_base::badbit) != 0)
305 __throw_exception_again;
311 #ifdef _GLIBCXX_USE_LONG_LONG
312 template<typename _CharT, typename _Traits>
313 basic_istream<_CharT, _Traits>&
314 basic_istream<_CharT, _Traits>::
315 operator>>(long long& __n)
317 sentry __cerb(*this, false);
322 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
323 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
324 this->setstate(__err);
328 // 27.6.1.2.1 Common requirements.
329 // Turn this on without causing an ios::failure to be thrown.
330 this->_M_setstate(ios_base::badbit);
331 if ((this->exceptions() & ios_base::badbit) != 0)
332 __throw_exception_again;
338 template<typename _CharT, typename _Traits>
339 basic_istream<_CharT, _Traits>&
340 basic_istream<_CharT, _Traits>::
341 operator>>(unsigned long long& __n)
343 sentry __cerb(*this, false);
348 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
349 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
350 this->setstate(__err);
354 // 27.6.1.2.1 Common requirements.
355 // Turn this on without causing an ios::failure to be thrown.
356 this->_M_setstate(ios_base::badbit);
357 if ((this->exceptions() & ios_base::badbit) != 0)
358 __throw_exception_again;
365 template<typename _CharT, typename _Traits>
366 basic_istream<_CharT, _Traits>&
367 basic_istream<_CharT, _Traits>::
368 operator>>(float& __n)
370 sentry __cerb(*this, false);
375 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
376 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
377 this->setstate(__err);
381 // 27.6.1.2.1 Common requirements.
382 // Turn this on without causing an ios::failure to be thrown.
383 this->_M_setstate(ios_base::badbit);
384 if ((this->exceptions() & ios_base::badbit) != 0)
385 __throw_exception_again;
391 template<typename _CharT, typename _Traits>
392 basic_istream<_CharT, _Traits>&
393 basic_istream<_CharT, _Traits>::
394 operator>>(double& __n)
396 sentry __cerb(*this, false);
401 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
402 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
403 this->setstate(__err);
407 // 27.6.1.2.1 Common requirements.
408 // Turn this on without causing an ios::failure to be thrown.
409 this->_M_setstate(ios_base::badbit);
410 if ((this->exceptions() & ios_base::badbit) != 0)
411 __throw_exception_again;
417 template<typename _CharT, typename _Traits>
418 basic_istream<_CharT, _Traits>&
419 basic_istream<_CharT, _Traits>::
420 operator>>(long double& __n)
422 sentry __cerb(*this, false);
427 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
428 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
429 this->setstate(__err);
433 // 27.6.1.2.1 Common requirements.
434 // Turn this on without causing an ios::failure to be thrown.
435 this->_M_setstate(ios_base::badbit);
436 if ((this->exceptions() & ios_base::badbit) != 0)
437 __throw_exception_again;
443 template<typename _CharT, typename _Traits>
444 basic_istream<_CharT, _Traits>&
445 basic_istream<_CharT, _Traits>::
446 operator>>(void*& __n)
448 sentry __cerb(*this, false);
453 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
454 __check_facet(this->_M_num_get).get(*this, 0, *this, __err, __n);
455 this->setstate(__err);
459 // 27.6.1.2.1 Common requirements.
460 // Turn this on without causing an ios::failure to be thrown.
461 this->_M_setstate(ios_base::badbit);
462 if ((this->exceptions() & ios_base::badbit) != 0)
463 __throw_exception_again;
469 template<typename _CharT, typename _Traits>
470 basic_istream<_CharT, _Traits>&
471 basic_istream<_CharT, _Traits>::
472 operator>>(__streambuf_type* __sbout)
474 sentry __cerb(*this, false);
479 streamsize __xtrct = 0;
482 __streambuf_type* __sbin = this->rdbuf();
483 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
485 if (!__sbout || !__xtrct)
486 this->setstate(ios_base::failbit);
490 // 27.6.2.5.1 Common requirements.
491 // Turn this on without causing an ios::failure to be thrown.
492 this->_M_setstate(ios_base::badbit);
493 if ((this->exceptions() & ios_base::badbit) != 0)
494 __throw_exception_again;
500 template<typename _CharT, typename _Traits>
501 typename basic_istream<_CharT, _Traits>::int_type
502 basic_istream<_CharT, _Traits>::
505 const int_type __eof = traits_type::eof();
506 int_type __c = __eof;
508 sentry __cerb(*this, true);
513 __c = this->rdbuf()->sbumpc();
514 // 27.6.1.1 paragraph 3
515 if (!traits_type::eq_int_type(__c, __eof))
518 this->setstate(ios_base::eofbit | ios_base::failbit);
522 // 27.6.1.3 paragraph 1
523 // Turn this on without causing an ios::failure to be thrown.
524 this->_M_setstate(ios_base::badbit);
525 if ((this->exceptions() & ios_base::badbit) != 0)
526 __throw_exception_again;
532 template<typename _CharT, typename _Traits>
533 basic_istream<_CharT, _Traits>&
534 basic_istream<_CharT, _Traits>::
538 sentry __cerb(*this, true);
543 const int_type __eof = traits_type::eof();
544 int_type __bufval = this->rdbuf()->sbumpc();
545 // 27.6.1.1 paragraph 3
546 if (!traits_type::eq_int_type(__bufval, __eof))
549 __c = traits_type::to_char_type(__bufval);
552 this->setstate(ios_base::eofbit | ios_base::failbit);
556 // 27.6.1.3 paragraph 1
557 // Turn this on without causing an ios::failure to be thrown.
558 this->_M_setstate(ios_base::badbit);
559 if ((this->exceptions() & ios_base::badbit) != 0)
560 __throw_exception_again;
566 template<typename _CharT, typename _Traits>
567 basic_istream<_CharT, _Traits>&
568 basic_istream<_CharT, _Traits>::
569 get(char_type* __s, streamsize __n, char_type __delim)
572 sentry __cerb(*this, true);
577 const int_type __idelim = traits_type::to_int_type(__delim);
578 const int_type __eof = traits_type::eof();
579 __streambuf_type* __sb = this->rdbuf();
580 int_type __c = __sb->sgetc();
582 while (_M_gcount + 1 < __n
583 && !traits_type::eq_int_type(__c, __eof)
584 && !traits_type::eq_int_type(__c, __idelim))
586 *__s++ = traits_type::to_char_type(__c);
587 __c = __sb->snextc();
590 if (traits_type::eq_int_type(__c, __eof))
591 this->setstate(ios_base::eofbit);
595 // 27.6.1.3 paragraph 1
596 // Turn this on without causing an ios::failure to be thrown.
597 this->_M_setstate(ios_base::badbit);
598 if ((this->exceptions() & ios_base::badbit) != 0)
599 __throw_exception_again;
604 this->setstate(ios_base::failbit);
608 template<typename _CharT, typename _Traits>
609 basic_istream<_CharT, _Traits>&
610 basic_istream<_CharT, _Traits>::
611 get(__streambuf_type& __sb, char_type __delim)
614 sentry __cerb(*this, true);
619 const int_type __idelim = traits_type::to_int_type(__delim);
620 const int_type __eof = traits_type::eof();
621 __streambuf_type* __this_sb = this->rdbuf();
622 int_type __c = __this_sb->sgetc();
623 char_type __c2 = traits_type::to_char_type(__c);
625 while (!traits_type::eq_int_type(__c, __eof)
626 && !traits_type::eq_int_type(__c, __idelim)
627 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
630 __c = __this_sb->snextc();
631 __c2 = traits_type::to_char_type(__c);
633 if (traits_type::eq_int_type(__c, __eof))
634 this->setstate(ios_base::eofbit);
638 // 27.6.1.3 paragraph 1
639 // Turn this on without causing an ios::failure to be thrown.
640 this->_M_setstate(ios_base::badbit);
641 if ((this->exceptions() & ios_base::badbit) != 0)
642 __throw_exception_again;
646 this->setstate(ios_base::failbit);
650 template<typename _CharT, typename _Traits>
651 basic_istream<_CharT, _Traits>&
652 basic_istream<_CharT, _Traits>::
653 getline(char_type* __s, streamsize __n, char_type __delim)
656 sentry __cerb(*this, true);
661 const int_type __idelim = traits_type::to_int_type(__delim);
662 const int_type __eof = traits_type::eof();
663 __streambuf_type* __sb = this->rdbuf();
664 int_type __c = __sb->sgetc();
666 while (_M_gcount + 1 < __n
667 && !traits_type::eq_int_type(__c, __eof)
668 && !traits_type::eq_int_type(__c, __idelim))
670 *__s++ = traits_type::to_char_type(__c);
671 __c = __sb->snextc();
674 if (traits_type::eq_int_type(__c, __eof))
675 this->setstate(ios_base::eofbit);
678 if (traits_type::eq_int_type(__c, __idelim))
684 this->setstate(ios_base::failbit);
689 // 27.6.1.3 paragraph 1
690 // Turn this on without causing an ios::failure to be thrown.
691 this->_M_setstate(ios_base::badbit);
692 if ((this->exceptions() & ios_base::badbit) != 0)
693 __throw_exception_again;
698 this->setstate(ios_base::failbit);
702 template<typename _CharT, typename _Traits>
703 basic_istream<_CharT, _Traits>&
704 basic_istream<_CharT, _Traits>::
705 ignore(streamsize __n, int_type __delim)
708 sentry __cerb(*this, true);
709 if (__cerb && __n > 0)
713 const int_type __eof = traits_type::eof();
714 __streambuf_type* __sb = this->rdbuf();
717 __n = std::min(__n, numeric_limits<streamsize>::max());
718 while (_M_gcount < __n
719 && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
722 if (traits_type::eq_int_type(__c, __delim))
725 if (traits_type::eq_int_type(__c, __eof))
726 this->setstate(ios_base::eofbit);
730 // 27.6.1.3 paragraph 1
731 // Turn this on without causing an ios::failure to be thrown.
732 this->_M_setstate(ios_base::badbit);
733 if ((this->exceptions() & ios_base::badbit) != 0)
734 __throw_exception_again;
740 template<typename _CharT, typename _Traits>
741 typename basic_istream<_CharT, _Traits>::int_type
742 basic_istream<_CharT, _Traits>::
745 int_type __c = traits_type::eof();
747 sentry __cerb(*this, true);
751 { __c = this->rdbuf()->sgetc(); }
754 // 27.6.1.3 paragraph 1
755 // Turn this on without causing an ios::failure to be thrown.
756 this->_M_setstate(ios_base::badbit);
757 if ((this->exceptions() & ios_base::badbit) != 0)
758 __throw_exception_again;
764 template<typename _CharT, typename _Traits>
765 basic_istream<_CharT, _Traits>&
766 basic_istream<_CharT, _Traits>::
767 read(char_type* __s, streamsize __n)
770 sentry __cerb(*this, true);
775 _M_gcount = this->rdbuf()->sgetn(__s, __n);
776 if (_M_gcount != __n)
777 this->setstate(ios_base::eofbit | ios_base::failbit);
781 // 27.6.1.3 paragraph 1
782 // Turn this on without causing an ios::failure to be thrown.
783 this->_M_setstate(ios_base::badbit);
784 if ((this->exceptions() & ios_base::badbit) != 0)
785 __throw_exception_again;
789 this->setstate(ios_base::failbit);
793 template<typename _CharT, typename _Traits>
795 basic_istream<_CharT, _Traits>::
796 readsome(char_type* __s, streamsize __n)
799 sentry __cerb(*this, true);
804 // Cannot compare int_type with streamsize generically.
805 streamsize __num = this->rdbuf()->in_avail();
808 __num = std::min(__num, __n);
810 _M_gcount = this->rdbuf()->sgetn(__s, __num);
813 this->setstate(ios_base::eofbit);
817 // 27.6.1.3 paragraph 1
818 // Turn this on without causing an ios::failure to be thrown.
819 this->_M_setstate(ios_base::badbit);
820 if ((this->exceptions() & ios_base::badbit) != 0)
821 __throw_exception_again;
825 this->setstate(ios_base::failbit);
829 template<typename _CharT, typename _Traits>
830 basic_istream<_CharT, _Traits>&
831 basic_istream<_CharT, _Traits>::
832 putback(char_type __c)
834 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
835 // 60. What is a formatted input function?
838 sentry __cerb(*this, true);
843 const int_type __eof = traits_type::eof();
844 __streambuf_type* __sb = this->rdbuf();
846 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
847 this->setstate(ios_base::badbit);
851 // 27.6.1.3 paragraph 1
852 // Turn this on without causing an ios::failure to be thrown.
853 this->_M_setstate(ios_base::badbit);
854 if ((this->exceptions() & ios_base::badbit) != 0)
855 __throw_exception_again;
859 this->setstate(ios_base::failbit);
863 template<typename _CharT, typename _Traits>
864 basic_istream<_CharT, _Traits>&
865 basic_istream<_CharT, _Traits>::
868 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
869 // 60. What is a formatted input function?
872 sentry __cerb(*this, true);
877 const int_type __eof = traits_type::eof();
878 __streambuf_type* __sb = this->rdbuf();
880 || traits_type::eq_int_type(__sb->sungetc(), __eof))
881 this->setstate(ios_base::badbit);
885 // 27.6.1.3 paragraph 1
886 // Turn this on without causing an ios::failure to be thrown.
887 this->_M_setstate(ios_base::badbit);
888 if ((this->exceptions() & ios_base::badbit) != 0)
889 __throw_exception_again;
893 this->setstate(ios_base::failbit);
897 template<typename _CharT, typename _Traits>
899 basic_istream<_CharT, _Traits>::
902 // DR60. Do not change _M_gcount.
904 sentry __cerb(*this, true);
909 __streambuf_type* __sb = this->rdbuf();
912 if (__sb->pubsync() == -1)
913 this->setstate(ios_base::badbit);
920 // 27.6.1.3 paragraph 1
921 // Turn this on without causing an ios::failure to be thrown.
922 this->_M_setstate(ios_base::badbit);
923 if ((this->exceptions() & ios_base::badbit) != 0)
924 __throw_exception_again;
930 template<typename _CharT, typename _Traits>
931 typename basic_istream<_CharT, _Traits>::pos_type
932 basic_istream<_CharT, _Traits>::
935 // DR60. Do not change _M_gcount.
936 pos_type __ret = pos_type(-1);
938 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
943 template<typename _CharT, typename _Traits>
944 basic_istream<_CharT, _Traits>&
945 basic_istream<_CharT, _Traits>::
946 seekg(pos_type __pos)
948 // DR60. Do not change _M_gcount.
951 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
952 // 136. seekp, seekg setting wrong streams?
953 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
955 // 129. Need error indication from seekp() and seekg()
956 if (__err == pos_type(off_type(-1)))
957 this->setstate(ios_base::failbit);
963 template<typename _CharT, typename _Traits>
964 basic_istream<_CharT, _Traits>&
965 basic_istream<_CharT, _Traits>::
966 seekg(off_type __off, ios_base::seekdir __dir)
968 // DR60. Do not change _M_gcount.
971 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
972 // 136. seekp, seekg setting wrong streams?
973 pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
976 // 129. Need error indication from seekp() and seekg()
977 if (__err == pos_type(off_type(-1)))
978 this->setstate(ios_base::failbit);
984 // 27.6.1.2.3 Character extraction templates
985 template<typename _CharT, typename _Traits>
986 basic_istream<_CharT, _Traits>&
987 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
989 typedef basic_istream<_CharT, _Traits> __istream_type;
990 typename __istream_type::sentry __cerb(__in, false);
997 // 27.6.1.2.1 Common requirements.
998 // Turn this on without causing an ios::failure to be thrown.
999 __in._M_setstate(ios_base::badbit);
1000 if ((__in.exceptions() & ios_base::badbit) != 0)
1001 __throw_exception_again;
1005 __in.setstate(ios_base::failbit);
1009 template<typename _CharT, typename _Traits>
1010 basic_istream<_CharT, _Traits>&
1011 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1013 typedef basic_istream<_CharT, _Traits> __istream_type;
1014 typedef typename __istream_type::__streambuf_type __streambuf_type;
1015 typedef typename _Traits::int_type int_type;
1016 typedef _CharT char_type;
1017 typedef ctype<_CharT> __ctype_type;
1018 streamsize __extracted = 0;
1020 typename __istream_type::sentry __cerb(__in, false);
1025 // Figure out how many characters to extract.
1026 streamsize __num = __in.width();
1028 __num = numeric_limits<streamsize>::max();
1030 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1031 const int_type __eof = _Traits::eof();
1032 __streambuf_type* __sb = __in.rdbuf();
1033 int_type __c = __sb->sgetc();
1035 while (__extracted < __num - 1
1036 && !_Traits::eq_int_type(__c, __eof)
1037 && !__ctype.is(ctype_base::space, _Traits::to_char_type(__c)))
1039 *__s++ = _Traits::to_char_type(__c);
1041 __c = __sb->snextc();
1043 if (_Traits::eq_int_type(__c, __eof))
1044 __in.setstate(ios_base::eofbit);
1046 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
1047 //68. Extractors for char* should store null at end
1054 // 27.6.1.2.1 Common requirements.
1055 // Turn this on without causing an ios::failure to be thrown.
1056 __in._M_setstate(ios_base::badbit);
1057 if ((__in.exceptions() & ios_base::badbit) != 0)
1058 __throw_exception_again;
1062 __in.setstate(ios_base::failbit);
1066 // 27.6.1.4 Standard basic_istream manipulators
1067 template<typename _CharT, typename _Traits>
1068 basic_istream<_CharT,_Traits>&
1069 ws(basic_istream<_CharT,_Traits>& __in)
1071 typedef basic_istream<_CharT, _Traits> __istream_type;
1072 typedef typename __istream_type::__streambuf_type __streambuf_type;
1073 typedef typename __istream_type::__ctype_type __ctype_type;
1074 typedef typename __istream_type::int_type __int_type;
1076 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1077 const __int_type __eof = _Traits::eof();
1078 __streambuf_type* __sb = __in.rdbuf();
1079 __int_type __c = __sb->sgetc();
1081 while (!_Traits::eq_int_type(__c, __eof)
1082 && __ctype.is(ctype_base::space, _Traits::to_char_type(__c)))
1083 __c = __sb->snextc();
1085 if (_Traits::eq_int_type(__c, __eof))
1086 __in.setstate(ios_base::eofbit);
1091 // 21.3.7.9 basic_string::getline and operators
1092 template<typename _CharT, typename _Traits, typename _Alloc>
1093 basic_istream<_CharT, _Traits>&
1094 operator>>(basic_istream<_CharT, _Traits>& __in,
1095 basic_string<_CharT, _Traits, _Alloc>& __str)
1097 typedef basic_istream<_CharT, _Traits> __istream_type;
1098 typedef typename __istream_type::int_type __int_type;
1099 typedef typename __istream_type::__streambuf_type __streambuf_type;
1100 typedef typename __istream_type::__ctype_type __ctype_type;
1101 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1102 typedef typename __string_type::size_type __size_type;
1103 __size_type __extracted = 0;
1105 typename __istream_type::sentry __cerb(__in, false);
1109 streamsize __w = __in.width();
1111 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1113 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1114 const __int_type __eof = _Traits::eof();
1115 __streambuf_type* __sb = __in.rdbuf();
1116 __int_type __c = __sb->sgetc();
1118 while (__extracted < __n
1119 && !_Traits::eq_int_type(__c, __eof)
1120 && !__ctype.is(ctype_base::space, _Traits::to_char_type(__c)))
1122 __str += _Traits::to_char_type(__c);
1124 __c = __sb->snextc();
1126 if (_Traits::eq_int_type(__c, __eof))
1127 __in.setstate(ios_base::eofbit);
1130 #ifdef _GLIBCXX_RESOLVE_LIB_DEFECTS
1131 //211. operator>>(istream&, string&) doesn't set failbit
1133 __in.setstate (ios_base::failbit);
1138 template<typename _CharT, typename _Traits, typename _Alloc>
1139 basic_istream<_CharT, _Traits>&
1140 getline(basic_istream<_CharT, _Traits>& __in,
1141 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1143 typedef basic_istream<_CharT, _Traits> __istream_type;
1144 typedef typename __istream_type::int_type __int_type;
1145 typedef typename __istream_type::__streambuf_type __streambuf_type;
1146 typedef typename __istream_type::__ctype_type __ctype_type;
1147 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1148 typedef typename __string_type::size_type __size_type;
1150 __size_type __extracted = 0;
1151 bool __testdelim = false;
1152 typename __istream_type::sentry __cerb(__in, true);
1156 __size_type __n = __str.max_size();
1158 __int_type __idelim = _Traits::to_int_type(__delim);
1159 __streambuf_type* __sb = __in.rdbuf();
1160 __int_type __c = __sb->sbumpc();
1161 const __int_type __eof = _Traits::eof();
1162 __testdelim = _Traits::eq_int_type(__c, __idelim);
1164 while (__extracted <= __n
1165 && !_Traits::eq_int_type(__c, __eof)
1168 __str += _Traits::to_char_type(__c);
1170 __c = __sb->sbumpc();
1171 __testdelim = _Traits::eq_int_type(__c, __idelim);
1173 if (_Traits::eq_int_type(__c, __eof))
1174 __in.setstate(ios_base::eofbit);
1176 if (!__extracted && !__testdelim)
1177 __in.setstate(ios_base::failbit);
1181 template<class _CharT, class _Traits, class _Alloc>
1182 inline basic_istream<_CharT,_Traits>&
1183 getline(basic_istream<_CharT, _Traits>& __in,
1184 basic_string<_CharT,_Traits,_Alloc>& __str)
1185 { return getline(__in, __str, __in.widen('\n')); }
1187 // Inhibit implicit instantiations for required instantiations,
1188 // which are defined via explicit instantiations elsewhere.
1189 // NB: This syntax is a GNU extension.
1190 #if _GLIBCXX_EXTERN_TEMPLATE
1191 extern template class basic_istream<char>;
1192 extern template istream& ws(istream&);
1193 extern template istream& operator>>(istream&, char&);
1194 extern template istream& operator>>(istream&, char*);
1195 extern template istream& operator>>(istream&, unsigned char&);
1196 extern template istream& operator>>(istream&, signed char&);
1197 extern template istream& operator>>(istream&, unsigned char*);
1198 extern template istream& operator>>(istream&, signed char*);
1200 #ifdef _GLIBCXX_USE_WCHAR_T
1201 extern template class basic_istream<wchar_t>;
1202 extern template wistream& ws(wistream&);
1203 extern template wistream& operator>>(wistream&, wchar_t&);
1204 extern template wistream& operator>>(wistream&, wchar_t*);