1 // istream classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
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
35 #pragma GCC system_header
38 #include <ostream> // For flush()
42 template<typename _CharT, typename _Traits>
43 basic_istream<_CharT, _Traits>::sentry::
44 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
50 if (!__noskipws && (__in.flags() & ios_base::skipws))
52 const __int_type __eof = traits_type::eof();
53 __streambuf_type* __sb = __in.rdbuf();
54 __int_type __c = __sb->sgetc();
56 if (__in._M_check_facet(__in._M_fctype))
58 && __in._M_fctype->is(ctype_base::space, __c))
61 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
62 //195. Should basic_istream::sentry's constructor ever set eofbit?
64 __in.setstate(ios_base::eofbit);
74 __in.setstate(ios_base::failbit);
78 template<typename _CharT, typename _Traits>
79 basic_istream<_CharT, _Traits>&
80 basic_istream<_CharT, _Traits>::
81 operator>>(__istream_type& (*__pf)(__istream_type&))
87 template<typename _CharT, typename _Traits>
88 basic_istream<_CharT, _Traits>&
89 basic_istream<_CharT, _Traits>::
90 operator>>(__ios_type& (*__pf)(__ios_type&))
96 template<typename _CharT, typename _Traits>
97 basic_istream<_CharT, _Traits>&
98 basic_istream<_CharT, _Traits>::
99 operator>>(ios_base& (*__pf)(ios_base&))
105 template<typename _CharT, typename _Traits>
106 basic_istream<_CharT, _Traits>&
107 basic_istream<_CharT, _Traits>::
108 operator>>(bool& __n)
110 sentry __cerb(*this, false);
115 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
116 if (_M_check_facet(_M_fnumget))
117 _M_fnumget->get(*this, 0, *this, __err, __n);
118 this->setstate(__err);
120 catch(exception& __fail)
122 // 27.6.1.2.1 Common requirements.
123 // Turn this on without causing an ios::failure to be thrown.
124 this->setstate(ios_base::badbit);
125 if ((this->exceptions() & ios_base::badbit) != 0)
126 __throw_exception_again;
132 template<typename _CharT, typename _Traits>
133 basic_istream<_CharT, _Traits>&
134 basic_istream<_CharT, _Traits>::
135 operator>>(short& __n)
137 sentry __cerb(*this, false);
142 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
144 if (_M_check_facet(_M_fnumget))
145 _M_fnumget->get(*this, 0, *this, __err, __l);
146 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
147 // 118. basic_istream uses nonexistent num_get member functions.
148 if (!(__err & ios_base::failbit)
149 && (numeric_limits<short>::min() <= __l
150 && __l <= numeric_limits<short>::max()))
153 __err |= ios_base::failbit;
155 this->setstate(__err);
157 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>>(unsigned short& __n)
174 sentry __cerb(*this, false);
179 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
180 if (_M_check_facet(_M_fnumget))
181 _M_fnumget->get(*this, 0, *this, __err, __n);
182 this->setstate(__err);
184 catch(exception& __fail)
186 // 27.6.1.2.1 Common requirements.
187 // Turn this on without causing an ios::failure to be thrown.
188 this->setstate(ios_base::badbit);
189 if ((this->exceptions() & ios_base::badbit) != 0)
190 __throw_exception_again;
196 template<typename _CharT, typename _Traits>
197 basic_istream<_CharT, _Traits>&
198 basic_istream<_CharT, _Traits>::
201 sentry __cerb(*this, false);
206 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
208 if (_M_check_facet(_M_fnumget))
209 _M_fnumget->get(*this, 0, *this, __err, __l);
210 #ifdef _GLIBCPP_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);
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>>(unsigned int& __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>>(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 template<typename _CharT, typename _Traits>
288 basic_istream<_CharT, _Traits>&
289 basic_istream<_CharT, _Traits>::
290 operator>>(unsigned long& __n)
292 sentry __cerb(*this, false);
297 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
298 if (_M_check_facet(_M_fnumget))
299 _M_fnumget->get(*this, 0, *this, __err, __n);
300 this->setstate(__err);
302 catch(exception& __fail)
304 // 27.6.1.2.1 Common requirements.
305 // Turn this on without causing an ios::failure to be thrown.
306 this->setstate(ios_base::badbit);
307 if ((this->exceptions() & ios_base::badbit) != 0)
308 __throw_exception_again;
314 #ifdef _GLIBCPP_USE_LONG_LONG
315 template<typename _CharT, typename _Traits>
316 basic_istream<_CharT, _Traits>&
317 basic_istream<_CharT, _Traits>::
318 operator>>(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;
342 template<typename _CharT, typename _Traits>
343 basic_istream<_CharT, _Traits>&
344 basic_istream<_CharT, _Traits>::
345 operator>>(unsigned long long& __n)
347 sentry __cerb(*this, false);
352 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
353 if (_M_check_facet(_M_fnumget))
354 _M_fnumget->get(*this, 0, *this, __err, __n);
355 this->setstate(__err);
357 catch(exception& __fail)
359 // 27.6.1.2.1 Common requirements.
360 // Turn this on without causing an ios::failure to be thrown.
361 this->setstate(ios_base::badbit);
362 if ((this->exceptions() & ios_base::badbit) != 0)
363 __throw_exception_again;
370 template<typename _CharT, typename _Traits>
371 basic_istream<_CharT, _Traits>&
372 basic_istream<_CharT, _Traits>::
373 operator>>(float& __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>>(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>>(long double& __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>>(void*& __n)
456 sentry __cerb(*this, false);
461 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
462 if (_M_check_facet(_M_fnumget))
463 _M_fnumget->get(*this, 0, *this, __err, __n);
464 this->setstate(__err);
466 catch(exception& __fail)
468 // 27.6.1.2.1 Common requirements.
469 // Turn this on without causing an ios::failure to be thrown.
470 this->setstate(ios_base::badbit);
471 if ((this->exceptions() & ios_base::badbit) != 0)
472 __throw_exception_again;
478 template<typename _CharT, typename _Traits>
479 basic_istream<_CharT, _Traits>&
480 basic_istream<_CharT, _Traits>::
481 operator>>(__streambuf_type* __sbout)
483 sentry __cerb(*this, false);
488 streamsize __xtrct = 0;
491 __streambuf_type* __sbin = this->rdbuf();
492 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
494 if (!__sbout || !__xtrct)
495 this->setstate(ios_base::failbit);
497 catch(exception& __fail)
499 // 27.6.2.5.1 Common requirements.
500 // Turn this on without causing an ios::failure to be thrown.
501 this->setstate(ios_base::badbit);
502 if ((this->exceptions() & ios_base::badbit) != 0)
503 __throw_exception_again;
509 template<typename _CharT, typename _Traits>
510 typename basic_istream<_CharT, _Traits>::int_type
511 basic_istream<_CharT, _Traits>::
514 const int_type __eof = traits_type::eof();
515 int_type __c = __eof;
517 sentry __cerb(*this, true);
522 __c = this->rdbuf()->sbumpc();
523 // 27.6.1.1 paragraph 3
527 this->setstate(ios_base::eofbit | ios_base::failbit);
529 catch(exception& __fail)
531 // 27.6.1.3 paragraph 1
532 // Turn this on without causing an ios::failure to be thrown.
533 this->setstate(ios_base::badbit);
534 if ((this->exceptions() & ios_base::badbit) != 0)
535 __throw_exception_again;
541 template<typename _CharT, typename _Traits>
542 basic_istream<_CharT, _Traits>&
543 basic_istream<_CharT, _Traits>::
547 sentry __cerb(*this, true);
552 const int_type __eof = traits_type::eof();
553 int_type __bufval = this->rdbuf()->sbumpc();
554 // 27.6.1.1 paragraph 3
555 if (__bufval != __eof)
558 __c = traits_type::to_char_type(__bufval);
561 this->setstate(ios_base::eofbit | ios_base::failbit);
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;
575 template<typename _CharT, typename _Traits>
576 basic_istream<_CharT, _Traits>&
577 basic_istream<_CharT, _Traits>::
578 get(char_type* __s, streamsize __n, char_type __delim)
581 sentry __cerb(*this, true);
586 const int_type __idelim = traits_type::to_int_type(__delim);
587 const int_type __eof = traits_type::eof();
588 __streambuf_type* __sb = this->rdbuf();
589 int_type __c = __sb->sgetc();
591 while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim)
593 *__s++ = traits_type::to_char_type(__c);
594 __c = __sb->snextc();
598 this->setstate(ios_base::eofbit);
600 catch(exception& __fail)
602 // 27.6.1.3 paragraph 1
603 // Turn this on without causing an ios::failure to be thrown.
604 this->setstate(ios_base::badbit);
605 if ((this->exceptions() & ios_base::badbit) != 0)
606 __throw_exception_again;
611 this->setstate(ios_base::failbit);
615 template<typename _CharT, typename _Traits>
616 basic_istream<_CharT, _Traits>&
617 basic_istream<_CharT, _Traits>::
618 get(__streambuf_type& __sb, char_type __delim)
621 sentry __cerb(*this, true);
626 const int_type __idelim = traits_type::to_int_type(__delim);
627 const int_type __eof = traits_type::eof();
628 __streambuf_type* __this_sb = this->rdbuf();
629 int_type __c = __this_sb->sgetc();
631 while (__c != __eof && __c != __idelim
632 && (__sb.sputc(traits_type::to_char_type(__c)) != __eof))
635 __c = __this_sb->snextc();
638 this->setstate(ios_base::eofbit);
640 catch(exception& __fail)
642 // 27.6.1.3 paragraph 1
643 // Turn this on without causing an ios::failure to be thrown.
644 this->setstate(ios_base::badbit);
645 if ((this->exceptions() & ios_base::badbit) != 0)
646 __throw_exception_again;
650 this->setstate(ios_base::failbit);
654 template<typename _CharT, typename _Traits>
655 basic_istream<_CharT, _Traits>&
656 basic_istream<_CharT, _Traits>::
657 getline(char_type* __s, streamsize __n, char_type __delim)
660 sentry __cerb(*this, true);
665 const int_type __idelim = traits_type::to_int_type(__delim);
666 const int_type __eof = traits_type::eof();
667 __streambuf_type* __sb = this->rdbuf();
668 int_type __c = __sb->sgetc();
670 while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim)
672 *__s++ = traits_type::to_char_type(__c);
673 __c = __sb->snextc();
677 this->setstate(ios_base::eofbit);
686 this->setstate(ios_base::failbit);
689 catch(exception& __fail)
691 // 27.6.1.3 paragraph 1
692 // Turn this on without causing an ios::failure to be thrown.
693 this->setstate(ios_base::badbit);
694 if ((this->exceptions() & ios_base::badbit) != 0)
695 __throw_exception_again;
700 this->setstate(ios_base::failbit);
704 template<typename _CharT, typename _Traits>
705 basic_istream<_CharT, _Traits>&
706 basic_istream<_CharT, _Traits>::
707 ignore(streamsize __n, int_type __delim)
710 sentry __cerb(*this, true);
715 const int_type __eof = traits_type::eof();
716 __streambuf_type* __sb = this->rdbuf();
717 int_type __c = __sb->sgetc();
719 __n = min(__n, numeric_limits<streamsize>::max());
720 while (_M_gcount < __n && __c !=__eof && __c != __delim)
722 __c = __sb->snextc();
726 this->setstate(ios_base::eofbit);
727 else if (__c == __delim)
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 typename basic_istream<_CharT, _Traits>::int_type
747 basic_istream<_CharT, _Traits>::
750 int_type __c = traits_type::eof();
752 sentry __cerb(*this, true);
756 { __c = this->rdbuf()->sgetc(); }
757 catch(exception& __fail)
759 // 27.6.1.3 paragraph 1
760 // Turn this on without causing an ios::failure to be thrown.
761 this->setstate(ios_base::badbit);
762 if ((this->exceptions() & ios_base::badbit) != 0)
763 __throw_exception_again;
769 template<typename _CharT, typename _Traits>
770 basic_istream<_CharT, _Traits>&
771 basic_istream<_CharT, _Traits>::
772 read(char_type* __s, streamsize __n)
775 sentry __cerb(*this, true);
780 _M_gcount = this->rdbuf()->sgetn(__s, __n);
781 if (_M_gcount != __n)
782 this->setstate(ios_base::eofbit | ios_base::failbit);
784 catch(exception& __fail)
786 // 27.6.1.3 paragraph 1
787 // Turn this on without causing an ios::failure to be thrown.
788 this->setstate(ios_base::badbit);
789 if ((this->exceptions() & ios_base::badbit) != 0)
790 __throw_exception_again;
794 this->setstate(ios_base::failbit);
798 template<typename _CharT, typename _Traits>
800 basic_istream<_CharT, _Traits>::
801 readsome(char_type* __s, streamsize __n)
804 sentry __cerb(*this, true);
809 const int_type __eof = traits_type::eof();
810 streamsize __num = this->rdbuf()->in_avail();
811 if (__num != static_cast<streamsize>(__eof))
813 __num = min(__num, __n);
815 _M_gcount = this->rdbuf()->sgetn(__s, __num);
818 this->setstate(ios_base::eofbit);
820 catch(exception& __fail)
822 // 27.6.1.3 paragraph 1
823 // Turn this on without causing an ios::failure to be thrown.
824 this->setstate(ios_base::badbit);
825 if ((this->exceptions() & ios_base::badbit) != 0)
826 __throw_exception_again;
830 this->setstate(ios_base::failbit);
834 template<typename _CharT, typename _Traits>
835 basic_istream<_CharT, _Traits>&
836 basic_istream<_CharT, _Traits>::
837 putback(char_type __c)
839 sentry __cerb(*this, true);
844 const int_type __eof = traits_type::eof();
845 __streambuf_type* __sb = this->rdbuf();
846 if (!__sb || __sb->sputbackc(__c) == __eof)
847 this->setstate(ios_base::badbit);
849 catch(exception& __fail)
851 // 27.6.1.3 paragraph 1
852 // Turn this on without causing an ios::failure to be thrown.
853 this->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>::
869 sentry __cerb(*this, true);
874 const int_type __eof = traits_type::eof();
875 __streambuf_type* __sb = this->rdbuf();
876 if (!__sb || __eof == __sb->sungetc())
877 this->setstate(ios_base::badbit);
879 catch(exception& __fail)
881 // 27.6.1.3 paragraph 1
882 // Turn this on without causing an ios::failure to be thrown.
883 this->setstate(ios_base::badbit);
884 if ((this->exceptions() & ios_base::badbit) != 0)
885 __throw_exception_again;
889 this->setstate(ios_base::failbit);
893 template<typename _CharT, typename _Traits>
895 basic_istream<_CharT, _Traits>::
898 int __ret = traits_type::eof();
900 sentry __cerb(*this, true);
905 __streambuf_type* __sb = this->rdbuf();
906 if (!__sb || __ret == __sb->pubsync())
907 this->setstate(ios_base::badbit);
911 catch(exception& __fail)
913 // 27.6.1.3 paragraph 1
914 // Turn this on without causing an ios::failure to be thrown.
915 this->setstate(ios_base::badbit);
916 if ((this->exceptions() & ios_base::badbit) != 0)
917 __throw_exception_again;
923 template<typename _CharT, typename _Traits>
924 typename basic_istream<_CharT, _Traits>::pos_type
925 basic_istream<_CharT, _Traits>::
928 pos_type __ret = pos_type(-1);
930 sentry __cerb(*this, true);
935 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
937 catch(exception& __fail)
939 // 27.6.1.3 paragraph 1
940 // Turn this on without causing an ios::failure to be thrown.
941 this->setstate(ios_base::badbit);
942 if ((this->exceptions() & ios_base::badbit) != 0)
943 __throw_exception_again;
950 template<typename _CharT, typename _Traits>
951 basic_istream<_CharT, _Traits>&
952 basic_istream<_CharT, _Traits>::
953 seekg(pos_type __pos)
956 sentry __cerb(*this, true);
961 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
962 // 136. seekp, seekg setting wrong streams?
963 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
965 // 129. Need error indication from seekp() and seekg()
966 if (__err == pos_type(off_type(-1)))
967 this->setstate(ios_base::failbit);
970 catch(exception& __fail)
972 // 27.6.1.3 paragraph 1
973 // Turn this on without causing an ios::failure to be thrown.
974 this->setstate(ios_base::badbit);
975 if ((this->exceptions() & ios_base::badbit) != 0)
976 __throw_exception_again;
982 template<typename _CharT, typename _Traits>
983 basic_istream<_CharT, _Traits>&
984 basic_istream<_CharT, _Traits>::
985 seekg(off_type __off, ios_base::seekdir __dir)
988 sentry __cerb(*this, true);
993 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
994 // 136. seekp, seekg setting wrong streams?
995 pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
998 // 129. Need error indication from seekp() and seekg()
999 if (__err == pos_type(off_type(-1)))
1000 this->setstate(ios_base::failbit);
1003 catch(exception& __fail)
1005 // 27.6.1.3 paragraph 1
1006 // Turn this on without causing an ios::failure to be thrown.
1007 this->setstate(ios_base::badbit);
1008 if ((this->exceptions() & ios_base::badbit) != 0)
1009 __throw_exception_again;
1015 // 27.6.1.2.3 Character extraction templates
1016 template<typename _CharT, typename _Traits>
1017 basic_istream<_CharT, _Traits>&
1018 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
1020 typedef basic_istream<_CharT, _Traits> __istream_type;
1021 typename __istream_type::sentry __cerb(__in, false);
1026 catch(exception& __fail)
1028 // 27.6.1.2.1 Common requirements.
1029 // Turn this on without causing an ios::failure to be thrown.
1030 __in.setstate(ios_base::badbit);
1031 if ((__in.exceptions() & ios_base::badbit) != 0)
1032 __throw_exception_again;
1036 __in.setstate(ios_base::failbit);
1040 template<typename _CharT, typename _Traits>
1041 basic_istream<_CharT, _Traits>&
1042 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1044 typedef basic_istream<_CharT, _Traits> __istream_type;
1045 typedef typename __istream_type::__streambuf_type __streambuf_type;
1046 typedef typename _Traits::int_type int_type;
1047 typedef _CharT char_type;
1048 typedef ctype<_CharT> __ctype_type;
1049 streamsize __extracted = 0;
1051 typename __istream_type::sentry __cerb(__in, false);
1056 // Figure out how many characters to extract.
1057 streamsize __num = __in.width();
1059 __num = numeric_limits<streamsize>::max();
1061 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1062 const int_type __eof = _Traits::eof();
1063 __streambuf_type* __sb = __in.rdbuf();
1064 int_type __c = __sb->sgetc();
1066 while (__extracted < __num - 1
1067 && __c != __eof && !__ctype.is(ctype_base::space, __c))
1071 __c = __sb->snextc();
1074 __in.setstate(ios_base::eofbit);
1076 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1077 //68. Extractors for char* should store null at end
1082 catch(exception& __fail)
1084 // 27.6.1.2.1 Common requirements.
1085 // Turn this on without causing an ios::failure to be thrown.
1086 __in.setstate(ios_base::badbit);
1087 if ((__in.exceptions() & ios_base::badbit) != 0)
1088 __throw_exception_again;
1092 __in.setstate(ios_base::failbit);
1096 // 27.6.1.4 Standard basic_istream manipulators
1097 template<typename _CharT, typename _Traits>
1098 basic_istream<_CharT,_Traits>&
1099 ws(basic_istream<_CharT,_Traits>& __in)
1101 typedef basic_istream<_CharT, _Traits> __istream_type;
1102 typedef typename __istream_type::__streambuf_type __streambuf_type;
1103 typedef typename __istream_type::__ctype_type __ctype_type;
1104 typedef typename __istream_type::int_type __int_type;
1106 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1107 const __int_type __eof = _Traits::eof();
1108 __streambuf_type* __sb = __in.rdbuf();
1109 __int_type __c = __sb->sgetc();
1111 while (__c != __eof && __ctype.is(ctype_base::space, __c))
1112 __c = __sb->snextc();
1114 __in.setstate(ios_base::eofbit);
1119 // 21.3.7.9 basic_string::getline and operators
1120 template<typename _CharT, typename _Traits, typename _Alloc>
1121 basic_istream<_CharT, _Traits>&
1122 operator>>(basic_istream<_CharT, _Traits>& __in,
1123 basic_string<_CharT, _Traits, _Alloc>& __str)
1125 typedef basic_istream<_CharT, _Traits> __istream_type;
1126 typedef typename __istream_type::int_type __int_type;
1127 typedef typename __istream_type::__streambuf_type __streambuf_type;
1128 typedef typename __istream_type::__ctype_type __ctype_type;
1129 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1130 typedef typename __string_type::size_type __size_type;
1131 __size_type __extracted = 0;
1133 typename __istream_type::sentry __cerb(__in, false);
1137 streamsize __w = __in.width();
1139 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1141 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
1142 const __int_type __eof = _Traits::eof();
1143 __streambuf_type* __sb = __in.rdbuf();
1144 __int_type __c = __sb->sgetc();
1146 while (__extracted < __n
1147 && __c != __eof && !__ctype.is(ctype_base::space, __c))
1149 __str += _Traits::to_char_type(__c);
1151 __c = __sb->snextc();
1154 __in.setstate(ios_base::eofbit);
1157 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1158 //211. operator>>(istream&, string&) doesn't set failbit
1160 __in.setstate (ios_base::failbit);
1165 template<typename _CharT, typename _Traits, typename _Alloc>
1166 basic_istream<_CharT, _Traits>&
1167 getline(basic_istream<_CharT, _Traits>& __in,
1168 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1170 typedef basic_istream<_CharT, _Traits> __istream_type;
1171 typedef typename __istream_type::int_type __int_type;
1172 typedef typename __istream_type::__streambuf_type __streambuf_type;
1173 typedef typename __istream_type::__ctype_type __ctype_type;
1174 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1175 typedef typename __string_type::size_type __size_type;
1177 __size_type __extracted = 0;
1178 bool __testdelim = false;
1179 typename __istream_type::sentry __cerb(__in, true);
1183 __size_type __n = __str.max_size();
1185 __int_type __idelim = _Traits::to_int_type(__delim);
1186 __streambuf_type* __sb = __in.rdbuf();
1187 __int_type __c = __sb->sbumpc();
1188 const __int_type __eof = _Traits::eof();
1189 __testdelim = __c == __idelim;
1191 while (__extracted <= __n && __c != __eof && !__testdelim)
1193 __str += _Traits::to_char_type(__c);
1195 __c = __sb->sbumpc();
1196 __testdelim = __c == __idelim;
1199 __in.setstate(ios_base::eofbit);
1201 if (!__extracted && !__testdelim)
1202 __in.setstate(ios_base::failbit);
1206 template<class _CharT, class _Traits, class _Alloc>
1207 inline basic_istream<_CharT,_Traits>&
1208 getline(basic_istream<_CharT, _Traits>& __in,
1209 basic_string<_CharT,_Traits,_Alloc>& __str)
1210 { return getline(__in, __str, __in.widen('\n')); }
1212 // Inhibit implicit instantiations for required instantiations,
1213 // which are defined via explicit instantiations elsewhere.
1214 // NB: This syntax is a GNU extension.
1215 extern template class basic_istream<char>;
1216 extern template istream& ws(istream&);
1217 extern template istream& operator>>(istream&, char&);
1218 extern template istream& operator>>(istream&, char*);
1219 extern template istream& operator>>(istream&, unsigned char&);
1220 extern template istream& operator>>(istream&, signed char&);
1221 extern template istream& operator>>(istream&, unsigned char*);
1222 extern template istream& operator>>(istream&, signed char*);
1224 #ifdef _GLIBCPP_USE_WCHAR_T
1225 extern template class basic_istream<wchar_t>;
1226 extern template wistream& ws(wistream&);
1227 extern template wistream& operator>>(wistream&, wchar_t&);
1228 extern template wistream& operator>>(wistream&, wchar_t*);