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 const __ctype_type* __ctype = __in._M_get_fctype_ios();
48 __streambuf_type* __sb = __in.rdbuf();
49 __int_type __c = __sb->sgetc();
51 while (__c != __eof && __ctype->is(ctype_base::space, __c))
54 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
55 //195. Should basic_istream::sentry's constructor ever set eofbit?
57 __in.setstate(ios_base::eofbit);
67 __in.setstate(ios_base::failbit);
71 template<typename _CharT, typename _Traits>
72 basic_istream<_CharT, _Traits>&
73 basic_istream<_CharT, _Traits>::
74 operator>>(__istream_type& (*__pf)(__istream_type&))
80 template<typename _CharT, typename _Traits>
81 basic_istream<_CharT, _Traits>&
82 basic_istream<_CharT, _Traits>::
83 operator>>(__ios_type& (*__pf)(__ios_type&))
89 template<typename _CharT, typename _Traits>
90 basic_istream<_CharT, _Traits>&
91 basic_istream<_CharT, _Traits>::
92 operator>>(ios_base& (*__pf)(ios_base&))
98 template<typename _CharT, typename _Traits>
99 basic_istream<_CharT, _Traits>&
100 basic_istream<_CharT, _Traits>::
101 operator>>(bool& __n)
103 sentry __cerb(*this, false);
108 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
109 if (_M_check_facet(_M_fnumget))
110 _M_fnumget->get(*this, 0, *this, __err, __n);
111 this->setstate(__err);
113 catch(exception& __fail)
115 // 27.6.1.2.1 Common requirements.
116 // Turn this on without causing an ios::failure to be thrown.
117 this->setstate(ios_base::badbit);
118 if ((this->exceptions() & ios_base::badbit) != 0)
119 __throw_exception_again;
125 template<typename _CharT, typename _Traits>
126 basic_istream<_CharT, _Traits>&
127 basic_istream<_CharT, _Traits>::
128 operator>>(short& __n)
130 sentry __cerb(*this, false);
135 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
136 if (_M_check_facet(_M_fnumget))
137 _M_fnumget->get(*this, 0, *this, __err, __n);
138 this->setstate(__err);
140 catch(exception& __fail)
142 // 27.6.1.2.1 Common requirements.
143 // Turn this on without causing an ios::failure to be thrown.
144 this->setstate(ios_base::badbit);
145 if ((this->exceptions() & ios_base::badbit) != 0)
146 __throw_exception_again;
152 template<typename _CharT, typename _Traits>
153 basic_istream<_CharT, _Traits>&
154 basic_istream<_CharT, _Traits>::
155 operator>>(unsigned short& __n)
157 sentry __cerb(*this, false);
162 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
163 if (_M_check_facet(_M_fnumget))
164 _M_fnumget->get(*this, 0, *this, __err, __n);
165 this->setstate(__err);
167 catch(exception& __fail)
169 // 27.6.1.2.1 Common requirements.
170 // Turn this on without causing an ios::failure to be thrown.
171 this->setstate(ios_base::badbit);
172 if ((this->exceptions() & ios_base::badbit) != 0)
173 __throw_exception_again;
179 template<typename _CharT, typename _Traits>
180 basic_istream<_CharT, _Traits>&
181 basic_istream<_CharT, _Traits>::
184 sentry __cerb(*this, false);
189 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
190 if (_M_check_facet(_M_fnumget))
191 _M_fnumget->get(*this, 0, *this, __err, __n);
192 this->setstate(__err);
194 catch(exception& __fail)
196 // 27.6.1.2.1 Common requirements.
197 // Turn this on without causing an ios::failure to be thrown.
198 this->setstate(ios_base::badbit);
199 if ((this->exceptions() & ios_base::badbit) != 0)
200 __throw_exception_again;
206 template<typename _CharT, typename _Traits>
207 basic_istream<_CharT, _Traits>&
208 basic_istream<_CharT, _Traits>::
209 operator>>(unsigned int& __n)
211 sentry __cerb(*this, false);
216 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
217 if (_M_check_facet(_M_fnumget))
218 _M_fnumget->get(*this, 0, *this, __err, __n);
219 this->setstate(__err);
221 catch(exception& __fail)
223 // 27.6.1.2.1 Common requirements.
224 // Turn this on without causing an ios::failure to be thrown.
225 this->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>>(long& __n)
238 sentry __cerb(*this, false);
243 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
244 if (_M_check_facet(_M_fnumget))
245 _M_fnumget->get(*this, 0, *this, __err, __n);
246 this->setstate(__err);
248 catch(exception& __fail)
250 // 27.6.1.2.1 Common requirements.
251 // Turn this on without causing an ios::failure to be thrown.
252 this->setstate(ios_base::badbit);
253 if ((this->exceptions() & ios_base::badbit) != 0)
254 __throw_exception_again;
260 template<typename _CharT, typename _Traits>
261 basic_istream<_CharT, _Traits>&
262 basic_istream<_CharT, _Traits>::
263 operator>>(unsigned long& __n)
265 sentry __cerb(*this, false);
270 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
271 if (_M_check_facet(_M_fnumget))
272 _M_fnumget->get(*this, 0, *this, __err, __n);
273 this->setstate(__err);
275 catch(exception& __fail)
277 // 27.6.1.2.1 Common requirements.
278 // Turn this on without causing an ios::failure to be thrown.
279 this->setstate(ios_base::badbit);
280 if ((this->exceptions() & ios_base::badbit) != 0)
281 __throw_exception_again;
287 #ifdef _GLIBCPP_USE_LONG_LONG
288 template<typename _CharT, typename _Traits>
289 basic_istream<_CharT, _Traits>&
290 basic_istream<_CharT, _Traits>::
291 operator>>(long long& __n)
293 sentry __cerb(*this, false);
298 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
299 if (_M_check_facet(_M_fnumget))
300 _M_fnumget->get(*this, 0, *this, __err, __n);
301 this->setstate(__err);
303 catch(exception& __fail)
305 // 27.6.1.2.1 Common requirements.
306 // Turn this on without causing an ios::failure to be thrown.
307 this->setstate(ios_base::badbit);
308 if ((this->exceptions() & ios_base::badbit) != 0)
309 __throw_exception_again;
315 template<typename _CharT, typename _Traits>
316 basic_istream<_CharT, _Traits>&
317 basic_istream<_CharT, _Traits>::
318 operator>>(unsigned long long& __n)
320 sentry __cerb(*this, false);
325 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
326 if (_M_check_facet(_M_fnumget))
327 _M_fnumget->get(*this, 0, *this, __err, __n);
328 this->setstate(__err);
330 catch(exception& __fail)
332 // 27.6.1.2.1 Common requirements.
333 // Turn this on without causing an ios::failure to be thrown.
334 this->setstate(ios_base::badbit);
335 if ((this->exceptions() & ios_base::badbit) != 0)
336 __throw_exception_again;
343 template<typename _CharT, typename _Traits>
344 basic_istream<_CharT, _Traits>&
345 basic_istream<_CharT, _Traits>::
346 operator>>(float& __n)
348 sentry __cerb(*this, false);
353 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
354 if (_M_check_facet(_M_fnumget))
355 _M_fnumget->get(*this, 0, *this, __err, __n);
356 this->setstate(__err);
358 catch(exception& __fail)
360 // 27.6.1.2.1 Common requirements.
361 // Turn this on without causing an ios::failure to be thrown.
362 this->setstate(ios_base::badbit);
363 if ((this->exceptions() & ios_base::badbit) != 0)
364 __throw_exception_again;
370 template<typename _CharT, typename _Traits>
371 basic_istream<_CharT, _Traits>&
372 basic_istream<_CharT, _Traits>::
373 operator>>(double& __n)
375 sentry __cerb(*this, false);
380 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
381 if (_M_check_facet(_M_fnumget))
382 _M_fnumget->get(*this, 0, *this, __err, __n);
383 this->setstate(__err);
385 catch(exception& __fail)
387 // 27.6.1.2.1 Common requirements.
388 // Turn this on without causing an ios::failure to be thrown.
389 this->setstate(ios_base::badbit);
390 if ((this->exceptions() & ios_base::badbit) != 0)
391 __throw_exception_again;
397 template<typename _CharT, typename _Traits>
398 basic_istream<_CharT, _Traits>&
399 basic_istream<_CharT, _Traits>::
400 operator>>(long double& __n)
402 sentry __cerb(*this, false);
407 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
408 if (_M_check_facet(_M_fnumget))
409 _M_fnumget->get(*this, 0, *this, __err, __n);
410 this->setstate(__err);
412 catch(exception& __fail)
414 // 27.6.1.2.1 Common requirements.
415 // Turn this on without causing an ios::failure to be thrown.
416 this->setstate(ios_base::badbit);
417 if ((this->exceptions() & ios_base::badbit) != 0)
418 __throw_exception_again;
424 template<typename _CharT, typename _Traits>
425 basic_istream<_CharT, _Traits>&
426 basic_istream<_CharT, _Traits>::
427 operator>>(void*& __n)
429 sentry __cerb(*this, false);
434 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
435 if (_M_check_facet(_M_fnumget))
436 _M_fnumget->get(*this, 0, *this, __err, __n);
437 this->setstate(__err);
439 catch(exception& __fail)
441 // 27.6.1.2.1 Common requirements.
442 // Turn this on without causing an ios::failure to be thrown.
443 this->setstate(ios_base::badbit);
444 if ((this->exceptions() & ios_base::badbit) != 0)
445 __throw_exception_again;
451 template<typename _CharT, typename _Traits>
452 basic_istream<_CharT, _Traits>&
453 basic_istream<_CharT, _Traits>::
454 operator>>(__streambuf_type* __sbout)
456 streamsize __xtrct = 0;
457 __streambuf_type* __sbin = this->rdbuf();
458 sentry __cerb(*this, false);
459 if (__sbout && __cerb)
460 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
461 if (!__sbout || !__xtrct)
462 this->setstate(ios_base::failbit);
466 template<typename _CharT, typename _Traits>
467 basic_istream<_CharT, _Traits>::int_type
468 basic_istream<_CharT, _Traits>::
471 const int_type __eof = traits_type::eof();
472 int_type __c = __eof;
474 sentry __cerb(*this, true);
479 __c = this->rdbuf()->sbumpc();
480 // 27.6.1.1 paragraph 3
484 this->setstate(ios_base::eofbit | ios_base::failbit);
486 catch(exception& __fail)
488 // 27.6.1.3 paragraph 1
489 // Turn this on without causing an ios::failure to be thrown.
490 this->setstate(ios_base::badbit);
491 if ((this->exceptions() & ios_base::badbit) != 0)
492 __throw_exception_again;
498 template<typename _CharT, typename _Traits>
499 basic_istream<_CharT, _Traits>&
500 basic_istream<_CharT, _Traits>::
504 sentry __cerb(*this, true);
509 const int_type __eof = traits_type::eof();
510 int_type __bufval = this->rdbuf()->sbumpc();
511 // 27.6.1.1 paragraph 3
512 if (__bufval != __eof)
515 __c = traits_type::to_char_type(__bufval);
518 this->setstate(ios_base::eofbit | ios_base::failbit);
520 catch(exception& __fail)
522 // 27.6.1.3 paragraph 1
523 // Turn this on without causing an ios::failure to be thrown.
524 this->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>::
535 get(char_type* __s, streamsize __n, char_type __delim)
538 sentry __cerb(*this, true);
539 if (__cerb && __n > 1)
543 const int_type __idelim = traits_type::to_int_type(__delim);
544 const int_type __eof = traits_type::eof();
545 __streambuf_type* __sb = this->rdbuf();
546 int_type __c = __sb->sbumpc();
547 bool __testdelim = __c == __idelim;
548 bool __testeof = __c == __eof;
550 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
552 *__s++ = traits_type::to_char_type(__c);
554 __c = __sb->sbumpc();
555 __testeof = __c == __eof;
556 __testdelim = __c == __idelim;
558 if (__testdelim || _M_gcount == __n - 1)
559 __sb->sputbackc(__c);
561 this->setstate(ios_base::eofbit);
563 catch(exception& __fail)
565 // 27.6.1.3 paragraph 1
566 // Turn this on without causing an ios::failure to be thrown.
567 this->setstate(ios_base::badbit);
568 if ((this->exceptions() & ios_base::badbit) != 0)
569 __throw_exception_again;
572 *__s = char_type(NULL);
574 this->setstate(ios_base::failbit);
578 template<typename _CharT, typename _Traits>
579 basic_istream<_CharT, _Traits>&
580 basic_istream<_CharT, _Traits>::
581 get(__streambuf_type& __sb, char_type __delim)
584 sentry __cerb(*this, true);
588 __streambuf_type* __this_sb = this->rdbuf();
591 const int_type __idelim = traits_type::to_int_type(__delim);
592 const int_type __eof = traits_type::eof();
593 __c = __this_sb->sbumpc();
594 bool __testdelim = __c == __idelim;
595 bool __testeof = __c == __eof;
596 bool __testput = true;
598 while (!__testeof && !__testdelim
599 && (__testput = __sb.sputc(traits_type::to_char_type(__c))
603 __c = __this_sb->sbumpc();
604 __testeof = __c == __eof;
605 __testdelim = __c == __idelim;
607 if (__testdelim || !__testput)
608 __this_sb->sputbackc(traits_type::to_char_type(__c));
610 this->setstate(ios_base::eofbit);
612 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);
634 __streambuf_type* __sb = this->rdbuf();
635 int_type __c = __sb->sbumpc();
637 const int_type __idelim = traits_type::to_int_type(__delim);
638 const int_type __eof = traits_type::eof();
639 bool __testdelim = __c == __idelim;
640 bool __testeof = __c == __eof;
642 while (_M_gcount < __n && !__testeof && !__testdelim)
644 *__s++ = traits_type::to_char_type(__c);
645 __c = __sb->sbumpc();
647 __testeof = __c == __eof;
648 __testdelim = __c == __idelim;
654 this->setstate(ios_base::eofbit);
656 else if (!__testdelim)
659 __sb->sputbackc(traits_type::to_char_type(__c));
660 this->setstate(ios_base::failbit);
663 catch(exception& __fail)
665 // 27.6.1.3 paragraph 1
666 // Turn this on without causing an ios::failure to be thrown.
667 this->setstate(ios_base::badbit);
668 if ((this->exceptions() & ios_base::badbit) != 0)
669 __throw_exception_again;
672 *__s = char_type(NULL);
674 this->setstate(ios_base::failbit);
678 template<typename _CharT, typename _Traits>
679 basic_istream<_CharT, _Traits>&
680 basic_istream<_CharT, _Traits>::
681 ignore(streamsize __n, int_type __delim)
684 sentry __cerb(*this, true);
685 if (__cerb && __n > 0)
689 const int_type __idelim = traits_type::to_int_type(__delim);
690 const int_type __eof = traits_type::eof();
691 __streambuf_type* __sb = this->rdbuf();
692 int_type __c = __sb->sbumpc();
693 bool __testdelim = __c == __idelim;
694 bool __testeof = __c == __eof;
696 __n = min(__n, numeric_limits<streamsize>::max());
697 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
700 __c = __sb->sbumpc();
701 __testeof = __c == __eof;
702 __testdelim = __c == __idelim;
704 if ((_M_gcount == __n - 1 && !__testeof) || __testdelim)
707 this->setstate(ios_base::eofbit);
709 catch(exception& __fail)
711 // 27.6.1.3 paragraph 1
712 // Turn this on without causing an ios::failure to be thrown.
713 this->setstate(ios_base::badbit);
714 if ((this->exceptions() & ios_base::badbit) != 0)
715 __throw_exception_again;
721 template<typename _CharT, typename _Traits>
722 basic_istream<_CharT, _Traits>::int_type
723 basic_istream<_CharT, _Traits>::
726 int_type __c = traits_type::eof();
728 sentry __cerb(*this, true);
732 { __c = this->rdbuf()->sgetc(); }
733 catch(exception& __fail)
735 // 27.6.1.3 paragraph 1
736 // Turn this on without causing an ios::failure to be thrown.
737 this->setstate(ios_base::badbit);
738 if ((this->exceptions() & ios_base::badbit) != 0)
739 __throw_exception_again;
745 template<typename _CharT, typename _Traits>
746 basic_istream<_CharT, _Traits>&
747 basic_istream<_CharT, _Traits>::
748 read(char_type* __s, streamsize __n)
751 sentry __cerb(*this, true);
758 const int_type __eof = traits_type::eof();
759 __streambuf_type* __sb = this->rdbuf();
760 int_type __c = __sb->sbumpc();
761 bool __testeof = __c == __eof;
763 while (_M_gcount < __n - 1 && !__testeof)
765 *__s++ = traits_type::to_char_type(__c);
767 __c = __sb->sbumpc();
768 __testeof = __c == __eof;
771 this->setstate(ios_base::eofbit | ios_base::failbit);
774 // _M_gcount == __n - 1
775 *__s++ = traits_type::to_char_type(__c);
779 catch(exception& __fail)
781 // 27.6.1.3 paragraph 1
782 // Turn this on without causing an ios::failure to be thrown.
783 this->setstate(ios_base::badbit);
784 if ((this->exceptions() & ios_base::badbit) != 0)
785 __throw_exception_again;
790 this->setstate(ios_base::failbit);
794 template<typename _CharT, typename _Traits>
796 basic_istream<_CharT, _Traits>::
797 readsome(char_type* __s, streamsize __n)
799 const int_type __eof = traits_type::eof();
801 sentry __cerb(*this, true);
808 streamsize __num = this->rdbuf()->in_avail();
809 if (__num != static_cast<streamsize>(__eof))
811 __num = min(__num, __n);
812 _M_gcount = this->rdbuf()->sgetn(__s, __num);
815 this->setstate(ios_base::eofbit);
817 catch(exception& __fail)
819 // 27.6.1.3 paragraph 1
820 // Turn this on without causing an ios::failure to be thrown.
821 this->setstate(ios_base::badbit);
822 if ((this->exceptions() & ios_base::badbit) != 0)
823 __throw_exception_again;
828 this->setstate(ios_base::failbit);
832 template<typename _CharT, typename _Traits>
833 basic_istream<_CharT, _Traits>&
834 basic_istream<_CharT, _Traits>::
835 putback(char_type __c)
837 sentry __cerb(*this, true);
842 const int_type __eof = traits_type::eof();
843 __streambuf_type* __sb = this->rdbuf();
844 if (!__sb || __sb->sputbackc(__c) == __eof)
845 this->setstate(ios_base::badbit);
847 catch(exception& __fail)
849 // 27.6.1.3 paragraph 1
850 // Turn this on without causing an ios::failure to be thrown.
851 this->setstate(ios_base::badbit);
852 if ((this->exceptions() & ios_base::badbit) != 0)
853 __throw_exception_again;
857 this->setstate(ios_base::failbit);
861 template<typename _CharT, typename _Traits>
862 basic_istream<_CharT, _Traits>&
863 basic_istream<_CharT, _Traits>::
867 sentry __cerb(*this, true);
872 const int_type __eof = traits_type::eof();
873 __streambuf_type* __sb = this->rdbuf();
874 if (!__sb || __eof == __sb->sungetc())
875 this->setstate(ios_base::badbit);
877 catch(exception& __fail)
879 // 27.6.1.3 paragraph 1
880 // Turn this on without causing an ios::failure to be thrown.
881 this->setstate(ios_base::badbit);
882 if ((this->exceptions() & ios_base::badbit) != 0)
883 __throw_exception_again;
887 this->setstate(ios_base::failbit);
891 template<typename _CharT, typename _Traits>
893 basic_istream<_CharT, _Traits>::
896 int __ret = traits_type::eof();
898 sentry __cerb(*this, true);
903 __streambuf_type* __sb = this->rdbuf();
904 if (!__sb || __ret == __sb->pubsync())
905 this->setstate(ios_base::badbit);
909 catch(exception& __fail)
911 // 27.6.1.3 paragraph 1
912 // Turn this on without causing an ios::failure to be thrown.
913 this->setstate(ios_base::badbit);
914 if ((this->exceptions() & ios_base::badbit) != 0)
915 __throw_exception_again;
921 template<typename _CharT, typename _Traits>
922 typename basic_istream<_CharT, _Traits>::pos_type
923 basic_istream<_CharT, _Traits>::
926 pos_type __ret = pos_type(-1);
928 sentry __cerb(*this, true);
933 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
935 catch(exception& __fail)
937 // 27.6.1.3 paragraph 1
938 // Turn this on without causing an ios::failure to be thrown.
939 this->setstate(ios_base::badbit);
940 if ((this->exceptions() & ios_base::badbit) != 0)
941 __throw_exception_again;
948 template<typename _CharT, typename _Traits>
949 basic_istream<_CharT, _Traits>&
950 basic_istream<_CharT, _Traits>::
951 seekg(pos_type __pos)
954 sentry __cerb(*this, true);
959 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
960 // 136. seekp, seekg setting wrong streams?
961 this->rdbuf()->pubseekpos(__pos, ios_base::in);
964 catch(exception& __fail)
966 // 27.6.1.3 paragraph 1
967 // Turn this on without causing an ios::failure to be thrown.
968 this->setstate(ios_base::badbit);
969 if ((this->exceptions() & ios_base::badbit) != 0)
970 __throw_exception_again;
976 template<typename _CharT, typename _Traits>
977 basic_istream<_CharT, _Traits>&
978 basic_istream<_CharT, _Traits>::
979 seekg(off_type __off, ios_base::seekdir __dir)
982 sentry __cerb(*this, true);
987 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
988 // 136. seekp, seekg setting wrong streams?
989 this->rdbuf()->pubseekoff(__off, __dir, ios_base::in);
992 catch(exception& __fail)
994 // 27.6.1.3 paragraph 1
995 // Turn this on without causing an ios::failure to be thrown.
996 this->setstate(ios_base::badbit);
997 if ((this->exceptions() & ios_base::badbit) != 0)
998 __throw_exception_again;
1004 // 27.6.1.2.3 Character extraction templates
1005 template<typename _CharT, typename _Traits>
1006 basic_istream<_CharT, _Traits>&
1007 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
1009 typedef basic_istream<_CharT, _Traits> __istream_type;
1010 typename __istream_type::sentry __cerb(__in, false);
1015 catch(exception& __fail)
1017 // 27.6.1.2.1 Common requirements.
1018 // Turn this on without causing an ios::failure to be thrown.
1019 __in.setstate(ios_base::badbit);
1020 if ((__in.exceptions() & ios_base::badbit) != 0)
1021 __throw_exception_again;
1025 __in.setstate(ios_base::failbit);
1029 template<typename _CharT, typename _Traits>
1030 basic_istream<_CharT, _Traits>&
1031 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1033 typedef basic_istream<_CharT, _Traits> __istream_type;
1034 typedef typename __istream_type::__streambuf_type __streambuf_type;
1035 typedef typename _Traits::int_type int_type;
1036 typedef _CharT char_type;
1037 typedef ctype<_CharT> __ctype_type;
1038 streamsize __extracted = 0;
1040 typename __istream_type::sentry __cerb(__in, false);
1045 // Figure out how many characters to extract.
1046 streamsize __num = __in.width();
1048 __num = numeric_limits<streamsize>::max();
1050 __streambuf_type* __sb = __in.rdbuf();
1051 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1052 int_type __c = __sb->sbumpc();
1053 const int_type __eof = _Traits::eof();
1054 bool __testsp = __ctype->is(ctype_base::space, __c);
1055 bool __testeof = __c == __eof;
1057 while (__extracted < __num - 1 && !__testeof && !__testsp)
1061 __c = __sb->sbumpc();
1062 __testeof = __c == __eof;
1063 __testsp = __ctype->is(ctype_base::space, __c);
1067 __sb->sputbackc(__c);
1069 __in.setstate(ios_base::eofbit);
1071 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1072 //68. Extractors for char* should store null at end
1077 catch(exception& __fail)
1079 // 27.6.1.2.1 Common requirements.
1080 // Turn this on without causing an ios::failure to be thrown.
1081 __in.setstate(ios_base::badbit);
1082 if ((__in.exceptions() & ios_base::badbit) != 0)
1083 __throw_exception_again;
1087 __in.setstate(ios_base::failbit);
1091 // 27.6.1.4 Standard basic_istream manipulators
1092 template<typename _CharT, typename _Traits>
1093 basic_istream<_CharT,_Traits>&
1094 ws(basic_istream<_CharT,_Traits>& __in)
1096 typedef basic_istream<_CharT, _Traits> __istream_type;
1097 typedef typename __istream_type::__streambuf_type __streambuf_type;
1098 typedef typename __istream_type::__ctype_type __ctype_type;
1099 typedef typename __istream_type::int_type __int_type;
1100 typedef typename __istream_type::char_type __char_type;
1102 __streambuf_type* __sb = __in.rdbuf();
1103 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1104 const __int_type __eof = _Traits::eof();
1111 __c = __sb->sbumpc();
1112 __testeof = __c == __eof;
1113 __testsp = __ctype->is(ctype_base::space, __c);
1115 while (!__testeof && __testsp);
1117 if (!__testeof && !__testsp)
1118 __sb->sputbackc(__c);
1120 __in.setstate(ios_base::eofbit);
1125 // 21.3.7.9 basic_string::getline and operators
1126 template<typename _CharT, typename _Traits, typename _Alloc>
1127 basic_istream<_CharT, _Traits>&
1128 operator>>(basic_istream<_CharT, _Traits>& __in,
1129 basic_string<_CharT, _Traits, _Alloc>& __str)
1131 typedef basic_istream<_CharT, _Traits> __istream_type;
1132 typedef typename __istream_type::int_type __int_type;
1133 typedef typename __istream_type::__streambuf_type __streambuf_type;
1134 typedef typename __istream_type::__ctype_type __ctype_type;
1135 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1136 typedef typename __string_type::size_type __size_type;
1137 __size_type __extracted = 0;
1139 typename __istream_type::sentry __cerb(__in, false);
1143 streamsize __w = __in.width();
1145 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1147 __streambuf_type* __sb = __in.rdbuf();
1148 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1149 __int_type __c = __sb->sbumpc();
1150 const __int_type __eof = _Traits::eof();
1151 bool __testsp = __ctype->is(ctype_base::space, __c);
1152 bool __testeof = __c == __eof;
1154 while (__extracted < __n && !__testeof && !__testsp)
1156 __str += _Traits::to_char_type(__c);
1158 __c = __sb->sbumpc();
1159 __testeof = __c == __eof;
1160 __testsp = __ctype->is(ctype_base::space, __c);
1163 __sb->sputbackc(__c);
1165 __in.setstate(ios_base::eofbit);
1168 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1169 // 2000-02-01 Number to be determined
1171 __in.setstate (ios_base::failbit);
1176 template<typename _CharT, typename _Traits, typename _Alloc>
1177 basic_istream<_CharT, _Traits>&
1178 getline(basic_istream<_CharT, _Traits>& __in,
1179 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1181 typedef basic_istream<_CharT, _Traits> __istream_type;
1182 typedef typename __istream_type::int_type __int_type;
1183 typedef typename __istream_type::__streambuf_type __streambuf_type;
1184 typedef typename __istream_type::__ctype_type __ctype_type;
1185 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1186 typedef typename __string_type::size_type __size_type;
1188 __size_type __extracted = 0;
1189 bool __testdelim = false;
1190 typename __istream_type::sentry __cerb(__in, true);
1194 __size_type __n = __str.max_size();
1196 __int_type __idelim = _Traits::to_int_type(__delim);
1197 __streambuf_type* __sb = __in.rdbuf();
1198 __int_type __c = __sb->sbumpc();
1199 const __int_type __eof = _Traits::eof();
1200 __testdelim = __c == __idelim;
1201 bool __testeof = __c == __eof;
1203 while (__extracted <= __n && !__testeof && !__testdelim)
1205 __str += _Traits::to_char_type(__c);
1207 __c = __sb->sbumpc();
1208 __testeof = __c == __eof;
1209 __testdelim = __c == __idelim;
1212 __in.setstate(ios_base::eofbit);
1214 if (!__extracted && !__testdelim)
1215 __in.setstate(ios_base::failbit);
1219 template<class _CharT, class _Traits, class _Alloc>
1220 inline basic_istream<_CharT,_Traits>&
1221 getline(basic_istream<_CharT, _Traits>& __in,
1222 basic_string<_CharT,_Traits,_Alloc>& __str)
1223 { return getline(__in, __str, __in.widen('\n')); }