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>
33 #include <bits/std_ostream.h> // for flush()
37 template<typename _CharT, typename _Traits>
38 basic_istream<_CharT, _Traits>::sentry::
39 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
45 if (!__noskipws && (__in.flags() & ios_base::skipws))
47 const __int_type __eof = traits_type::eof();
48 const __ctype_type* __ctype = __in._M_get_fctype_ios();
49 __streambuf_type* __sb = __in.rdbuf();
50 __int_type __c = __sb->sgetc();
52 while (__c != __eof && __ctype->is(ctype_base::space, __c))
55 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
56 //195. Should basic_istream::sentry's constructor ever set eofbit?
58 __in.setstate(ios_base::eofbit);
68 __in.setstate(ios_base::failbit);
72 template<typename _CharT, typename _Traits>
73 basic_istream<_CharT, _Traits>&
74 basic_istream<_CharT, _Traits>::
75 operator>>(__istream_type& (*__pf)(__istream_type&))
81 template<typename _CharT, typename _Traits>
82 basic_istream<_CharT, _Traits>&
83 basic_istream<_CharT, _Traits>::
84 operator>>(__ios_type& (*__pf)(__ios_type&))
90 template<typename _CharT, typename _Traits>
91 basic_istream<_CharT, _Traits>&
92 basic_istream<_CharT, _Traits>::
93 operator>>(ios_base& (*__pf)(ios_base&))
99 template<typename _CharT, typename _Traits>
100 basic_istream<_CharT, _Traits>&
101 basic_istream<_CharT, _Traits>::
102 operator>>(bool& __n)
104 sentry __cerb(*this, false);
109 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
110 if (_M_check_facet(_M_fnumget))
111 _M_fnumget->get(*this, 0, *this, __err, __n);
112 this->setstate(__err);
114 catch(exception& __fail)
116 // 27.6.1.2.1 Common requirements.
117 // Turn this on without causing an ios::failure to be thrown.
118 this->setstate(ios_base::badbit);
119 if ((this->exceptions() & ios_base::badbit) != 0)
120 __throw_exception_again;
126 template<typename _CharT, typename _Traits>
127 basic_istream<_CharT, _Traits>&
128 basic_istream<_CharT, _Traits>::
129 operator>>(short& __n)
131 sentry __cerb(*this, false);
136 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
137 if (_M_check_facet(_M_fnumget))
138 _M_fnumget->get(*this, 0, *this, __err, __n);
139 this->setstate(__err);
141 catch(exception& __fail)
143 // 27.6.1.2.1 Common requirements.
144 // Turn this on without causing an ios::failure to be thrown.
145 this->setstate(ios_base::badbit);
146 if ((this->exceptions() & ios_base::badbit) != 0)
147 __throw_exception_again;
153 template<typename _CharT, typename _Traits>
154 basic_istream<_CharT, _Traits>&
155 basic_istream<_CharT, _Traits>::
156 operator>>(unsigned short& __n)
158 sentry __cerb(*this, false);
163 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
164 if (_M_check_facet(_M_fnumget))
165 _M_fnumget->get(*this, 0, *this, __err, __n);
166 this->setstate(__err);
168 catch(exception& __fail)
170 // 27.6.1.2.1 Common requirements.
171 // Turn this on without causing an ios::failure to be thrown.
172 this->setstate(ios_base::badbit);
173 if ((this->exceptions() & ios_base::badbit) != 0)
174 __throw_exception_again;
180 template<typename _CharT, typename _Traits>
181 basic_istream<_CharT, _Traits>&
182 basic_istream<_CharT, _Traits>::
185 sentry __cerb(*this, false);
190 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
191 if (_M_check_facet(_M_fnumget))
192 _M_fnumget->get(*this, 0, *this, __err, __n);
193 this->setstate(__err);
195 catch(exception& __fail)
197 // 27.6.1.2.1 Common requirements.
198 // Turn this on without causing an ios::failure to be thrown.
199 this->setstate(ios_base::badbit);
200 if ((this->exceptions() & ios_base::badbit) != 0)
201 __throw_exception_again;
207 template<typename _CharT, typename _Traits>
208 basic_istream<_CharT, _Traits>&
209 basic_istream<_CharT, _Traits>::
210 operator>>(unsigned int& __n)
212 sentry __cerb(*this, false);
217 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
218 if (_M_check_facet(_M_fnumget))
219 _M_fnumget->get(*this, 0, *this, __err, __n);
220 this->setstate(__err);
222 catch(exception& __fail)
224 // 27.6.1.2.1 Common requirements.
225 // Turn this on without causing an ios::failure to be thrown.
226 this->setstate(ios_base::badbit);
227 if ((this->exceptions() & ios_base::badbit) != 0)
228 __throw_exception_again;
234 template<typename _CharT, typename _Traits>
235 basic_istream<_CharT, _Traits>&
236 basic_istream<_CharT, _Traits>::
237 operator>>(long& __n)
239 sentry __cerb(*this, false);
244 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
245 if (_M_check_facet(_M_fnumget))
246 _M_fnumget->get(*this, 0, *this, __err, __n);
247 this->setstate(__err);
249 catch(exception& __fail)
251 // 27.6.1.2.1 Common requirements.
252 // Turn this on without causing an ios::failure to be thrown.
253 this->setstate(ios_base::badbit);
254 if ((this->exceptions() & ios_base::badbit) != 0)
255 __throw_exception_again;
261 template<typename _CharT, typename _Traits>
262 basic_istream<_CharT, _Traits>&
263 basic_istream<_CharT, _Traits>::
264 operator>>(unsigned long& __n)
266 sentry __cerb(*this, false);
271 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
272 if (_M_check_facet(_M_fnumget))
273 _M_fnumget->get(*this, 0, *this, __err, __n);
274 this->setstate(__err);
276 catch(exception& __fail)
278 // 27.6.1.2.1 Common requirements.
279 // Turn this on without causing an ios::failure to be thrown.
280 this->setstate(ios_base::badbit);
281 if ((this->exceptions() & ios_base::badbit) != 0)
282 __throw_exception_again;
288 #ifdef _GLIBCPP_USE_LONG_LONG
289 template<typename _CharT, typename _Traits>
290 basic_istream<_CharT, _Traits>&
291 basic_istream<_CharT, _Traits>::
292 operator>>(long long& __n)
294 sentry __cerb(*this, false);
299 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
300 if (_M_check_facet(_M_fnumget))
301 _M_fnumget->get(*this, 0, *this, __err, __n);
302 this->setstate(__err);
304 catch(exception& __fail)
306 // 27.6.1.2.1 Common requirements.
307 // Turn this on without causing an ios::failure to be thrown.
308 this->setstate(ios_base::badbit);
309 if ((this->exceptions() & ios_base::badbit) != 0)
310 __throw_exception_again;
316 template<typename _CharT, typename _Traits>
317 basic_istream<_CharT, _Traits>&
318 basic_istream<_CharT, _Traits>::
319 operator>>(unsigned long long& __n)
321 sentry __cerb(*this, false);
326 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
327 if (_M_check_facet(_M_fnumget))
328 _M_fnumget->get(*this, 0, *this, __err, __n);
329 this->setstate(__err);
331 catch(exception& __fail)
333 // 27.6.1.2.1 Common requirements.
334 // Turn this on without causing an ios::failure to be thrown.
335 this->setstate(ios_base::badbit);
336 if ((this->exceptions() & ios_base::badbit) != 0)
337 __throw_exception_again;
344 template<typename _CharT, typename _Traits>
345 basic_istream<_CharT, _Traits>&
346 basic_istream<_CharT, _Traits>::
347 operator>>(float& __n)
349 sentry __cerb(*this, false);
354 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
355 if (_M_check_facet(_M_fnumget))
356 _M_fnumget->get(*this, 0, *this, __err, __n);
357 this->setstate(__err);
359 catch(exception& __fail)
361 // 27.6.1.2.1 Common requirements.
362 // Turn this on without causing an ios::failure to be thrown.
363 this->setstate(ios_base::badbit);
364 if ((this->exceptions() & ios_base::badbit) != 0)
365 __throw_exception_again;
371 template<typename _CharT, typename _Traits>
372 basic_istream<_CharT, _Traits>&
373 basic_istream<_CharT, _Traits>::
374 operator>>(double& __n)
376 sentry __cerb(*this, false);
381 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
382 if (_M_check_facet(_M_fnumget))
383 _M_fnumget->get(*this, 0, *this, __err, __n);
384 this->setstate(__err);
386 catch(exception& __fail)
388 // 27.6.1.2.1 Common requirements.
389 // Turn this on without causing an ios::failure to be thrown.
390 this->setstate(ios_base::badbit);
391 if ((this->exceptions() & ios_base::badbit) != 0)
392 __throw_exception_again;
398 template<typename _CharT, typename _Traits>
399 basic_istream<_CharT, _Traits>&
400 basic_istream<_CharT, _Traits>::
401 operator>>(long double& __n)
403 sentry __cerb(*this, false);
408 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
409 if (_M_check_facet(_M_fnumget))
410 _M_fnumget->get(*this, 0, *this, __err, __n);
411 this->setstate(__err);
413 catch(exception& __fail)
415 // 27.6.1.2.1 Common requirements.
416 // Turn this on without causing an ios::failure to be thrown.
417 this->setstate(ios_base::badbit);
418 if ((this->exceptions() & ios_base::badbit) != 0)
419 __throw_exception_again;
425 template<typename _CharT, typename _Traits>
426 basic_istream<_CharT, _Traits>&
427 basic_istream<_CharT, _Traits>::
428 operator>>(void*& __n)
430 sentry __cerb(*this, false);
435 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
436 if (_M_check_facet(_M_fnumget))
437 _M_fnumget->get(*this, 0, *this, __err, __n);
438 this->setstate(__err);
440 catch(exception& __fail)
442 // 27.6.1.2.1 Common requirements.
443 // Turn this on without causing an ios::failure to be thrown.
444 this->setstate(ios_base::badbit);
445 if ((this->exceptions() & ios_base::badbit) != 0)
446 __throw_exception_again;
452 template<typename _CharT, typename _Traits>
453 basic_istream<_CharT, _Traits>&
454 basic_istream<_CharT, _Traits>::
455 operator>>(__streambuf_type* __sbout)
457 streamsize __xtrct = 0;
458 __streambuf_type* __sbin = this->rdbuf();
459 sentry __cerb(*this, false);
460 if (__sbout && __cerb)
461 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
462 if (!__sbout || !__xtrct)
463 this->setstate(ios_base::failbit);
467 template<typename _CharT, typename _Traits>
468 typename basic_istream<_CharT, _Traits>::int_type
469 basic_istream<_CharT, _Traits>::
472 const int_type __eof = traits_type::eof();
473 int_type __c = __eof;
475 sentry __cerb(*this, true);
480 __c = this->rdbuf()->sbumpc();
481 // 27.6.1.1 paragraph 3
485 this->setstate(ios_base::eofbit | ios_base::failbit);
487 catch(exception& __fail)
489 // 27.6.1.3 paragraph 1
490 // Turn this on without causing an ios::failure to be thrown.
491 this->setstate(ios_base::badbit);
492 if ((this->exceptions() & ios_base::badbit) != 0)
493 __throw_exception_again;
499 template<typename _CharT, typename _Traits>
500 basic_istream<_CharT, _Traits>&
501 basic_istream<_CharT, _Traits>::
505 sentry __cerb(*this, true);
510 const int_type __eof = traits_type::eof();
511 int_type __bufval = this->rdbuf()->sbumpc();
512 // 27.6.1.1 paragraph 3
513 if (__bufval != __eof)
516 __c = traits_type::to_char_type(__bufval);
519 this->setstate(ios_base::eofbit | ios_base::failbit);
521 catch(exception& __fail)
523 // 27.6.1.3 paragraph 1
524 // Turn this on without causing an ios::failure to be thrown.
525 this->setstate(ios_base::badbit);
526 if ((this->exceptions() & ios_base::badbit) != 0)
527 __throw_exception_again;
533 template<typename _CharT, typename _Traits>
534 basic_istream<_CharT, _Traits>&
535 basic_istream<_CharT, _Traits>::
536 get(char_type* __s, streamsize __n, char_type __delim)
539 sentry __cerb(*this, true);
540 if (__cerb && __n > 1)
544 const int_type __idelim = traits_type::to_int_type(__delim);
545 const int_type __eof = traits_type::eof();
546 __streambuf_type* __sb = this->rdbuf();
547 int_type __c = __sb->sbumpc();
548 bool __testdelim = __c == __idelim;
549 bool __testeof = __c == __eof;
551 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
553 *__s++ = traits_type::to_char_type(__c);
555 __c = __sb->sbumpc();
556 __testeof = __c == __eof;
557 __testdelim = __c == __idelim;
559 if (__testdelim || _M_gcount == __n - 1)
560 __sb->sputbackc(__c);
562 this->setstate(ios_base::eofbit);
564 catch(exception& __fail)
566 // 27.6.1.3 paragraph 1
567 // Turn this on without causing an ios::failure to be thrown.
568 this->setstate(ios_base::badbit);
569 if ((this->exceptions() & ios_base::badbit) != 0)
570 __throw_exception_again;
575 this->setstate(ios_base::failbit);
579 template<typename _CharT, typename _Traits>
580 basic_istream<_CharT, _Traits>&
581 basic_istream<_CharT, _Traits>::
582 get(__streambuf_type& __sb, char_type __delim)
585 sentry __cerb(*this, true);
589 __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)
615 // Exception may result from sputc->overflow.
616 __this_sb->sputbackc(traits_type::to_char_type(__c));
620 this->setstate(ios_base::failbit);
624 template<typename _CharT, typename _Traits>
625 basic_istream<_CharT, _Traits>&
626 basic_istream<_CharT, _Traits>::
627 getline(char_type* __s, streamsize __n, char_type __delim)
630 sentry __cerb(*this, true);
635 __streambuf_type* __sb = this->rdbuf();
636 int_type __c = __sb->sbumpc();
638 const int_type __idelim = traits_type::to_int_type(__delim);
639 const int_type __eof = traits_type::eof();
640 bool __testdelim = __c == __idelim;
641 bool __testeof = __c == __eof;
643 while (_M_gcount < __n && !__testeof && !__testdelim)
645 *__s++ = traits_type::to_char_type(__c);
646 __c = __sb->sbumpc();
648 __testeof = __c == __eof;
649 __testdelim = __c == __idelim;
655 this->setstate(ios_base::eofbit);
657 else if (!__testdelim)
660 __sb->sputbackc(traits_type::to_char_type(__c));
661 this->setstate(ios_base::failbit);
664 catch(exception& __fail)
666 // 27.6.1.3 paragraph 1
667 // Turn this on without causing an ios::failure to be thrown.
668 this->setstate(ios_base::badbit);
669 if ((this->exceptions() & ios_base::badbit) != 0)
670 __throw_exception_again;
675 this->setstate(ios_base::failbit);
679 template<typename _CharT, typename _Traits>
680 basic_istream<_CharT, _Traits>&
681 basic_istream<_CharT, _Traits>::
682 ignore(streamsize __n, int_type __delim)
685 sentry __cerb(*this, true);
686 if (__cerb && __n > 0)
690 const int_type __idelim = traits_type::to_int_type(__delim);
691 const int_type __eof = traits_type::eof();
692 __streambuf_type* __sb = this->rdbuf();
693 int_type __c = __sb->sbumpc();
694 bool __testdelim = __c == __idelim;
695 bool __testeof = __c == __eof;
697 __n = min(__n, numeric_limits<streamsize>::max());
698 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
701 __c = __sb->sbumpc();
702 __testeof = __c == __eof;
703 __testdelim = __c == __idelim;
705 if ((_M_gcount == __n - 1 && !__testeof) || __testdelim)
708 this->setstate(ios_base::eofbit);
710 catch(exception& __fail)
712 // 27.6.1.3 paragraph 1
713 // Turn this on without causing an ios::failure to be thrown.
714 this->setstate(ios_base::badbit);
715 if ((this->exceptions() & ios_base::badbit) != 0)
716 __throw_exception_again;
722 template<typename _CharT, typename _Traits>
723 typename basic_istream<_CharT, _Traits>::int_type
724 basic_istream<_CharT, _Traits>::
727 int_type __c = traits_type::eof();
729 sentry __cerb(*this, true);
733 { __c = this->rdbuf()->sgetc(); }
734 catch(exception& __fail)
736 // 27.6.1.3 paragraph 1
737 // Turn this on without causing an ios::failure to be thrown.
738 this->setstate(ios_base::badbit);
739 if ((this->exceptions() & ios_base::badbit) != 0)
740 __throw_exception_again;
746 template<typename _CharT, typename _Traits>
747 basic_istream<_CharT, _Traits>&
748 basic_istream<_CharT, _Traits>::
749 read(char_type* __s, streamsize __n)
752 sentry __cerb(*this, true);
759 const int_type __eof = traits_type::eof();
760 __streambuf_type* __sb = this->rdbuf();
761 int_type __c = __sb->sbumpc();
762 bool __testeof = __c == __eof;
764 while (_M_gcount < __n - 1 && !__testeof)
766 *__s++ = traits_type::to_char_type(__c);
768 __c = __sb->sbumpc();
769 __testeof = __c == __eof;
772 this->setstate(ios_base::eofbit | ios_base::failbit);
775 // _M_gcount == __n - 1
776 *__s++ = traits_type::to_char_type(__c);
780 catch(exception& __fail)
782 // 27.6.1.3 paragraph 1
783 // Turn this on without causing an ios::failure to be thrown.
784 this->setstate(ios_base::badbit);
785 if ((this->exceptions() & ios_base::badbit) != 0)
786 __throw_exception_again;
791 this->setstate(ios_base::failbit);
795 template<typename _CharT, typename _Traits>
797 basic_istream<_CharT, _Traits>::
798 readsome(char_type* __s, streamsize __n)
800 const int_type __eof = traits_type::eof();
802 sentry __cerb(*this, true);
809 streamsize __num = this->rdbuf()->in_avail();
810 if (__num != static_cast<streamsize>(__eof))
812 __num = min(__num, __n);
813 _M_gcount = this->rdbuf()->sgetn(__s, __num);
816 this->setstate(ios_base::eofbit);
818 catch(exception& __fail)
820 // 27.6.1.3 paragraph 1
821 // Turn this on without causing an ios::failure to be thrown.
822 this->setstate(ios_base::badbit);
823 if ((this->exceptions() & ios_base::badbit) != 0)
824 __throw_exception_again;
829 this->setstate(ios_base::failbit);
833 template<typename _CharT, typename _Traits>
834 basic_istream<_CharT, _Traits>&
835 basic_istream<_CharT, _Traits>::
836 putback(char_type __c)
838 sentry __cerb(*this, true);
843 const int_type __eof = traits_type::eof();
844 __streambuf_type* __sb = this->rdbuf();
845 if (!__sb || __sb->sputbackc(__c) == __eof)
846 this->setstate(ios_base::badbit);
848 catch(exception& __fail)
850 // 27.6.1.3 paragraph 1
851 // Turn this on without causing an ios::failure to be thrown.
852 this->setstate(ios_base::badbit);
853 if ((this->exceptions() & ios_base::badbit) != 0)
854 __throw_exception_again;
858 this->setstate(ios_base::failbit);
862 template<typename _CharT, typename _Traits>
863 basic_istream<_CharT, _Traits>&
864 basic_istream<_CharT, _Traits>::
868 sentry __cerb(*this, true);
873 const int_type __eof = traits_type::eof();
874 __streambuf_type* __sb = this->rdbuf();
875 if (!__sb || __eof == __sb->sungetc())
876 this->setstate(ios_base::badbit);
878 catch(exception& __fail)
880 // 27.6.1.3 paragraph 1
881 // Turn this on without causing an ios::failure to be thrown.
882 this->setstate(ios_base::badbit);
883 if ((this->exceptions() & ios_base::badbit) != 0)
884 __throw_exception_again;
888 this->setstate(ios_base::failbit);
892 template<typename _CharT, typename _Traits>
894 basic_istream<_CharT, _Traits>::
897 int __ret = traits_type::eof();
899 sentry __cerb(*this, true);
904 __streambuf_type* __sb = this->rdbuf();
905 if (!__sb || __ret == __sb->pubsync())
906 this->setstate(ios_base::badbit);
910 catch(exception& __fail)
912 // 27.6.1.3 paragraph 1
913 // Turn this on without causing an ios::failure to be thrown.
914 this->setstate(ios_base::badbit);
915 if ((this->exceptions() & ios_base::badbit) != 0)
916 __throw_exception_again;
922 template<typename _CharT, typename _Traits>
923 typename basic_istream<_CharT, _Traits>::pos_type
924 basic_istream<_CharT, _Traits>::
927 pos_type __ret = pos_type(-1);
929 sentry __cerb(*this, true);
934 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
936 catch(exception& __fail)
938 // 27.6.1.3 paragraph 1
939 // Turn this on without causing an ios::failure to be thrown.
940 this->setstate(ios_base::badbit);
941 if ((this->exceptions() & ios_base::badbit) != 0)
942 __throw_exception_again;
949 template<typename _CharT, typename _Traits>
950 basic_istream<_CharT, _Traits>&
951 basic_istream<_CharT, _Traits>::
952 seekg(pos_type __pos)
955 sentry __cerb(*this, true);
960 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
961 // 136. seekp, seekg setting wrong streams?
962 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
964 // 129. Need error indication from seekp() and seekg()
965 if (__err == pos_type(off_type(-1)))
966 this->setstate(failbit);
969 catch(exception& __fail)
971 // 27.6.1.3 paragraph 1
972 // Turn this on without causing an ios::failure to be thrown.
973 this->setstate(ios_base::badbit);
974 if ((this->exceptions() & ios_base::badbit) != 0)
975 __throw_exception_again;
981 template<typename _CharT, typename _Traits>
982 basic_istream<_CharT, _Traits>&
983 basic_istream<_CharT, _Traits>::
984 seekg(off_type __off, ios_base::seekdir __dir)
987 sentry __cerb(*this, true);
992 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
993 // 136. seekp, seekg setting wrong streams?
994 pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
997 // 129. Need error indication from seekp() and seekg()
998 if (__err == pos_type(off_type(-1)))
999 this->setstate(failbit);
1002 catch(exception& __fail)
1004 // 27.6.1.3 paragraph 1
1005 // Turn this on without causing an ios::failure to be thrown.
1006 this->setstate(ios_base::badbit);
1007 if ((this->exceptions() & ios_base::badbit) != 0)
1008 __throw_exception_again;
1014 // 27.6.1.2.3 Character extraction templates
1015 template<typename _CharT, typename _Traits>
1016 basic_istream<_CharT, _Traits>&
1017 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
1019 typedef basic_istream<_CharT, _Traits> __istream_type;
1020 typename __istream_type::sentry __cerb(__in, false);
1025 catch(exception& __fail)
1027 // 27.6.1.2.1 Common requirements.
1028 // Turn this on without causing an ios::failure to be thrown.
1029 __in.setstate(ios_base::badbit);
1030 if ((__in.exceptions() & ios_base::badbit) != 0)
1031 __throw_exception_again;
1035 __in.setstate(ios_base::failbit);
1039 template<typename _CharT, typename _Traits>
1040 basic_istream<_CharT, _Traits>&
1041 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1043 typedef basic_istream<_CharT, _Traits> __istream_type;
1044 typedef typename __istream_type::__streambuf_type __streambuf_type;
1045 typedef typename _Traits::int_type int_type;
1046 typedef _CharT char_type;
1047 typedef ctype<_CharT> __ctype_type;
1048 streamsize __extracted = 0;
1050 typename __istream_type::sentry __cerb(__in, false);
1055 // Figure out how many characters to extract.
1056 streamsize __num = __in.width();
1058 __num = numeric_limits<streamsize>::max();
1060 __streambuf_type* __sb = __in.rdbuf();
1061 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1062 int_type __c = __sb->sbumpc();
1063 const int_type __eof = _Traits::eof();
1064 bool __testsp = __ctype->is(ctype_base::space, __c);
1065 bool __testeof = __c == __eof;
1067 while (__extracted < __num - 1 && !__testeof && !__testsp)
1071 __c = __sb->sbumpc();
1072 __testeof = __c == __eof;
1073 __testsp = __ctype->is(ctype_base::space, __c);
1077 __sb->sputbackc(__c);
1079 __in.setstate(ios_base::eofbit);
1081 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1082 //68. Extractors for char* should store null at end
1087 catch(exception& __fail)
1089 // 27.6.1.2.1 Common requirements.
1090 // Turn this on without causing an ios::failure to be thrown.
1091 __in.setstate(ios_base::badbit);
1092 if ((__in.exceptions() & ios_base::badbit) != 0)
1093 __throw_exception_again;
1097 __in.setstate(ios_base::failbit);
1101 // 27.6.1.4 Standard basic_istream manipulators
1102 template<typename _CharT, typename _Traits>
1103 basic_istream<_CharT,_Traits>&
1104 ws(basic_istream<_CharT,_Traits>& __in)
1106 typedef basic_istream<_CharT, _Traits> __istream_type;
1107 typedef typename __istream_type::__streambuf_type __streambuf_type;
1108 typedef typename __istream_type::__ctype_type __ctype_type;
1109 typedef typename __istream_type::int_type __int_type;
1110 typedef typename __istream_type::char_type __char_type;
1112 __streambuf_type* __sb = __in.rdbuf();
1113 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1114 const __int_type __eof = _Traits::eof();
1121 __c = __sb->sbumpc();
1122 __testeof = __c == __eof;
1123 __testsp = __ctype->is(ctype_base::space, __c);
1125 while (!__testeof && __testsp);
1127 if (!__testeof && !__testsp)
1128 __sb->sputbackc(__c);
1130 __in.setstate(ios_base::eofbit);
1135 // 21.3.7.9 basic_string::getline and operators
1136 template<typename _CharT, typename _Traits, typename _Alloc>
1137 basic_istream<_CharT, _Traits>&
1138 operator>>(basic_istream<_CharT, _Traits>& __in,
1139 basic_string<_CharT, _Traits, _Alloc>& __str)
1141 typedef basic_istream<_CharT, _Traits> __istream_type;
1142 typedef typename __istream_type::int_type __int_type;
1143 typedef typename __istream_type::__streambuf_type __streambuf_type;
1144 typedef typename __istream_type::__ctype_type __ctype_type;
1145 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1146 typedef typename __string_type::size_type __size_type;
1147 __size_type __extracted = 0;
1149 typename __istream_type::sentry __cerb(__in, false);
1153 streamsize __w = __in.width();
1155 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1157 __streambuf_type* __sb = __in.rdbuf();
1158 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1159 __int_type __c = __sb->sbumpc();
1160 const __int_type __eof = _Traits::eof();
1161 bool __testsp = __ctype->is(ctype_base::space, __c);
1162 bool __testeof = __c == __eof;
1164 while (__extracted < __n && !__testeof && !__testsp)
1166 __str += _Traits::to_char_type(__c);
1168 __c = __sb->sbumpc();
1169 __testeof = __c == __eof;
1170 __testsp = __ctype->is(ctype_base::space, __c);
1173 __sb->sputbackc(__c);
1175 __in.setstate(ios_base::eofbit);
1178 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1179 //211. operator>>(istream&, string&) doesn't set failbit
1181 __in.setstate (ios_base::failbit);
1186 template<typename _CharT, typename _Traits, typename _Alloc>
1187 basic_istream<_CharT, _Traits>&
1188 getline(basic_istream<_CharT, _Traits>& __in,
1189 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1191 typedef basic_istream<_CharT, _Traits> __istream_type;
1192 typedef typename __istream_type::int_type __int_type;
1193 typedef typename __istream_type::__streambuf_type __streambuf_type;
1194 typedef typename __istream_type::__ctype_type __ctype_type;
1195 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1196 typedef typename __string_type::size_type __size_type;
1198 __size_type __extracted = 0;
1199 bool __testdelim = false;
1200 typename __istream_type::sentry __cerb(__in, true);
1204 __size_type __n = __str.max_size();
1206 __int_type __idelim = _Traits::to_int_type(__delim);
1207 __streambuf_type* __sb = __in.rdbuf();
1208 __int_type __c = __sb->sbumpc();
1209 const __int_type __eof = _Traits::eof();
1210 __testdelim = __c == __idelim;
1211 bool __testeof = __c == __eof;
1213 while (__extracted <= __n && !__testeof && !__testdelim)
1215 __str += _Traits::to_char_type(__c);
1217 __c = __sb->sbumpc();
1218 __testeof = __c == __eof;
1219 __testdelim = __c == __idelim;
1222 __in.setstate(ios_base::eofbit);
1224 if (!__extracted && !__testdelim)
1225 __in.setstate(ios_base::failbit);
1229 template<class _CharT, class _Traits, class _Alloc>
1230 inline basic_istream<_CharT,_Traits>&
1231 getline(basic_istream<_CharT, _Traits>& __in,
1232 basic_string<_CharT,_Traits,_Alloc>& __str)
1233 { return getline(__in, __str, __in.widen('\n')); }