1 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
29 // ISO C++ 14882: 27.6.2 Output streams
32 #include <bits/std_locale.h>
36 template<typename _CharT, typename _Traits>
37 basic_istream<_CharT, _Traits>::sentry::
38 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
44 if (!__noskipws && (__in.flags() & ios_base::skipws))
46 const __int_type __eof = traits_type::eof();
47 __int_type __c = __int_type(0);
48 __streambuf_type* __sb = __in.rdbuf();
49 const __ctype_type* __ctype = __in._M_get_fctype_ios();
51 bool __testeof = false;
53 while (!__testeof && __testsp)
56 __testeof = __c == __eof;
57 __testsp = __ctype->is(ctype_base::space, __c);
60 if (!__testeof && !__testsp)
62 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
63 //195. Should basic_istream::sentry's constructor ever set eofbit?
65 __in.setstate(ios_base::eofbit);
75 __in.setstate(ios_base::failbit);
79 template<typename _CharT, typename _Traits>
80 basic_istream<_CharT, _Traits>&
81 basic_istream<_CharT, _Traits>::
82 operator>>(__istream_type& (*__pf)(__istream_type&))
84 sentry __cerb(*this, false);
90 catch(exception& __fail){
91 // 27.6.1.2.1 Common requirements.
92 // Turn this on without causing an ios::failure to be thrown.
93 this->setstate(ios_base::badbit);
94 if ((this->exceptions() & ios_base::badbit) != 0)
95 __throw_exception_again;
101 template<typename _CharT, typename _Traits>
102 basic_istream<_CharT, _Traits>&
103 basic_istream<_CharT, _Traits>::
104 operator>>(__ios_type& (*__pf)(__ios_type&))
106 sentry __cerb(*this, false);
112 catch(exception& __fail){
113 // 27.6.1.2.1 Common requirements.
114 // Turn this on without causing an ios::failure to be thrown.
115 this->setstate(ios_base::badbit);
116 if ((this->exceptions() & ios_base::badbit) != 0)
117 __throw_exception_again;
123 template<typename _CharT, typename _Traits>
124 basic_istream<_CharT, _Traits>&
125 basic_istream<_CharT, _Traits>::
126 operator>>(ios_base& (*__pf)(ios_base&))
128 sentry __cerb(*this, false);
134 catch(exception& __fail){
135 // 27.6.1.2.1 Common requirements.
136 // Turn this on without causing an ios::failure to be thrown.
137 this->setstate(ios_base::badbit);
138 if ((this->exceptions() & ios_base::badbit) != 0)
139 __throw_exception_again;
145 template<typename _CharT, typename _Traits>
146 basic_istream<_CharT, _Traits>&
147 basic_istream<_CharT, _Traits>::
148 operator>>(bool& __n)
150 sentry __cerb(*this, false);
154 iostate __err = iostate(ios_base::goodbit);
155 _M_fnumget->get(*this, 0, *this, __err, __n);
156 this->setstate(__err);
158 catch(exception& __fail){
159 // 27.6.1.2.1 Common requirements.
160 // Turn this on without causing an ios::failure to be thrown.
161 this->setstate(ios_base::badbit);
162 if ((this->exceptions() & ios_base::badbit) != 0)
163 __throw_exception_again;
169 template<typename _CharT, typename _Traits>
170 basic_istream<_CharT, _Traits>&
171 basic_istream<_CharT, _Traits>::
172 operator>>(short& __n)
174 sentry __cerb(*this, false);
178 iostate __err = iostate(ios_base::goodbit);
179 _M_fnumget->get(*this, 0, *this, __err, __n);
180 this->setstate(__err);
182 catch(exception& __fail){
183 // 27.6.1.2.1 Common requirements.
184 // Turn this on without causing an ios::failure to be thrown.
185 this->setstate(ios_base::badbit);
186 if ((this->exceptions() & ios_base::badbit) != 0)
187 __throw_exception_again;
193 template<typename _CharT, typename _Traits>
194 basic_istream<_CharT, _Traits>&
195 basic_istream<_CharT, _Traits>::
196 operator>>(unsigned short& __n)
198 sentry __cerb(*this, false);
202 iostate __err = iostate(ios_base::goodbit);
203 _M_fnumget->get(*this, 0, *this, __err, __n);
204 this->setstate(__err);
206 catch(exception& __fail){
207 // 27.6.1.2.1 Common requirements.
208 // Turn this on without causing an ios::failure to be thrown.
209 this->setstate(ios_base::badbit);
210 if ((this->exceptions() & ios_base::badbit) != 0)
211 __throw_exception_again;
217 template<typename _CharT, typename _Traits>
218 basic_istream<_CharT, _Traits>&
219 basic_istream<_CharT, _Traits>::
222 sentry __cerb(*this, false);
226 iostate __err = iostate(ios_base::goodbit);
227 _M_fnumget->get(*this, 0, *this, __err, __n);
228 this->setstate(__err);
230 catch(exception& __fail){
231 // 27.6.1.2.1 Common requirements.
232 // Turn this on without causing an ios::failure to be thrown.
233 this->setstate(ios_base::badbit);
234 if ((this->exceptions() & ios_base::badbit) != 0)
235 __throw_exception_again;
241 template<typename _CharT, typename _Traits>
242 basic_istream<_CharT, _Traits>&
243 basic_istream<_CharT, _Traits>::
244 operator>>(unsigned int& __n)
246 sentry __cerb(*this, false);
250 iostate __err = iostate(ios_base::goodbit);
251 _M_fnumget->get(*this, 0, *this, __err, __n);
252 this->setstate(__err);
254 catch(exception& __fail){
255 // 27.6.1.2.1 Common requirements.
256 // Turn this on without causing an ios::failure to be thrown.
257 this->setstate(ios_base::badbit);
258 if ((this->exceptions() & ios_base::badbit) != 0)
259 __throw_exception_again;
265 template<typename _CharT, typename _Traits>
266 basic_istream<_CharT, _Traits>&
267 basic_istream<_CharT, _Traits>::
268 operator>>(long& __n)
270 sentry __cerb(*this, false);
274 iostate __err = iostate(ios_base::goodbit);
275 _M_fnumget->get(*this, 0, *this, __err, __n);
276 this->setstate(__err);
278 catch(exception& __fail){
279 // 27.6.1.2.1 Common requirements.
280 // Turn this on without causing an ios::failure to be thrown.
281 this->setstate(ios_base::badbit);
282 if ((this->exceptions() & ios_base::badbit) != 0)
283 __throw_exception_again;
289 template<typename _CharT, typename _Traits>
290 basic_istream<_CharT, _Traits>&
291 basic_istream<_CharT, _Traits>::
292 operator>>(unsigned long& __n)
294 sentry __cerb(*this, false);
298 iostate __err = iostate(ios_base::goodbit);
299 _M_fnumget->get(*this, 0, *this, __err, __n);
300 this->setstate(__err);
302 catch(exception& __fail){
303 // 27.6.1.2.1 Common requirements.
304 // Turn this on without causing an ios::failure to be thrown.
305 this->setstate(ios_base::badbit);
306 if ((this->exceptions() & ios_base::badbit) != 0)
307 __throw_exception_again;
313 #ifdef _GLIBCPP_USE_LONG_LONG
314 template<typename _CharT, typename _Traits>
315 basic_istream<_CharT, _Traits>&
316 basic_istream<_CharT, _Traits>::
317 operator>>(long long& __n)
319 sentry __cerb(*this, false);
323 iostate __err = iostate(ios_base::goodbit);
324 _M_fnumget->get(*this, 0, *this, __err, __n);
325 this->setstate(__err);
327 catch(exception& __fail){
328 // 27.6.1.2.1 Common requirements.
329 // Turn this on without causing an ios::failure to be thrown.
330 this->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);
347 iostate __err = iostate(ios_base::goodbit);
348 _M_fnumget->get(*this, 0, *this, __err, __n);
349 this->setstate(__err);
351 catch(exception& __fail){
352 // 27.6.1.2.1 Common requirements.
353 // Turn this on without causing an ios::failure to be thrown.
354 this->setstate(ios_base::badbit);
355 if ((this->exceptions() & ios_base::badbit) != 0)
356 __throw_exception_again;
363 template<typename _CharT, typename _Traits>
364 basic_istream<_CharT, _Traits>&
365 basic_istream<_CharT, _Traits>::
366 operator>>(float& __n)
368 sentry __cerb(*this, false);
372 iostate __err = iostate(ios_base::goodbit);
373 _M_fnumget->get(*this, 0, *this, __err, __n);
374 this->setstate(__err);
376 catch(exception& __fail){
377 // 27.6.1.2.1 Common requirements.
378 // Turn this on without causing an ios::failure to be thrown.
379 this->setstate(ios_base::badbit);
380 if ((this->exceptions() & ios_base::badbit) != 0)
381 __throw_exception_again;
387 template<typename _CharT, typename _Traits>
388 basic_istream<_CharT, _Traits>&
389 basic_istream<_CharT, _Traits>::
390 operator>>(double& __n)
392 sentry __cerb(*this, false);
396 iostate __err = iostate(ios_base::goodbit);
397 _M_fnumget->get(*this, 0, *this, __err, __n);
398 this->setstate(__err);
400 catch(exception& __fail){
401 // 27.6.1.2.1 Common requirements.
402 // Turn this on without causing an ios::failure to be thrown.
403 this->setstate(ios_base::badbit);
404 if ((this->exceptions() & ios_base::badbit) != 0)
405 __throw_exception_again;
411 template<typename _CharT, typename _Traits>
412 basic_istream<_CharT, _Traits>&
413 basic_istream<_CharT, _Traits>::
414 operator>>(long double& __n)
416 sentry __cerb(*this, false);
420 iostate __err = iostate(ios_base::goodbit);
421 _M_fnumget->get(*this, 0, *this, __err, __n);
422 this->setstate(__err);
424 catch(exception& __fail){
425 // 27.6.1.2.1 Common requirements.
426 // Turn this on without causing an ios::failure to be thrown.
427 this->setstate(ios_base::badbit);
428 if ((this->exceptions() & ios_base::badbit) != 0)
429 __throw_exception_again;
435 template<typename _CharT, typename _Traits>
436 basic_istream<_CharT, _Traits>&
437 basic_istream<_CharT, _Traits>::
438 operator>>(void*& __n)
440 sentry __cerb(*this, false);
444 iostate __err = iostate(ios_base::goodbit);
445 _M_fnumget->get(*this, 0, *this, __err, __n);
446 this->setstate(__err);
448 catch(exception& __fail){
449 // 27.6.1.2.1 Common requirements.
450 // Turn this on without causing an ios::failure to be thrown.
451 this->setstate(ios_base::badbit);
452 if ((this->exceptions() & ios_base::badbit) != 0)
453 __throw_exception_again;
459 template<typename _CharT, typename _Traits>
460 basic_istream<_CharT, _Traits>&
461 basic_istream<_CharT, _Traits>::
462 operator>>(__streambuf_type* __sbout)
464 streamsize __xtrct = 0;
465 __streambuf_type* __sbin = this->rdbuf();
466 sentry __cerb(*this, false);
467 if (__sbout && __cerb)
468 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
469 if (!__sbout || !__xtrct)
470 this->setstate(ios_base::failbit);
474 template<typename _CharT, typename _Traits>
475 basic_istream<_CharT, _Traits>::int_type
476 basic_istream<_CharT, _Traits>::
479 const int_type __eof = traits_type::eof();
480 int_type __c = __eof;
482 sentry __cerb(*this, true);
486 __c = this->rdbuf()->sbumpc();
487 // 27.6.1.1 paragraph 3
491 this->setstate(ios_base::eofbit | ios_base::failbit);
493 catch(exception& __fail){
494 // 27.6.1.3 paragraph 1
495 // Turn this on without causing an ios::failure to be thrown.
496 this->setstate(ios_base::badbit);
497 if ((this->exceptions() & ios_base::badbit) != 0)
498 __throw_exception_again;
504 template<typename _CharT, typename _Traits>
505 basic_istream<_CharT, _Traits>&
506 basic_istream<_CharT, _Traits>::
510 sentry __cerb(*this, true);
514 const int_type __eof = traits_type::eof();
515 int_type __bufval = this->rdbuf()->sbumpc();
516 // 27.6.1.1 paragraph 3
517 if (__bufval != __eof)
520 __c = traits_type::to_char_type(__bufval);
523 this->setstate(ios_base::eofbit | ios_base::failbit);
525 catch(exception& __fail){
526 // 27.6.1.3 paragraph 1
527 // Turn this on without causing an ios::failure to be thrown.
528 this->setstate(ios_base::badbit);
529 if ((this->exceptions() & ios_base::badbit) != 0)
530 __throw_exception_again;
536 template<typename _CharT, typename _Traits>
537 basic_istream<_CharT, _Traits>&
538 basic_istream<_CharT, _Traits>::
539 get(char_type* __s, streamsize __n, char_type __delim)
542 sentry __cerb(*this, true);
543 if (__cerb && __n > 1)
546 const int_type __idelim = traits_type::to_int_type(__delim);
547 const int_type __eof = traits_type::eof();
548 __streambuf_type* __sb = this->rdbuf();
549 int_type __c = __sb->sbumpc();
550 bool __testdelim = __c == __idelim;
551 bool __testeof = __c == __eof;
553 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
555 *__s++ = traits_type::to_char_type(__c);
557 __c = __sb->sbumpc();
558 __testeof = __c == __eof;
559 __testdelim = __c == __idelim;
561 if (__testdelim || _M_gcount == __n - 1)
562 __sb->sputbackc(__c);
564 this->setstate(ios_base::eofbit);
566 catch(exception& __fail){
567 // 27.6.1.3 paragraph 1
568 // Turn this on without causing an ios::failure to be thrown.
569 this->setstate(ios_base::badbit);
570 if ((this->exceptions() & ios_base::badbit) != 0)
571 __throw_exception_again;
574 *__s = char_type(NULL);
576 this->setstate(ios_base::failbit);
580 template<typename _CharT, typename _Traits>
581 basic_istream<_CharT, _Traits>&
582 basic_istream<_CharT, _Traits>::
583 get(__streambuf_type& __sb, char_type __delim)
586 sentry __cerb(*this, true);
590 __streambuf_type* __this_sb = this->rdbuf();
592 const int_type __idelim = traits_type::to_int_type(__delim);
593 const int_type __eof = traits_type::eof();
594 __c = __this_sb->sbumpc();
595 bool __testdelim = __c == __idelim;
596 bool __testeof = __c == __eof;
597 bool __testput = true;
599 while (!__testeof && !__testdelim
600 && (__testput = __sb.sputc(traits_type::to_char_type(__c))
604 __c = __this_sb->sbumpc();
605 __testeof = __c == __eof;
606 __testdelim = __c == __idelim;
608 if (__testdelim || !__testput)
609 __this_sb->sputbackc(traits_type::to_char_type(__c));
611 this->setstate(ios_base::eofbit);
613 catch(exception& __fail){
614 // Exception may result from sputc->overflow.
615 __this_sb->sputbackc(traits_type::to_char_type(__c));
619 this->setstate(ios_base::failbit);
623 template<typename _CharT, typename _Traits>
624 basic_istream<_CharT, _Traits>&
625 basic_istream<_CharT, _Traits>::
626 getline(char_type* __s, streamsize __n, char_type __delim)
629 sentry __cerb(*this, true);
633 __streambuf_type* __sb = this->rdbuf();
634 int_type __c = __sb->sbumpc();
636 const int_type __idelim = traits_type::to_int_type(__delim);
637 const int_type __eof = traits_type::eof();
638 bool __testdelim = __c == __idelim;
639 bool __testeof = __c == __eof;
641 while (_M_gcount < __n && !__testeof && !__testdelim)
643 *__s++ = traits_type::to_char_type(__c);
644 __c = __sb->sbumpc();
646 __testeof = __c == __eof;
647 __testdelim = __c == __idelim;
653 this->setstate(ios_base::eofbit);
655 else if (!__testdelim)
658 __sb->sputbackc(traits_type::to_char_type(__c));
659 this->setstate(ios_base::failbit);
662 catch(exception& __fail){
663 // 27.6.1.3 paragraph 1
664 // Turn this on without causing an ios::failure to be thrown.
665 this->setstate(ios_base::badbit);
666 if ((this->exceptions() & ios_base::badbit) != 0)
667 __throw_exception_again;
670 *__s = char_type(NULL);
672 this->setstate(ios_base::failbit);
676 template<typename _CharT, typename _Traits>
677 basic_istream<_CharT, _Traits>&
678 basic_istream<_CharT, _Traits>::
679 ignore(streamsize __n, int_type __delim)
682 sentry __cerb(*this, true);
683 if (__cerb && __n > 0)
686 const int_type __idelim = traits_type::to_int_type(__delim);
687 const int_type __eof = traits_type::eof();
688 __streambuf_type* __sb = this->rdbuf();
689 int_type __c = __sb->sbumpc();
690 bool __testdelim = __c == __idelim;
691 bool __testeof = __c == __eof;
693 __n = min(__n, numeric_limits<streamsize>::max());
694 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
697 __c = __sb->sbumpc();
698 __testeof = __c == __eof;
699 __testdelim = __c == __idelim;
701 if ((_M_gcount == __n - 1 && !__testeof) || __testdelim)
704 this->setstate(ios_base::eofbit);
706 catch(exception& __fail){
707 // 27.6.1.3 paragraph 1
708 // Turn this on without causing an ios::failure to be thrown.
709 this->setstate(ios_base::badbit);
710 if ((this->exceptions() & ios_base::badbit) != 0)
711 __throw_exception_again;
717 template<typename _CharT, typename _Traits>
718 basic_istream<_CharT, _Traits>::int_type
719 basic_istream<_CharT, _Traits>::
722 int_type __c = traits_type::eof();
724 sentry __cerb(*this, true);
728 __c = this->rdbuf()->sgetc();
730 catch(exception& __fail){
731 // 27.6.1.3 paragraph 1
732 // Turn this on without causing an ios::failure to be thrown.
733 this->setstate(ios_base::badbit);
734 if ((this->exceptions() & ios_base::badbit) != 0)
735 __throw_exception_again;
741 template<typename _CharT, typename _Traits>
742 basic_istream<_CharT, _Traits>&
743 basic_istream<_CharT, _Traits>::
744 read(char_type* __s, streamsize __n)
747 sentry __cerb(*this, true);
753 const int_type __eof = traits_type::eof();
754 __streambuf_type* __sb = this->rdbuf();
755 int_type __c = __sb->sbumpc();
756 bool __testeof = __c == __eof;
758 while (_M_gcount < __n - 1 && !__testeof)
760 *__s++ = traits_type::to_char_type(__c);
762 __c = __sb->sbumpc();
763 __testeof = __c == __eof;
766 this->setstate(ios_base::eofbit | ios_base::failbit);
769 // _M_gcount == __n - 1
770 *__s++ = traits_type::to_char_type(__c);
774 catch(exception& __fail){
775 // 27.6.1.3 paragraph 1
776 // Turn this on without causing an ios::failure to be thrown.
777 this->setstate(ios_base::badbit);
778 if ((this->exceptions() & ios_base::badbit) != 0)
779 __throw_exception_again;
784 this->setstate(ios_base::failbit);
788 template<typename _CharT, typename _Traits>
790 basic_istream<_CharT, _Traits>::
791 readsome(char_type* __s, streamsize __n)
793 const int_type __eof = traits_type::eof();
795 sentry __cerb(*this, true);
801 streamsize __num = this->rdbuf()->in_avail();
802 if (__num != static_cast<streamsize>(__eof))
804 __num = min(__num, __n);
805 _M_gcount = this->rdbuf()->sgetn(__s, __num);
808 this->setstate(ios_base::eofbit);
811 catch(exception& __fail){
812 // 27.6.1.3 paragraph 1
813 // Turn this on without causing an ios::failure to be thrown.
814 this->setstate(ios_base::badbit);
815 if ((this->exceptions() & ios_base::badbit) != 0)
816 __throw_exception_again;
821 this->setstate(ios_base::failbit);
825 template<typename _CharT, typename _Traits>
826 basic_istream<_CharT, _Traits>&
827 basic_istream<_CharT, _Traits>::
828 putback(char_type __c)
830 sentry __cerb(*this, true);
834 const int_type __eof = traits_type::eof();
835 __streambuf_type* __sb = this->rdbuf();
836 if (!__sb || __sb->sputbackc(__c) == __eof)
837 this->setstate(ios_base::badbit);
839 catch(exception& __fail){
840 // 27.6.1.3 paragraph 1
841 // Turn this on without causing an ios::failure to be thrown.
842 this->setstate(ios_base::badbit);
843 if ((this->exceptions() & ios_base::badbit) != 0)
844 __throw_exception_again;
848 this->setstate(ios_base::failbit);
852 template<typename _CharT, typename _Traits>
853 basic_istream<_CharT, _Traits>&
854 basic_istream<_CharT, _Traits>::
858 sentry __cerb(*this, true);
862 const int_type __eof = traits_type::eof();
863 __streambuf_type* __sb = this->rdbuf();
864 if (!__sb || __eof == __sb->sungetc())
865 this->setstate(ios_base::badbit);
867 catch(exception& __fail){
868 // 27.6.1.3 paragraph 1
869 // Turn this on without causing an ios::failure to be thrown.
870 this->setstate(ios_base::badbit);
871 if ((this->exceptions() & ios_base::badbit) != 0)
872 __throw_exception_again;
876 this->setstate(ios_base::failbit);
880 template<typename _CharT, typename _Traits>
882 basic_istream<_CharT, _Traits>::
885 int __ret = traits_type::eof();
887 sentry __cerb(*this, true);
891 __streambuf_type* __sb = this->rdbuf();
892 if (!__sb || __ret == __sb->pubsync())
893 this->setstate(ios_base::badbit);
897 catch(exception& __fail){
898 // 27.6.1.3 paragraph 1
899 // Turn this on without causing an ios::failure to be thrown.
900 this->setstate(ios_base::badbit);
901 if ((this->exceptions() & ios_base::badbit) != 0)
902 __throw_exception_again;
908 template<typename _CharT, typename _Traits>
909 typename basic_istream<_CharT, _Traits>::pos_type
910 basic_istream<_CharT, _Traits>::
913 pos_type __ret = pos_type(-1);
915 sentry __cerb(*this, true);
919 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
921 catch(exception& __fail){
922 // 27.6.1.3 paragraph 1
923 // Turn this on without causing an ios::failure to be thrown.
924 this->setstate(ios_base::badbit);
925 if ((this->exceptions() & ios_base::badbit) != 0)
926 __throw_exception_again;
933 template<typename _CharT, typename _Traits>
934 basic_istream<_CharT, _Traits>&
935 basic_istream<_CharT, _Traits>::
936 seekg(pos_type __pos)
939 sentry __cerb(*this, true);
943 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
944 // 136. seekp, seekg setting wrong streams?
945 this->rdbuf()->pubseekpos(__pos, ios_base::in);
948 catch(exception& __fail){
949 // 27.6.1.3 paragraph 1
950 // Turn this on without causing an ios::failure to be thrown.
951 this->setstate(ios_base::badbit);
952 if ((this->exceptions() & ios_base::badbit) != 0)
953 __throw_exception_again;
959 template<typename _CharT, typename _Traits>
960 basic_istream<_CharT, _Traits>&
961 basic_istream<_CharT, _Traits>::
962 seekg(off_type __off, ios_base::seekdir __dir)
965 sentry __cerb(*this, true);
969 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
970 // 136. seekp, seekg setting wrong streams?
971 this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
974 catch(exception& __fail){
975 // 27.6.1.3 paragraph 1
976 // Turn this on without causing an ios::failure to be thrown.
977 this->setstate(ios_base::badbit);
978 if ((this->exceptions() & ios_base::badbit) != 0)
979 __throw_exception_again;
985 // 27.6.1.2.3 Character extraction templates
986 template<typename _CharT, typename _Traits>
987 basic_istream<_CharT, _Traits>&
988 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
990 typedef basic_istream<_CharT, _Traits> __istream_type;
991 __istream_type::sentry __cerb(__in, false);
997 catch(exception& __fail){
998 // 27.6.1.2.1 Common requirements.
999 // Turn this on without causing an ios::failure to be thrown.
1000 __in.setstate(ios_base::badbit);
1001 if ((__in.exceptions() & ios_base::badbit) != 0)
1002 __throw_exception_again;
1006 __in.setstate(ios_base::failbit);
1010 template<typename _CharT, typename _Traits>
1011 basic_istream<_CharT, _Traits>&
1012 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1014 typedef basic_istream<_CharT, _Traits> __istream_type;
1015 typedef typename __istream_type::__streambuf_type __streambuf_type;
1016 typedef typename _Traits::int_type int_type;
1017 typedef _CharT char_type;
1018 typedef ctype<_CharT> __ctype_type;
1019 int_type __extracted = 0;
1021 __istream_type::sentry __cerb(__in, false);
1025 // Figure out how many characters to extract.
1026 int_type __num = static_cast<int_type>(__in.width());
1028 __num = basic_string<_CharT, _Traits>::npos;
1030 __streambuf_type* __sb = __in.rdbuf();
1031 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1032 int_type __c = __sb->sbumpc();
1033 const int_type __eof = _Traits::eof();
1034 bool __testsp = __ctype->is(ctype_base::space, __c);
1035 bool __testeof = __c == __eof;
1037 while (__extracted < __num - 1 && !__testeof && !__testsp)
1041 __c = __sb->sbumpc();
1042 __testeof = __c == __eof;
1043 __testsp = __ctype->is(ctype_base::space, __c);
1047 __sb->sputbackc(__c);
1049 __in.setstate(ios_base::eofbit);
1051 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1052 //68. Extractors for char* should store null at end
1057 catch(exception& __fail){
1058 // 27.6.1.2.1 Common requirements.
1059 // Turn this on without causing an ios::failure to be thrown.
1060 __in.setstate(ios_base::badbit);
1061 if ((__in.exceptions() & ios_base::badbit) != 0)
1062 __throw_exception_again;
1066 __in.setstate(ios_base::failbit);
1070 // 27.6.1.4 Standard basic_istream manipulators
1071 template<typename _CharT, typename _Traits>
1072 basic_istream<_CharT,_Traits>&
1073 ws(basic_istream<_CharT,_Traits>& __in)
1075 typedef basic_istream<_CharT, _Traits> __istream_type;
1076 typedef typename __istream_type::__streambuf_type __streambuf_type;
1077 typedef typename __istream_type::__ctype_type __ctype_type;
1078 typedef typename __istream_type::int_type __int_type;
1079 typedef typename __istream_type::char_type __char_type;
1081 __streambuf_type* __sb = __in.rdbuf();
1082 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1083 const __int_type __eof = _Traits::eof();
1090 __c = __sb->sbumpc();
1091 __testeof = __c == __eof;
1092 __testsp = __ctype->is(ctype_base::space, __c);
1094 while (!__testeof && __testsp);
1096 if (!__testeof && !__testsp)
1097 __sb->sputbackc(__c);
1099 __in.setstate(ios_base::eofbit);
1104 // 21.3.7.9 basic_string::getline and operators
1105 template<typename _CharT, typename _Traits, typename _Alloc>
1106 basic_istream<_CharT, _Traits>&
1107 operator>>(basic_istream<_CharT, _Traits>& __in,
1108 basic_string<_CharT, _Traits, _Alloc>& __str)
1110 typedef basic_istream<_CharT, _Traits> __istream_type;
1111 typedef typename __istream_type::int_type __int_type;
1112 typedef typename __istream_type::__streambuf_type __streambuf_type;
1113 typedef typename __istream_type::__ctype_type __ctype_type;
1114 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1115 typedef typename __string_type::size_type __size_type;
1116 __int_type __extracted = 0;
1118 __istream_type::sentry __cerb(__in, false);
1122 streamsize __w = __in.width();
1124 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1126 __streambuf_type* __sb = __in.rdbuf();
1127 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1128 __int_type __c = __sb->sbumpc();
1129 const __int_type __eof = _Traits::eof();
1130 bool __testsp = __ctype->is(ctype_base::space, __c);
1131 bool __testeof = __c == __eof;
1133 while (__extracted < __n && !__testeof && !__testsp)
1135 __str += _Traits::to_char_type(__c);
1137 __c = __sb->sbumpc();
1138 __testeof = __c == __eof;
1139 __testsp = __ctype->is(ctype_base::space, __c);
1142 __sb->sputbackc(__c);
1144 __in.setstate(ios_base::eofbit);
1147 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1148 // 2000-02-01 Number to be determined
1150 __in.setstate (ios_base::failbit);
1155 template<typename _CharT, typename _Traits, typename _Alloc>
1156 basic_istream<_CharT, _Traits>&
1157 getline(basic_istream<_CharT, _Traits>& __in,
1158 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1160 typedef basic_istream<_CharT, _Traits> __istream_type;
1161 typedef typename __istream_type::int_type __int_type;
1162 typedef typename __istream_type::__streambuf_type __streambuf_type;
1163 typedef typename __istream_type::__ctype_type __ctype_type;
1164 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1165 typedef typename __string_type::size_type __size_type;
1167 __size_type __extracted = 0;
1168 bool __testdelim = false;
1169 __istream_type::sentry __cerb(__in, true);
1173 __size_type __n = __str.max_size();
1175 __int_type __idelim = _Traits::to_int_type(__delim);
1176 __streambuf_type* __sb = __in.rdbuf();
1177 __int_type __c = __sb->sbumpc();
1178 const __int_type __eof = _Traits::eof();
1179 __testdelim = __c == __idelim;
1180 bool __testeof = __c == __eof;
1182 while (__extracted <= __n && !__testeof && !__testdelim)
1184 __str += _Traits::to_char_type(__c);
1186 __c = __sb->sbumpc();
1187 __testeof = __c == __eof;
1188 __testdelim = __c == __idelim;
1191 __in.setstate(ios_base::eofbit);
1193 if (!__extracted && !__testdelim)
1194 __in.setstate(ios_base::failbit);
1198 template<class _CharT, class _Traits, class _Alloc>
1199 inline basic_istream<_CharT,_Traits>&
1200 getline(basic_istream<_CharT, _Traits>& __in,
1201 basic_string<_CharT,_Traits,_Alloc>& __str)
1202 { return getline(__in, __str, __in.widen('\n')); }