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);
138 if (_M_check_facet(_M_fnumget))
139 _M_fnumget->get(*this, 0, *this, __err, __l);
140 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
141 // 118. basic_istream uses nonexistent num_get member functions.
142 if (!(__err & ios_base::failbit)
143 && (numeric_limits<short>::min() <= __l
144 && __l <= numeric_limits<short>::max()))
147 __err |= ios_base::failbit;
149 this->setstate(__err);
151 catch(exception& __fail)
153 // 27.6.1.2.1 Common requirements.
154 // Turn this on without causing an ios::failure to be thrown.
155 this->setstate(ios_base::badbit);
156 if ((this->exceptions() & ios_base::badbit) != 0)
157 __throw_exception_again;
163 template<typename _CharT, typename _Traits>
164 basic_istream<_CharT, _Traits>&
165 basic_istream<_CharT, _Traits>::
166 operator>>(unsigned short& __n)
168 sentry __cerb(*this, false);
173 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
174 if (_M_check_facet(_M_fnumget))
175 _M_fnumget->get(*this, 0, *this, __err, __n);
176 this->setstate(__err);
178 catch(exception& __fail)
180 // 27.6.1.2.1 Common requirements.
181 // Turn this on without causing an ios::failure to be thrown.
182 this->setstate(ios_base::badbit);
183 if ((this->exceptions() & ios_base::badbit) != 0)
184 __throw_exception_again;
190 template<typename _CharT, typename _Traits>
191 basic_istream<_CharT, _Traits>&
192 basic_istream<_CharT, _Traits>::
195 sentry __cerb(*this, false);
200 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
202 if (_M_check_facet(_M_fnumget))
203 _M_fnumget->get(*this, 0, *this, __err, __l);
204 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
205 // 118. basic_istream uses nonexistent num_get member functions.
206 if (!(__err & ios_base::failbit)
207 && (numeric_limits<int>::min() <= __l
208 && __l <= numeric_limits<int>::max()))
211 __err |= ios_base::failbit;
213 this->setstate(__err);
215 catch(exception& __fail)
217 // 27.6.1.2.1 Common requirements.
218 // Turn this on without causing an ios::failure to be thrown.
219 this->setstate(ios_base::badbit);
220 if ((this->exceptions() & ios_base::badbit) != 0)
221 __throw_exception_again;
227 template<typename _CharT, typename _Traits>
228 basic_istream<_CharT, _Traits>&
229 basic_istream<_CharT, _Traits>::
230 operator>>(unsigned int& __n)
232 sentry __cerb(*this, false);
237 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
238 if (_M_check_facet(_M_fnumget))
239 _M_fnumget->get(*this, 0, *this, __err, __n);
240 this->setstate(__err);
242 catch(exception& __fail)
244 // 27.6.1.2.1 Common requirements.
245 // Turn this on without causing an ios::failure to be thrown.
246 this->setstate(ios_base::badbit);
247 if ((this->exceptions() & ios_base::badbit) != 0)
248 __throw_exception_again;
254 template<typename _CharT, typename _Traits>
255 basic_istream<_CharT, _Traits>&
256 basic_istream<_CharT, _Traits>::
257 operator>>(long& __n)
259 sentry __cerb(*this, false);
264 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
265 if (_M_check_facet(_M_fnumget))
266 _M_fnumget->get(*this, 0, *this, __err, __n);
267 this->setstate(__err);
269 catch(exception& __fail)
271 // 27.6.1.2.1 Common requirements.
272 // Turn this on without causing an ios::failure to be thrown.
273 this->setstate(ios_base::badbit);
274 if ((this->exceptions() & ios_base::badbit) != 0)
275 __throw_exception_again;
281 template<typename _CharT, typename _Traits>
282 basic_istream<_CharT, _Traits>&
283 basic_istream<_CharT, _Traits>::
284 operator>>(unsigned long& __n)
286 sentry __cerb(*this, false);
291 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
292 if (_M_check_facet(_M_fnumget))
293 _M_fnumget->get(*this, 0, *this, __err, __n);
294 this->setstate(__err);
296 catch(exception& __fail)
298 // 27.6.1.2.1 Common requirements.
299 // Turn this on without causing an ios::failure to be thrown.
300 this->setstate(ios_base::badbit);
301 if ((this->exceptions() & ios_base::badbit) != 0)
302 __throw_exception_again;
308 #ifdef _GLIBCPP_USE_LONG_LONG
309 template<typename _CharT, typename _Traits>
310 basic_istream<_CharT, _Traits>&
311 basic_istream<_CharT, _Traits>::
312 operator>>(long long& __n)
314 sentry __cerb(*this, false);
319 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
320 if (_M_check_facet(_M_fnumget))
321 _M_fnumget->get(*this, 0, *this, __err, __n);
322 this->setstate(__err);
324 catch(exception& __fail)
326 // 27.6.1.2.1 Common requirements.
327 // Turn this on without causing an ios::failure to be thrown.
328 this->setstate(ios_base::badbit);
329 if ((this->exceptions() & ios_base::badbit) != 0)
330 __throw_exception_again;
336 template<typename _CharT, typename _Traits>
337 basic_istream<_CharT, _Traits>&
338 basic_istream<_CharT, _Traits>::
339 operator>>(unsigned long long& __n)
341 sentry __cerb(*this, false);
346 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
347 if (_M_check_facet(_M_fnumget))
348 _M_fnumget->get(*this, 0, *this, __err, __n);
349 this->setstate(__err);
351 catch(exception& __fail)
353 // 27.6.1.2.1 Common requirements.
354 // Turn this on without causing an ios::failure to be thrown.
355 this->setstate(ios_base::badbit);
356 if ((this->exceptions() & ios_base::badbit) != 0)
357 __throw_exception_again;
364 template<typename _CharT, typename _Traits>
365 basic_istream<_CharT, _Traits>&
366 basic_istream<_CharT, _Traits>::
367 operator>>(float& __n)
369 sentry __cerb(*this, false);
374 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
375 if (_M_check_facet(_M_fnumget))
376 _M_fnumget->get(*this, 0, *this, __err, __n);
377 this->setstate(__err);
379 catch(exception& __fail)
381 // 27.6.1.2.1 Common requirements.
382 // Turn this on without causing an ios::failure to be thrown.
383 this->setstate(ios_base::badbit);
384 if ((this->exceptions() & ios_base::badbit) != 0)
385 __throw_exception_again;
391 template<typename _CharT, typename _Traits>
392 basic_istream<_CharT, _Traits>&
393 basic_istream<_CharT, _Traits>::
394 operator>>(double& __n)
396 sentry __cerb(*this, false);
401 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
402 if (_M_check_facet(_M_fnumget))
403 _M_fnumget->get(*this, 0, *this, __err, __n);
404 this->setstate(__err);
406 catch(exception& __fail)
408 // 27.6.1.2.1 Common requirements.
409 // Turn this on without causing an ios::failure to be thrown.
410 this->setstate(ios_base::badbit);
411 if ((this->exceptions() & ios_base::badbit) != 0)
412 __throw_exception_again;
418 template<typename _CharT, typename _Traits>
419 basic_istream<_CharT, _Traits>&
420 basic_istream<_CharT, _Traits>::
421 operator>>(long double& __n)
423 sentry __cerb(*this, false);
428 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
429 if (_M_check_facet(_M_fnumget))
430 _M_fnumget->get(*this, 0, *this, __err, __n);
431 this->setstate(__err);
433 catch(exception& __fail)
435 // 27.6.1.2.1 Common requirements.
436 // Turn this on without causing an ios::failure to be thrown.
437 this->setstate(ios_base::badbit);
438 if ((this->exceptions() & ios_base::badbit) != 0)
439 __throw_exception_again;
445 template<typename _CharT, typename _Traits>
446 basic_istream<_CharT, _Traits>&
447 basic_istream<_CharT, _Traits>::
448 operator>>(void*& __n)
450 sentry __cerb(*this, false);
455 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
456 if (_M_check_facet(_M_fnumget))
457 _M_fnumget->get(*this, 0, *this, __err, __n);
458 this->setstate(__err);
460 catch(exception& __fail)
462 // 27.6.1.2.1 Common requirements.
463 // Turn this on without causing an ios::failure to be thrown.
464 this->setstate(ios_base::badbit);
465 if ((this->exceptions() & ios_base::badbit) != 0)
466 __throw_exception_again;
472 template<typename _CharT, typename _Traits>
473 basic_istream<_CharT, _Traits>&
474 basic_istream<_CharT, _Traits>::
475 operator>>(__streambuf_type* __sbout)
477 sentry __cerb(*this, false);
482 streamsize __xtrct = 0;
485 __streambuf_type* __sbin = this->rdbuf();
486 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
488 if (!__sbout || !__xtrct)
489 this->setstate(ios_base::failbit);
491 catch(exception& __fail)
493 // 27.6.2.5.1 Common requirements.
494 // Turn this on without causing an ios::failure to be thrown.
495 this->setstate(ios_base::badbit);
496 if ((this->exceptions() & ios_base::badbit) != 0)
497 __throw_exception_again;
503 template<typename _CharT, typename _Traits>
504 typename basic_istream<_CharT, _Traits>::int_type
505 basic_istream<_CharT, _Traits>::
508 const int_type __eof = traits_type::eof();
509 int_type __c = __eof;
511 sentry __cerb(*this, true);
516 __c = this->rdbuf()->sbumpc();
517 // 27.6.1.1 paragraph 3
521 this->setstate(ios_base::eofbit | ios_base::failbit);
523 catch(exception& __fail)
525 // 27.6.1.3 paragraph 1
526 // Turn this on without causing an ios::failure to be thrown.
527 this->setstate(ios_base::badbit);
528 if ((this->exceptions() & ios_base::badbit) != 0)
529 __throw_exception_again;
535 template<typename _CharT, typename _Traits>
536 basic_istream<_CharT, _Traits>&
537 basic_istream<_CharT, _Traits>::
541 sentry __cerb(*this, true);
546 const int_type __eof = traits_type::eof();
547 int_type __bufval = this->rdbuf()->sbumpc();
548 // 27.6.1.1 paragraph 3
549 if (__bufval != __eof)
552 __c = traits_type::to_char_type(__bufval);
555 this->setstate(ios_base::eofbit | ios_base::failbit);
557 catch(exception& __fail)
559 // 27.6.1.3 paragraph 1
560 // Turn this on without causing an ios::failure to be thrown.
561 this->setstate(ios_base::badbit);
562 if ((this->exceptions() & ios_base::badbit) != 0)
563 __throw_exception_again;
569 template<typename _CharT, typename _Traits>
570 basic_istream<_CharT, _Traits>&
571 basic_istream<_CharT, _Traits>::
572 get(char_type* __s, streamsize __n, char_type __delim)
575 sentry __cerb(*this, true);
576 if (__cerb && __n > 1)
580 const int_type __idelim = traits_type::to_int_type(__delim);
581 const int_type __eof = traits_type::eof();
582 __streambuf_type* __sb = this->rdbuf();
583 int_type __c = __sb->sbumpc();
584 bool __testdelim = __c == __idelim;
585 bool __testeof = __c == __eof;
587 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
589 *__s++ = traits_type::to_char_type(__c);
591 __c = __sb->sbumpc();
592 __testeof = __c == __eof;
593 __testdelim = __c == __idelim;
595 if (__testdelim || _M_gcount == __n - 1)
596 __sb->sputbackc(__c);
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);
625 __streambuf_type* __this_sb = this->rdbuf();
628 const int_type __idelim = traits_type::to_int_type(__delim);
629 const int_type __eof = traits_type::eof();
630 __c = __this_sb->sbumpc();
631 bool __testdelim = __c == __idelim;
632 bool __testeof = __c == __eof;
633 bool __testput = true;
635 while (!__testeof && !__testdelim
636 && (__testput = __sb.sputc(traits_type::to_char_type(__c))
640 __c = __this_sb->sbumpc();
641 __testeof = __c == __eof;
642 __testdelim = __c == __idelim;
644 if (__testdelim || !__testput)
645 __this_sb->sputbackc(traits_type::to_char_type(__c));
647 this->setstate(ios_base::eofbit);
649 catch(exception& __fail)
651 // Exception may result from sputc->overflow.
652 __this_sb->sputbackc(traits_type::to_char_type(__c));
656 this->setstate(ios_base::failbit);
660 template<typename _CharT, typename _Traits>
661 basic_istream<_CharT, _Traits>&
662 basic_istream<_CharT, _Traits>::
663 getline(char_type* __s, streamsize __n, char_type __delim)
666 sentry __cerb(*this, true);
671 __streambuf_type* __sb = this->rdbuf();
672 int_type __c = __sb->sbumpc();
674 const int_type __idelim = traits_type::to_int_type(__delim);
675 const int_type __eof = traits_type::eof();
676 bool __testdelim = __c == __idelim;
677 bool __testeof = __c == __eof;
679 while (_M_gcount < __n && !__testeof && !__testdelim)
681 *__s++ = traits_type::to_char_type(__c);
682 __c = __sb->sbumpc();
684 __testeof = __c == __eof;
685 __testdelim = __c == __idelim;
691 this->setstate(ios_base::eofbit);
693 else if (!__testdelim)
696 __sb->sputbackc(traits_type::to_char_type(__c));
697 this->setstate(ios_base::failbit);
700 catch(exception& __fail)
702 // 27.6.1.3 paragraph 1
703 // Turn this on without causing an ios::failure to be thrown.
704 this->setstate(ios_base::badbit);
705 if ((this->exceptions() & ios_base::badbit) != 0)
706 __throw_exception_again;
711 this->setstate(ios_base::failbit);
715 template<typename _CharT, typename _Traits>
716 basic_istream<_CharT, _Traits>&
717 basic_istream<_CharT, _Traits>::
718 ignore(streamsize __n, int_type __delim)
721 sentry __cerb(*this, true);
722 if (__cerb && __n > 0)
726 const int_type __idelim = traits_type::to_int_type(__delim);
727 const int_type __eof = traits_type::eof();
728 __streambuf_type* __sb = this->rdbuf();
729 int_type __c = __sb->sbumpc();
730 bool __testdelim = __c == __idelim;
731 bool __testeof = __c == __eof;
733 __n = min(__n, numeric_limits<streamsize>::max());
734 while (_M_gcount < __n - 1 && !__testeof && !__testdelim)
737 __c = __sb->sbumpc();
738 __testeof = __c == __eof;
739 __testdelim = __c == __idelim;
741 if ((_M_gcount == __n - 1 && !__testeof) || __testdelim)
744 this->setstate(ios_base::eofbit);
746 catch(exception& __fail)
748 // 27.6.1.3 paragraph 1
749 // Turn this on without causing an ios::failure to be thrown.
750 this->setstate(ios_base::badbit);
751 if ((this->exceptions() & ios_base::badbit) != 0)
752 __throw_exception_again;
758 template<typename _CharT, typename _Traits>
759 typename basic_istream<_CharT, _Traits>::int_type
760 basic_istream<_CharT, _Traits>::
763 int_type __c = traits_type::eof();
765 sentry __cerb(*this, true);
769 { __c = this->rdbuf()->sgetc(); }
770 catch(exception& __fail)
772 // 27.6.1.3 paragraph 1
773 // Turn this on without causing an ios::failure to be thrown.
774 this->setstate(ios_base::badbit);
775 if ((this->exceptions() & ios_base::badbit) != 0)
776 __throw_exception_again;
782 template<typename _CharT, typename _Traits>
783 basic_istream<_CharT, _Traits>&
784 basic_istream<_CharT, _Traits>::
785 read(char_type* __s, streamsize __n)
788 sentry __cerb(*this, true);
795 const int_type __eof = traits_type::eof();
796 __streambuf_type* __sb = this->rdbuf();
797 int_type __c = __sb->sbumpc();
798 bool __testeof = __c == __eof;
800 while (_M_gcount < __n - 1 && !__testeof)
802 *__s++ = traits_type::to_char_type(__c);
804 __c = __sb->sbumpc();
805 __testeof = __c == __eof;
808 this->setstate(ios_base::eofbit | ios_base::failbit);
811 // _M_gcount == __n - 1
812 *__s++ = traits_type::to_char_type(__c);
816 catch(exception& __fail)
818 // 27.6.1.3 paragraph 1
819 // Turn this on without causing an ios::failure to be thrown.
820 this->setstate(ios_base::badbit);
821 if ((this->exceptions() & ios_base::badbit) != 0)
822 __throw_exception_again;
827 this->setstate(ios_base::failbit);
831 template<typename _CharT, typename _Traits>
833 basic_istream<_CharT, _Traits>::
834 readsome(char_type* __s, streamsize __n)
836 const int_type __eof = traits_type::eof();
838 sentry __cerb(*this, true);
845 streamsize __num = this->rdbuf()->in_avail();
846 if (__num != static_cast<streamsize>(__eof))
848 __num = min(__num, __n);
849 _M_gcount = this->rdbuf()->sgetn(__s, __num);
852 this->setstate(ios_base::eofbit);
854 catch(exception& __fail)
856 // 27.6.1.3 paragraph 1
857 // Turn this on without causing an ios::failure to be thrown.
858 this->setstate(ios_base::badbit);
859 if ((this->exceptions() & ios_base::badbit) != 0)
860 __throw_exception_again;
865 this->setstate(ios_base::failbit);
869 template<typename _CharT, typename _Traits>
870 basic_istream<_CharT, _Traits>&
871 basic_istream<_CharT, _Traits>::
872 putback(char_type __c)
874 sentry __cerb(*this, true);
879 const int_type __eof = traits_type::eof();
880 __streambuf_type* __sb = this->rdbuf();
881 if (!__sb || __sb->sputbackc(__c) == __eof)
882 this->setstate(ios_base::badbit);
884 catch(exception& __fail)
886 // 27.6.1.3 paragraph 1
887 // Turn this on without causing an ios::failure to be thrown.
888 this->setstate(ios_base::badbit);
889 if ((this->exceptions() & ios_base::badbit) != 0)
890 __throw_exception_again;
894 this->setstate(ios_base::failbit);
898 template<typename _CharT, typename _Traits>
899 basic_istream<_CharT, _Traits>&
900 basic_istream<_CharT, _Traits>::
904 sentry __cerb(*this, true);
909 const int_type __eof = traits_type::eof();
910 __streambuf_type* __sb = this->rdbuf();
911 if (!__sb || __eof == __sb->sungetc())
912 this->setstate(ios_base::badbit);
914 catch(exception& __fail)
916 // 27.6.1.3 paragraph 1
917 // Turn this on without causing an ios::failure to be thrown.
918 this->setstate(ios_base::badbit);
919 if ((this->exceptions() & ios_base::badbit) != 0)
920 __throw_exception_again;
924 this->setstate(ios_base::failbit);
928 template<typename _CharT, typename _Traits>
930 basic_istream<_CharT, _Traits>::
933 int __ret = traits_type::eof();
935 sentry __cerb(*this, true);
940 __streambuf_type* __sb = this->rdbuf();
941 if (!__sb || __ret == __sb->pubsync())
942 this->setstate(ios_base::badbit);
946 catch(exception& __fail)
948 // 27.6.1.3 paragraph 1
949 // Turn this on without causing an ios::failure to be thrown.
950 this->setstate(ios_base::badbit);
951 if ((this->exceptions() & ios_base::badbit) != 0)
952 __throw_exception_again;
958 template<typename _CharT, typename _Traits>
959 typename basic_istream<_CharT, _Traits>::pos_type
960 basic_istream<_CharT, _Traits>::
963 pos_type __ret = pos_type(-1);
965 sentry __cerb(*this, true);
970 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
972 catch(exception& __fail)
974 // 27.6.1.3 paragraph 1
975 // Turn this on without causing an ios::failure to be thrown.
976 this->setstate(ios_base::badbit);
977 if ((this->exceptions() & ios_base::badbit) != 0)
978 __throw_exception_again;
985 template<typename _CharT, typename _Traits>
986 basic_istream<_CharT, _Traits>&
987 basic_istream<_CharT, _Traits>::
988 seekg(pos_type __pos)
991 sentry __cerb(*this, true);
996 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
997 // 136. seekp, seekg setting wrong streams?
998 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
1000 // 129. Need error indication from seekp() and seekg()
1001 if (__err == pos_type(off_type(-1)))
1002 this->setstate(ios_base::failbit);
1005 catch(exception& __fail)
1007 // 27.6.1.3 paragraph 1
1008 // Turn this on without causing an ios::failure to be thrown.
1009 this->setstate(ios_base::badbit);
1010 if ((this->exceptions() & ios_base::badbit) != 0)
1011 __throw_exception_again;
1017 template<typename _CharT, typename _Traits>
1018 basic_istream<_CharT, _Traits>&
1019 basic_istream<_CharT, _Traits>::
1020 seekg(off_type __off, ios_base::seekdir __dir)
1023 sentry __cerb(*this, true);
1028 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1029 // 136. seekp, seekg setting wrong streams?
1030 pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
1033 // 129. Need error indication from seekp() and seekg()
1034 if (__err == pos_type(off_type(-1)))
1035 this->setstate(ios_base::failbit);
1038 catch(exception& __fail)
1040 // 27.6.1.3 paragraph 1
1041 // Turn this on without causing an ios::failure to be thrown.
1042 this->setstate(ios_base::badbit);
1043 if ((this->exceptions() & ios_base::badbit) != 0)
1044 __throw_exception_again;
1050 // 27.6.1.2.3 Character extraction templates
1051 template<typename _CharT, typename _Traits>
1052 basic_istream<_CharT, _Traits>&
1053 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
1055 typedef basic_istream<_CharT, _Traits> __istream_type;
1056 typename __istream_type::sentry __cerb(__in, false);
1061 catch(exception& __fail)
1063 // 27.6.1.2.1 Common requirements.
1064 // Turn this on without causing an ios::failure to be thrown.
1065 __in.setstate(ios_base::badbit);
1066 if ((__in.exceptions() & ios_base::badbit) != 0)
1067 __throw_exception_again;
1071 __in.setstate(ios_base::failbit);
1075 template<typename _CharT, typename _Traits>
1076 basic_istream<_CharT, _Traits>&
1077 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
1079 typedef basic_istream<_CharT, _Traits> __istream_type;
1080 typedef typename __istream_type::__streambuf_type __streambuf_type;
1081 typedef typename _Traits::int_type int_type;
1082 typedef _CharT char_type;
1083 typedef ctype<_CharT> __ctype_type;
1084 streamsize __extracted = 0;
1086 typename __istream_type::sentry __cerb(__in, false);
1091 // Figure out how many characters to extract.
1092 streamsize __num = __in.width();
1094 __num = numeric_limits<streamsize>::max();
1096 __streambuf_type* __sb = __in.rdbuf();
1097 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1098 int_type __c = __sb->sbumpc();
1099 const int_type __eof = _Traits::eof();
1100 bool __testsp = __ctype->is(ctype_base::space, __c);
1101 bool __testeof = __c == __eof;
1103 while (__extracted < __num - 1 && !__testeof && !__testsp)
1107 __c = __sb->sbumpc();
1108 __testeof = __c == __eof;
1109 __testsp = __ctype->is(ctype_base::space, __c);
1113 __sb->sputbackc(__c);
1115 __in.setstate(ios_base::eofbit);
1117 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1118 //68. Extractors for char* should store null at end
1123 catch(exception& __fail)
1125 // 27.6.1.2.1 Common requirements.
1126 // Turn this on without causing an ios::failure to be thrown.
1127 __in.setstate(ios_base::badbit);
1128 if ((__in.exceptions() & ios_base::badbit) != 0)
1129 __throw_exception_again;
1133 __in.setstate(ios_base::failbit);
1137 // 27.6.1.4 Standard basic_istream manipulators
1138 template<typename _CharT, typename _Traits>
1139 basic_istream<_CharT,_Traits>&
1140 ws(basic_istream<_CharT,_Traits>& __in)
1142 typedef basic_istream<_CharT, _Traits> __istream_type;
1143 typedef typename __istream_type::__streambuf_type __streambuf_type;
1144 typedef typename __istream_type::__ctype_type __ctype_type;
1145 typedef typename __istream_type::int_type __int_type;
1146 typedef typename __istream_type::char_type __char_type;
1148 __streambuf_type* __sb = __in.rdbuf();
1149 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1150 const __int_type __eof = _Traits::eof();
1157 __c = __sb->sbumpc();
1158 __testeof = __c == __eof;
1159 __testsp = __ctype->is(ctype_base::space, __c);
1161 while (!__testeof && __testsp);
1163 if (!__testeof && !__testsp)
1164 __sb->sputbackc(__c);
1166 __in.setstate(ios_base::eofbit);
1171 // 21.3.7.9 basic_string::getline and operators
1172 template<typename _CharT, typename _Traits, typename _Alloc>
1173 basic_istream<_CharT, _Traits>&
1174 operator>>(basic_istream<_CharT, _Traits>& __in,
1175 basic_string<_CharT, _Traits, _Alloc>& __str)
1177 typedef basic_istream<_CharT, _Traits> __istream_type;
1178 typedef typename __istream_type::int_type __int_type;
1179 typedef typename __istream_type::__streambuf_type __streambuf_type;
1180 typedef typename __istream_type::__ctype_type __ctype_type;
1181 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1182 typedef typename __string_type::size_type __size_type;
1183 __size_type __extracted = 0;
1185 typename __istream_type::sentry __cerb(__in, false);
1189 streamsize __w = __in.width();
1191 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
1193 __streambuf_type* __sb = __in.rdbuf();
1194 const __ctype_type* __ctype = __in._M_get_fctype_ios();
1195 __int_type __c = __sb->sbumpc();
1196 const __int_type __eof = _Traits::eof();
1197 bool __testsp = __ctype->is(ctype_base::space, __c);
1198 bool __testeof = __c == __eof;
1200 while (__extracted < __n && !__testeof && !__testsp)
1202 __str += _Traits::to_char_type(__c);
1204 __c = __sb->sbumpc();
1205 __testeof = __c == __eof;
1206 __testsp = __ctype->is(ctype_base::space, __c);
1209 __sb->sputbackc(__c);
1211 __in.setstate(ios_base::eofbit);
1214 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
1215 //211. operator>>(istream&, string&) doesn't set failbit
1217 __in.setstate (ios_base::failbit);
1222 template<typename _CharT, typename _Traits, typename _Alloc>
1223 basic_istream<_CharT, _Traits>&
1224 getline(basic_istream<_CharT, _Traits>& __in,
1225 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
1227 typedef basic_istream<_CharT, _Traits> __istream_type;
1228 typedef typename __istream_type::int_type __int_type;
1229 typedef typename __istream_type::__streambuf_type __streambuf_type;
1230 typedef typename __istream_type::__ctype_type __ctype_type;
1231 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
1232 typedef typename __string_type::size_type __size_type;
1234 __size_type __extracted = 0;
1235 bool __testdelim = false;
1236 typename __istream_type::sentry __cerb(__in, true);
1240 __size_type __n = __str.max_size();
1242 __int_type __idelim = _Traits::to_int_type(__delim);
1243 __streambuf_type* __sb = __in.rdbuf();
1244 __int_type __c = __sb->sbumpc();
1245 const __int_type __eof = _Traits::eof();
1246 __testdelim = __c == __idelim;
1247 bool __testeof = __c == __eof;
1249 while (__extracted <= __n && !__testeof && !__testdelim)
1251 __str += _Traits::to_char_type(__c);
1253 __c = __sb->sbumpc();
1254 __testeof = __c == __eof;
1255 __testdelim = __c == __idelim;
1258 __in.setstate(ios_base::eofbit);
1260 if (!__extracted && !__testdelim)
1261 __in.setstate(ios_base::failbit);
1265 template<class _CharT, class _Traits, class _Alloc>
1266 inline basic_istream<_CharT,_Traits>&
1267 getline(basic_istream<_CharT, _Traits>& __in,
1268 basic_string<_CharT,_Traits,_Alloc>& __str)
1269 { return getline(__in, __str, __in.widen('\n')); }