00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma GCC system_header
00036
00037 #include <locale>
00038 #include <ostream>
00039
00040 namespace std
00041 {
00042 template<typename _CharT, typename _Traits>
00043 basic_istream<_CharT, _Traits>::sentry::
00044 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskipws)
00045 {
00046 if (__in.good())
00047 {
00048 if (__in.tie())
00049 __in.tie()->flush();
00050 if (!__noskipws && (__in.flags() & ios_base::skipws))
00051 {
00052 const __int_type __eof = traits_type::eof();
00053 __streambuf_type* __sb = __in.rdbuf();
00054 __int_type __c = __sb->sgetc();
00055
00056 if (__in._M_check_facet(__in._M_fctype))
00057 while (__c != __eof
00058 && __in._M_fctype->is(ctype_base::space, __c))
00059 __c = __sb->snextc();
00060
00061 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00062
00063 if (__c == __eof)
00064 __in.setstate(ios_base::eofbit);
00065 #endif
00066 }
00067 }
00068
00069 if (__in.good())
00070 _M_ok = true;
00071 else
00072 {
00073 _M_ok = false;
00074 __in.setstate(ios_base::failbit);
00075 }
00076 }
00077
00078 template<typename _CharT, typename _Traits>
00079 basic_istream<_CharT, _Traits>&
00080 basic_istream<_CharT, _Traits>::
00081 operator>>(__istream_type& (*__pf)(__istream_type&))
00082 {
00083 __pf(*this);
00084 return *this;
00085 }
00086
00087 template<typename _CharT, typename _Traits>
00088 basic_istream<_CharT, _Traits>&
00089 basic_istream<_CharT, _Traits>::
00090 operator>>(__ios_type& (*__pf)(__ios_type&))
00091 {
00092 __pf(*this);
00093 return *this;
00094 }
00095
00096 template<typename _CharT, typename _Traits>
00097 basic_istream<_CharT, _Traits>&
00098 basic_istream<_CharT, _Traits>::
00099 operator>>(ios_base& (*__pf)(ios_base&))
00100 {
00101 __pf(*this);
00102 return *this;
00103 }
00104
00105 template<typename _CharT, typename _Traits>
00106 basic_istream<_CharT, _Traits>&
00107 basic_istream<_CharT, _Traits>::
00108 operator>>(bool& __n)
00109 {
00110 sentry __cerb(*this, false);
00111 if (__cerb)
00112 {
00113 try
00114 {
00115 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00116 if (_M_check_facet(_M_fnumget))
00117 _M_fnumget->get(*this, 0, *this, __err, __n);
00118 this->setstate(__err);
00119 }
00120 catch(exception& __fail)
00121 {
00122
00123
00124 this->setstate(ios_base::badbit);
00125 if ((this->exceptions() & ios_base::badbit) != 0)
00126 __throw_exception_again;
00127 }
00128 }
00129 return *this;
00130 }
00131
00132 template<typename _CharT, typename _Traits>
00133 basic_istream<_CharT, _Traits>&
00134 basic_istream<_CharT, _Traits>::
00135 operator>>(short& __n)
00136 {
00137 sentry __cerb(*this, false);
00138 if (__cerb)
00139 {
00140 try
00141 {
00142 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00143 long __l;
00144 if (_M_check_facet(_M_fnumget))
00145 _M_fnumget->get(*this, 0, *this, __err, __l);
00146 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00147
00148 if (!(__err & ios_base::failbit)
00149 && (numeric_limits<short>::min() <= __l
00150 && __l <= numeric_limits<short>::max()))
00151 __n = __l;
00152 else
00153 __err |= ios_base::failbit;
00154 #endif
00155 this->setstate(__err);
00156 }
00157 catch(exception& __fail)
00158 {
00159
00160
00161 this->setstate(ios_base::badbit);
00162 if ((this->exceptions() & ios_base::badbit) != 0)
00163 __throw_exception_again;
00164 }
00165 }
00166 return *this;
00167 }
00168
00169 template<typename _CharT, typename _Traits>
00170 basic_istream<_CharT, _Traits>&
00171 basic_istream<_CharT, _Traits>::
00172 operator>>(unsigned short& __n)
00173 {
00174 sentry __cerb(*this, false);
00175 if (__cerb)
00176 {
00177 try
00178 {
00179 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00180 if (_M_check_facet(_M_fnumget))
00181 _M_fnumget->get(*this, 0, *this, __err, __n);
00182 this->setstate(__err);
00183 }
00184 catch(exception& __fail)
00185 {
00186
00187
00188 this->setstate(ios_base::badbit);
00189 if ((this->exceptions() & ios_base::badbit) != 0)
00190 __throw_exception_again;
00191 }
00192 }
00193 return *this;
00194 }
00195
00196 template<typename _CharT, typename _Traits>
00197 basic_istream<_CharT, _Traits>&
00198 basic_istream<_CharT, _Traits>::
00199 operator>>(int& __n)
00200 {
00201 sentry __cerb(*this, false);
00202 if (__cerb)
00203 {
00204 try
00205 {
00206 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00207 long __l;
00208 if (_M_check_facet(_M_fnumget))
00209 _M_fnumget->get(*this, 0, *this, __err, __l);
00210 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00211
00212 if (!(__err & ios_base::failbit)
00213 && (numeric_limits<int>::min() <= __l
00214 && __l <= numeric_limits<int>::max()))
00215 __n = __l;
00216 else
00217 __err |= ios_base::failbit;
00218 #endif
00219 this->setstate(__err);
00220 }
00221 catch(exception& __fail)
00222 {
00223
00224
00225 this->setstate(ios_base::badbit);
00226 if ((this->exceptions() & ios_base::badbit) != 0)
00227 __throw_exception_again;
00228 }
00229 }
00230 return *this;
00231 }
00232
00233 template<typename _CharT, typename _Traits>
00234 basic_istream<_CharT, _Traits>&
00235 basic_istream<_CharT, _Traits>::
00236 operator>>(unsigned int& __n)
00237 {
00238 sentry __cerb(*this, false);
00239 if (__cerb)
00240 {
00241 try
00242 {
00243 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00244 if (_M_check_facet(_M_fnumget))
00245 _M_fnumget->get(*this, 0, *this, __err, __n);
00246 this->setstate(__err);
00247 }
00248 catch(exception& __fail)
00249 {
00250
00251
00252 this->setstate(ios_base::badbit);
00253 if ((this->exceptions() & ios_base::badbit) != 0)
00254 __throw_exception_again;
00255 }
00256 }
00257 return *this;
00258 }
00259
00260 template<typename _CharT, typename _Traits>
00261 basic_istream<_CharT, _Traits>&
00262 basic_istream<_CharT, _Traits>::
00263 operator>>(long& __n)
00264 {
00265 sentry __cerb(*this, false);
00266 if (__cerb)
00267 {
00268 try
00269 {
00270 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00271 if (_M_check_facet(_M_fnumget))
00272 _M_fnumget->get(*this, 0, *this, __err, __n);
00273 this->setstate(__err);
00274 }
00275 catch(exception& __fail)
00276 {
00277
00278
00279 this->setstate(ios_base::badbit);
00280 if ((this->exceptions() & ios_base::badbit) != 0)
00281 __throw_exception_again;
00282 }
00283 }
00284 return *this;
00285 }
00286
00287 template<typename _CharT, typename _Traits>
00288 basic_istream<_CharT, _Traits>&
00289 basic_istream<_CharT, _Traits>::
00290 operator>>(unsigned long& __n)
00291 {
00292 sentry __cerb(*this, false);
00293 if (__cerb)
00294 {
00295 try
00296 {
00297 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00298 if (_M_check_facet(_M_fnumget))
00299 _M_fnumget->get(*this, 0, *this, __err, __n);
00300 this->setstate(__err);
00301 }
00302 catch(exception& __fail)
00303 {
00304
00305
00306 this->setstate(ios_base::badbit);
00307 if ((this->exceptions() & ios_base::badbit) != 0)
00308 __throw_exception_again;
00309 }
00310 }
00311 return *this;
00312 }
00313
00314 #ifdef _GLIBCPP_USE_LONG_LONG
00315 template<typename _CharT, typename _Traits>
00316 basic_istream<_CharT, _Traits>&
00317 basic_istream<_CharT, _Traits>::
00318 operator>>(long long& __n)
00319 {
00320 sentry __cerb(*this, false);
00321 if (__cerb)
00322 {
00323 try
00324 {
00325 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00326 if (_M_check_facet(_M_fnumget))
00327 _M_fnumget->get(*this, 0, *this, __err, __n);
00328 this->setstate(__err);
00329 }
00330 catch(exception& __fail)
00331 {
00332
00333
00334 this->setstate(ios_base::badbit);
00335 if ((this->exceptions() & ios_base::badbit) != 0)
00336 __throw_exception_again;
00337 }
00338 }
00339 return *this;
00340 }
00341
00342 template<typename _CharT, typename _Traits>
00343 basic_istream<_CharT, _Traits>&
00344 basic_istream<_CharT, _Traits>::
00345 operator>>(unsigned long long& __n)
00346 {
00347 sentry __cerb(*this, false);
00348 if (__cerb)
00349 {
00350 try
00351 {
00352 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00353 if (_M_check_facet(_M_fnumget))
00354 _M_fnumget->get(*this, 0, *this, __err, __n);
00355 this->setstate(__err);
00356 }
00357 catch(exception& __fail)
00358 {
00359
00360
00361 this->setstate(ios_base::badbit);
00362 if ((this->exceptions() & ios_base::badbit) != 0)
00363 __throw_exception_again;
00364 }
00365 }
00366 return *this;
00367 }
00368 #endif
00369
00370 template<typename _CharT, typename _Traits>
00371 basic_istream<_CharT, _Traits>&
00372 basic_istream<_CharT, _Traits>::
00373 operator>>(float& __n)
00374 {
00375 sentry __cerb(*this, false);
00376 if (__cerb)
00377 {
00378 try
00379 {
00380 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00381 if (_M_check_facet(_M_fnumget))
00382 _M_fnumget->get(*this, 0, *this, __err, __n);
00383 this->setstate(__err);
00384 }
00385 catch(exception& __fail)
00386 {
00387
00388
00389 this->setstate(ios_base::badbit);
00390 if ((this->exceptions() & ios_base::badbit) != 0)
00391 __throw_exception_again;
00392 }
00393 }
00394 return *this;
00395 }
00396
00397 template<typename _CharT, typename _Traits>
00398 basic_istream<_CharT, _Traits>&
00399 basic_istream<_CharT, _Traits>::
00400 operator>>(double& __n)
00401 {
00402 sentry __cerb(*this, false);
00403 if (__cerb)
00404 {
00405 try
00406 {
00407 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00408 if (_M_check_facet(_M_fnumget))
00409 _M_fnumget->get(*this, 0, *this, __err, __n);
00410 this->setstate(__err);
00411 }
00412 catch(exception& __fail)
00413 {
00414
00415
00416 this->setstate(ios_base::badbit);
00417 if ((this->exceptions() & ios_base::badbit) != 0)
00418 __throw_exception_again;
00419 }
00420 }
00421 return *this;
00422 }
00423
00424 template<typename _CharT, typename _Traits>
00425 basic_istream<_CharT, _Traits>&
00426 basic_istream<_CharT, _Traits>::
00427 operator>>(long double& __n)
00428 {
00429 sentry __cerb(*this, false);
00430 if (__cerb)
00431 {
00432 try
00433 {
00434 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00435 if (_M_check_facet(_M_fnumget))
00436 _M_fnumget->get(*this, 0, *this, __err, __n);
00437 this->setstate(__err);
00438 }
00439 catch(exception& __fail)
00440 {
00441
00442
00443 this->setstate(ios_base::badbit);
00444 if ((this->exceptions() & ios_base::badbit) != 0)
00445 __throw_exception_again;
00446 }
00447 }
00448 return *this;
00449 }
00450
00451 template<typename _CharT, typename _Traits>
00452 basic_istream<_CharT, _Traits>&
00453 basic_istream<_CharT, _Traits>::
00454 operator>>(void*& __n)
00455 {
00456 sentry __cerb(*this, false);
00457 if (__cerb)
00458 {
00459 try
00460 {
00461 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00462 if (_M_check_facet(_M_fnumget))
00463 _M_fnumget->get(*this, 0, *this, __err, __n);
00464 this->setstate(__err);
00465 }
00466 catch(exception& __fail)
00467 {
00468
00469
00470 this->setstate(ios_base::badbit);
00471 if ((this->exceptions() & ios_base::badbit) != 0)
00472 __throw_exception_again;
00473 }
00474 }
00475 return *this;
00476 }
00477
00478 template<typename _CharT, typename _Traits>
00479 basic_istream<_CharT, _Traits>&
00480 basic_istream<_CharT, _Traits>::
00481 operator>>(__streambuf_type* __sbout)
00482 {
00483 sentry __cerb(*this, false);
00484 if (__cerb)
00485 {
00486 try
00487 {
00488 streamsize __xtrct = 0;
00489 if (__sbout)
00490 {
00491 __streambuf_type* __sbin = this->rdbuf();
00492 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
00493 }
00494 if (!__sbout || !__xtrct)
00495 this->setstate(ios_base::failbit);
00496 }
00497 catch(exception& __fail)
00498 {
00499
00500
00501 this->setstate(ios_base::badbit);
00502 if ((this->exceptions() & ios_base::badbit) != 0)
00503 __throw_exception_again;
00504 }
00505 }
00506 return *this;
00507 }
00508
00509 template<typename _CharT, typename _Traits>
00510 typename basic_istream<_CharT, _Traits>::int_type
00511 basic_istream<_CharT, _Traits>::
00512 get(void)
00513 {
00514 const int_type __eof = traits_type::eof();
00515 int_type __c = __eof;
00516 _M_gcount = 0;
00517 sentry __cerb(*this, true);
00518 if (__cerb)
00519 {
00520 try
00521 {
00522 __c = this->rdbuf()->sbumpc();
00523
00524 if (__c != __eof)
00525 _M_gcount = 1;
00526 else
00527 this->setstate(ios_base::eofbit | ios_base::failbit);
00528 }
00529 catch(exception& __fail)
00530 {
00531
00532
00533 this->setstate(ios_base::badbit);
00534 if ((this->exceptions() & ios_base::badbit) != 0)
00535 __throw_exception_again;
00536 }
00537 }
00538 return __c;
00539 }
00540
00541 template<typename _CharT, typename _Traits>
00542 basic_istream<_CharT, _Traits>&
00543 basic_istream<_CharT, _Traits>::
00544 get(char_type& __c)
00545 {
00546 _M_gcount = 0;
00547 sentry __cerb(*this, true);
00548 if (__cerb)
00549 {
00550 try
00551 {
00552 const int_type __eof = traits_type::eof();
00553 int_type __bufval = this->rdbuf()->sbumpc();
00554
00555 if (__bufval != __eof)
00556 {
00557 _M_gcount = 1;
00558 __c = traits_type::to_char_type(__bufval);
00559 }
00560 else
00561 this->setstate(ios_base::eofbit | ios_base::failbit);
00562 }
00563 catch(exception& __fail)
00564 {
00565
00566
00567 this->setstate(ios_base::badbit);
00568 if ((this->exceptions() & ios_base::badbit) != 0)
00569 __throw_exception_again;
00570 }
00571 }
00572 return *this;
00573 }
00574
00575 template<typename _CharT, typename _Traits>
00576 basic_istream<_CharT, _Traits>&
00577 basic_istream<_CharT, _Traits>::
00578 get(char_type* __s, streamsize __n, char_type __delim)
00579 {
00580 _M_gcount = 0;
00581 sentry __cerb(*this, true);
00582 if (__cerb)
00583 {
00584 try
00585 {
00586 const int_type __idelim = traits_type::to_int_type(__delim);
00587 const int_type __eof = traits_type::eof();
00588 __streambuf_type* __sb = this->rdbuf();
00589 int_type __c = __sb->sgetc();
00590
00591 while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim)
00592 {
00593 *__s++ = traits_type::to_char_type(__c);
00594 __c = __sb->snextc();
00595 ++_M_gcount;
00596 }
00597 if (__c == __eof)
00598 this->setstate(ios_base::eofbit);
00599 }
00600 catch(exception& __fail)
00601 {
00602
00603
00604 this->setstate(ios_base::badbit);
00605 if ((this->exceptions() & ios_base::badbit) != 0)
00606 __throw_exception_again;
00607 }
00608 }
00609 *__s = char_type();
00610 if (!_M_gcount)
00611 this->setstate(ios_base::failbit);
00612 return *this;
00613 }
00614
00615 template<typename _CharT, typename _Traits>
00616 basic_istream<_CharT, _Traits>&
00617 basic_istream<_CharT, _Traits>::
00618 get(__streambuf_type& __sb, char_type __delim)
00619 {
00620 _M_gcount = 0;
00621 sentry __cerb(*this, true);
00622 if (__cerb)
00623 {
00624 try
00625 {
00626 const int_type __idelim = traits_type::to_int_type(__delim);
00627 const int_type __eof = traits_type::eof();
00628 __streambuf_type* __this_sb = this->rdbuf();
00629 int_type __c = __this_sb->sgetc();
00630
00631 while (__c != __eof && __c != __idelim
00632 && (__sb.sputc(traits_type::to_char_type(__c)) != __eof))
00633 {
00634 ++_M_gcount;
00635 __c = __this_sb->snextc();
00636 }
00637 if (__c == __eof)
00638 this->setstate(ios_base::eofbit);
00639 }
00640 catch(exception& __fail)
00641 {
00642
00643
00644 this->setstate(ios_base::badbit);
00645 if ((this->exceptions() & ios_base::badbit) != 0)
00646 __throw_exception_again;
00647 }
00648 }
00649 if (!_M_gcount)
00650 this->setstate(ios_base::failbit);
00651 return *this;
00652 }
00653
00654 template<typename _CharT, typename _Traits>
00655 basic_istream<_CharT, _Traits>&
00656 basic_istream<_CharT, _Traits>::
00657 getline(char_type* __s, streamsize __n, char_type __delim)
00658 {
00659 _M_gcount = 0;
00660 sentry __cerb(*this, true);
00661 if (__cerb)
00662 {
00663 try
00664 {
00665 const int_type __idelim = traits_type::to_int_type(__delim);
00666 const int_type __eof = traits_type::eof();
00667 __streambuf_type* __sb = this->rdbuf();
00668 int_type __c = __sb->sgetc();
00669
00670 while (_M_gcount + 1 < __n && __c != __eof && __c != __idelim)
00671 {
00672 *__s++ = traits_type::to_char_type(__c);
00673 __c = __sb->snextc();
00674 ++_M_gcount;
00675 }
00676 if (__c == __eof)
00677 this->setstate(ios_base::eofbit);
00678 else
00679 {
00680 if (__c == __idelim)
00681 {
00682 __sb->snextc();
00683 ++_M_gcount;
00684 }
00685 else
00686 this->setstate(ios_base::failbit);
00687 }
00688 }
00689 catch(exception& __fail)
00690 {
00691
00692
00693 this->setstate(ios_base::badbit);
00694 if ((this->exceptions() & ios_base::badbit) != 0)
00695 __throw_exception_again;
00696 }
00697 }
00698 *__s = char_type();
00699 if (!_M_gcount)
00700 this->setstate(ios_base::failbit);
00701 return *this;
00702 }
00703
00704 template<typename _CharT, typename _Traits>
00705 basic_istream<_CharT, _Traits>&
00706 basic_istream<_CharT, _Traits>::
00707 ignore(streamsize __n, int_type __delim)
00708 {
00709 _M_gcount = 0;
00710 sentry __cerb(*this, true);
00711 if (__cerb)
00712 {
00713 try
00714 {
00715 const int_type __eof = traits_type::eof();
00716 __streambuf_type* __sb = this->rdbuf();
00717 int_type __c = __sb->sgetc();
00718
00719 __n = min(__n, numeric_limits<streamsize>::max());
00720 while (_M_gcount < __n && __c !=__eof && __c != __delim)
00721 {
00722 __c = __sb->snextc();
00723 ++_M_gcount;
00724 }
00725 if (__c == __eof)
00726 this->setstate(ios_base::eofbit);
00727 else if (__c == __delim)
00728 {
00729 __sb->snextc();
00730 ++_M_gcount;
00731 }
00732 }
00733 catch(exception& __fail)
00734 {
00735
00736
00737 this->setstate(ios_base::badbit);
00738 if ((this->exceptions() & ios_base::badbit) != 0)
00739 __throw_exception_again;
00740 }
00741 }
00742 return *this;
00743 }
00744
00745 template<typename _CharT, typename _Traits>
00746 typename basic_istream<_CharT, _Traits>::int_type
00747 basic_istream<_CharT, _Traits>::
00748 peek(void)
00749 {
00750 int_type __c = traits_type::eof();
00751 _M_gcount = 0;
00752 sentry __cerb(*this, true);
00753 if (__cerb)
00754 {
00755 try
00756 { __c = this->rdbuf()->sgetc(); }
00757 catch(exception& __fail)
00758 {
00759
00760
00761 this->setstate(ios_base::badbit);
00762 if ((this->exceptions() & ios_base::badbit) != 0)
00763 __throw_exception_again;
00764 }
00765 }
00766 return __c;
00767 }
00768
00769 template<typename _CharT, typename _Traits>
00770 basic_istream<_CharT, _Traits>&
00771 basic_istream<_CharT, _Traits>::
00772 read(char_type* __s, streamsize __n)
00773 {
00774 _M_gcount = 0;
00775 sentry __cerb(*this, true);
00776 if (__cerb)
00777 {
00778 try
00779 {
00780 _M_gcount = this->rdbuf()->sgetn(__s, __n);
00781 if (_M_gcount != __n)
00782 this->setstate(ios_base::eofbit | ios_base::failbit);
00783 }
00784 catch(exception& __fail)
00785 {
00786
00787
00788 this->setstate(ios_base::badbit);
00789 if ((this->exceptions() & ios_base::badbit) != 0)
00790 __throw_exception_again;
00791 }
00792 }
00793 else
00794 this->setstate(ios_base::failbit);
00795 return *this;
00796 }
00797
00798 template<typename _CharT, typename _Traits>
00799 streamsize
00800 basic_istream<_CharT, _Traits>::
00801 readsome(char_type* __s, streamsize __n)
00802 {
00803 _M_gcount = 0;
00804 sentry __cerb(*this, true);
00805 if (__cerb)
00806 {
00807 try
00808 {
00809 const int_type __eof = traits_type::eof();
00810 streamsize __num = this->rdbuf()->in_avail();
00811 if (__num != static_cast<streamsize>(__eof))
00812 {
00813 __num = min(__num, __n);
00814 if (__num)
00815 _M_gcount = this->rdbuf()->sgetn(__s, __num);
00816 }
00817 else
00818 this->setstate(ios_base::eofbit);
00819 }
00820 catch(exception& __fail)
00821 {
00822
00823
00824 this->setstate(ios_base::badbit);
00825 if ((this->exceptions() & ios_base::badbit) != 0)
00826 __throw_exception_again;
00827 }
00828 }
00829 else
00830 this->setstate(ios_base::failbit);
00831 return _M_gcount;
00832 }
00833
00834 template<typename _CharT, typename _Traits>
00835 basic_istream<_CharT, _Traits>&
00836 basic_istream<_CharT, _Traits>::
00837 putback(char_type __c)
00838 {
00839 sentry __cerb(*this, true);
00840 if (__cerb)
00841 {
00842 try
00843 {
00844 const int_type __eof = traits_type::eof();
00845 __streambuf_type* __sb = this->rdbuf();
00846 if (!__sb || __sb->sputbackc(__c) == __eof)
00847 this->setstate(ios_base::badbit);
00848 }
00849 catch(exception& __fail)
00850 {
00851
00852
00853 this->setstate(ios_base::badbit);
00854 if ((this->exceptions() & ios_base::badbit) != 0)
00855 __throw_exception_again;
00856 }
00857 }
00858 else
00859 this->setstate(ios_base::failbit);
00860 return *this;
00861 }
00862
00863 template<typename _CharT, typename _Traits>
00864 basic_istream<_CharT, _Traits>&
00865 basic_istream<_CharT, _Traits>::
00866 unget(void)
00867 {
00868 _M_gcount = 0;
00869 sentry __cerb(*this, true);
00870 if (__cerb)
00871 {
00872 try
00873 {
00874 const int_type __eof = traits_type::eof();
00875 __streambuf_type* __sb = this->rdbuf();
00876 if (!__sb || __eof == __sb->sungetc())
00877 this->setstate(ios_base::badbit);
00878 }
00879 catch(exception& __fail)
00880 {
00881
00882
00883 this->setstate(ios_base::badbit);
00884 if ((this->exceptions() & ios_base::badbit) != 0)
00885 __throw_exception_again;
00886 }
00887 }
00888 else
00889 this->setstate(ios_base::failbit);
00890 return *this;
00891 }
00892
00893 template<typename _CharT, typename _Traits>
00894 int
00895 basic_istream<_CharT, _Traits>::
00896 sync(void)
00897 {
00898 int __ret = traits_type::eof();
00899 _M_gcount = 0;
00900 sentry __cerb(*this, true);
00901 if (__cerb)
00902 {
00903 try
00904 {
00905 __streambuf_type* __sb = this->rdbuf();
00906 if (!__sb || __ret == __sb->pubsync())
00907 this->setstate(ios_base::badbit);
00908 else
00909 __ret = 0;
00910 }
00911 catch(exception& __fail)
00912 {
00913
00914
00915 this->setstate(ios_base::badbit);
00916 if ((this->exceptions() & ios_base::badbit) != 0)
00917 __throw_exception_again;
00918 }
00919 }
00920 return __ret;
00921 }
00922
00923 template<typename _CharT, typename _Traits>
00924 typename basic_istream<_CharT, _Traits>::pos_type
00925 basic_istream<_CharT, _Traits>::
00926 tellg(void)
00927 {
00928 pos_type __ret = pos_type(-1);
00929 _M_gcount = 0;
00930 sentry __cerb(*this, true);
00931 if (__cerb)
00932 {
00933 try
00934 {
00935 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
00936 }
00937 catch(exception& __fail)
00938 {
00939
00940
00941 this->setstate(ios_base::badbit);
00942 if ((this->exceptions() & ios_base::badbit) != 0)
00943 __throw_exception_again;
00944 }
00945 }
00946 return __ret;
00947 }
00948
00949
00950 template<typename _CharT, typename _Traits>
00951 basic_istream<_CharT, _Traits>&
00952 basic_istream<_CharT, _Traits>::
00953 seekg(pos_type __pos)
00954 {
00955 _M_gcount = 0;
00956 sentry __cerb(*this, true);
00957 if (__cerb)
00958 {
00959 try
00960 {
00961 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00962
00963 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::in);
00964
00965
00966 if (__err == pos_type(off_type(-1)))
00967 this->setstate(ios_base::failbit);
00968 #endif
00969 }
00970 catch(exception& __fail)
00971 {
00972
00973
00974 this->setstate(ios_base::badbit);
00975 if ((this->exceptions() & ios_base::badbit) != 0)
00976 __throw_exception_again;
00977 }
00978 }
00979 return *this;
00980 }
00981
00982 template<typename _CharT, typename _Traits>
00983 basic_istream<_CharT, _Traits>&
00984 basic_istream<_CharT, _Traits>::
00985 seekg(off_type __off, ios_base::seekdir __dir)
00986 {
00987 _M_gcount = 0;
00988 sentry __cerb(*this, true);
00989 if (__cerb)
00990 {
00991 try
00992 {
00993 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00994
00995 pos_type __err = this->rdbuf()->pubseekoff(__off, __dir,
00996 ios_base::in);
00997
00998
00999 if (__err == pos_type(off_type(-1)))
01000 this->setstate(ios_base::failbit);
01001 #endif
01002 }
01003 catch(exception& __fail)
01004 {
01005
01006
01007 this->setstate(ios_base::badbit);
01008 if ((this->exceptions() & ios_base::badbit) != 0)
01009 __throw_exception_again;
01010 }
01011 }
01012 return *this;
01013 }
01014
01015
01016 template<typename _CharT, typename _Traits>
01017 basic_istream<_CharT, _Traits>&
01018 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
01019 {
01020 typedef basic_istream<_CharT, _Traits> __istream_type;
01021 typename __istream_type::sentry __cerb(__in, false);
01022 if (__cerb)
01023 {
01024 try
01025 { __in.get(__c); }
01026 catch(exception& __fail)
01027 {
01028
01029
01030 __in.setstate(ios_base::badbit);
01031 if ((__in.exceptions() & ios_base::badbit) != 0)
01032 __throw_exception_again;
01033 }
01034 }
01035 else
01036 __in.setstate(ios_base::failbit);
01037 return __in;
01038 }
01039
01040 template<typename _CharT, typename _Traits>
01041 basic_istream<_CharT, _Traits>&
01042 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
01043 {
01044 typedef basic_istream<_CharT, _Traits> __istream_type;
01045 typedef typename __istream_type::__streambuf_type __streambuf_type;
01046 typedef typename _Traits::int_type int_type;
01047 typedef _CharT char_type;
01048 typedef ctype<_CharT> __ctype_type;
01049 streamsize __extracted = 0;
01050
01051 typename __istream_type::sentry __cerb(__in, false);
01052 if (__cerb)
01053 {
01054 try
01055 {
01056
01057 streamsize __num = __in.width();
01058 if (__num == 0)
01059 __num = numeric_limits<streamsize>::max();
01060
01061 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
01062 const int_type __eof = _Traits::eof();
01063 __streambuf_type* __sb = __in.rdbuf();
01064 int_type __c = __sb->sgetc();
01065
01066 while (__extracted < __num - 1
01067 && __c != __eof && !__ctype.is(ctype_base::space, __c))
01068 {
01069 *__s++ = __c;
01070 ++__extracted;
01071 __c = __sb->snextc();
01072 }
01073 if (__c == __eof)
01074 __in.setstate(ios_base::eofbit);
01075
01076 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
01077
01078 *__s = char_type();
01079 #endif
01080 __in.width(0);
01081 }
01082 catch(exception& __fail)
01083 {
01084
01085
01086 __in.setstate(ios_base::badbit);
01087 if ((__in.exceptions() & ios_base::badbit) != 0)
01088 __throw_exception_again;
01089 }
01090 }
01091 if (!__extracted)
01092 __in.setstate(ios_base::failbit);
01093 return __in;
01094 }
01095
01096
01097 template<typename _CharT, typename _Traits>
01098 basic_istream<_CharT,_Traits>&
01099 ws(basic_istream<_CharT,_Traits>& __in)
01100 {
01101 typedef basic_istream<_CharT, _Traits> __istream_type;
01102 typedef typename __istream_type::__streambuf_type __streambuf_type;
01103 typedef typename __istream_type::__ctype_type __ctype_type;
01104 typedef typename __istream_type::int_type __int_type;
01105
01106 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
01107 const __int_type __eof = _Traits::eof();
01108 __streambuf_type* __sb = __in.rdbuf();
01109 __int_type __c = __sb->sgetc();
01110
01111 while (__c != __eof && __ctype.is(ctype_base::space, __c))
01112 __c = __sb->snextc();
01113 if (__c == __eof)
01114 __in.setstate(ios_base::eofbit);
01115
01116 return __in;
01117 }
01118
01119
01120 template<typename _CharT, typename _Traits, typename _Alloc>
01121 basic_istream<_CharT, _Traits>&
01122 operator>>(basic_istream<_CharT, _Traits>& __in,
01123 basic_string<_CharT, _Traits, _Alloc>& __str)
01124 {
01125 typedef basic_istream<_CharT, _Traits> __istream_type;
01126 typedef typename __istream_type::int_type __int_type;
01127 typedef typename __istream_type::__streambuf_type __streambuf_type;
01128 typedef typename __istream_type::__ctype_type __ctype_type;
01129 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
01130 typedef typename __string_type::size_type __size_type;
01131 __size_type __extracted = 0;
01132
01133 typename __istream_type::sentry __cerb(__in, false);
01134 if (__cerb)
01135 {
01136 __str.erase();
01137 streamsize __w = __in.width();
01138 __size_type __n;
01139 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
01140
01141 const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
01142 const __int_type __eof = _Traits::eof();
01143 __streambuf_type* __sb = __in.rdbuf();
01144 __int_type __c = __sb->sgetc();
01145
01146 while (__extracted < __n
01147 && __c != __eof && !__ctype.is(ctype_base::space, __c))
01148 {
01149 __str += _Traits::to_char_type(__c);
01150 ++__extracted;
01151 __c = __sb->snextc();
01152 }
01153 if (__c == __eof)
01154 __in.setstate(ios_base::eofbit);
01155 __in.width(0);
01156 }
01157 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
01158
01159 if (!__extracted)
01160 __in.setstate (ios_base::failbit);
01161 #endif
01162 return __in;
01163 }
01164
01165 template<typename _CharT, typename _Traits, typename _Alloc>
01166 basic_istream<_CharT, _Traits>&
01167 getline(basic_istream<_CharT, _Traits>& __in,
01168 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
01169 {
01170 typedef basic_istream<_CharT, _Traits> __istream_type;
01171 typedef typename __istream_type::int_type __int_type;
01172 typedef typename __istream_type::__streambuf_type __streambuf_type;
01173 typedef typename __istream_type::__ctype_type __ctype_type;
01174 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
01175 typedef typename __string_type::size_type __size_type;
01176
01177 __size_type __extracted = 0;
01178 bool __testdelim = false;
01179 typename __istream_type::sentry __cerb(__in, true);
01180 if (__cerb)
01181 {
01182 __str.erase();
01183 __size_type __n = __str.max_size();
01184
01185 __int_type __idelim = _Traits::to_int_type(__delim);
01186 __streambuf_type* __sb = __in.rdbuf();
01187 __int_type __c = __sb->sbumpc();
01188 const __int_type __eof = _Traits::eof();
01189 __testdelim = __c == __idelim;
01190
01191 while (__extracted <= __n && __c != __eof && !__testdelim)
01192 {
01193 __str += _Traits::to_char_type(__c);
01194 ++__extracted;
01195 __c = __sb->sbumpc();
01196 __testdelim = __c == __idelim;
01197 }
01198 if (__c == __eof)
01199 __in.setstate(ios_base::eofbit);
01200 }
01201 if (!__extracted && !__testdelim)
01202 __in.setstate(ios_base::failbit);
01203 return __in;
01204 }
01205
01206 template<class _CharT, class _Traits, class _Alloc>
01207 inline basic_istream<_CharT,_Traits>&
01208 getline(basic_istream<_CharT, _Traits>& __in,
01209 basic_string<_CharT,_Traits,_Alloc>& __str)
01210 { return getline(__in, __str, __in.widen('\n')); }
01211
01212
01213
01214
01215 extern template class basic_istream<char>;
01216 extern template istream& ws(istream&);
01217 extern template istream& operator>>(istream&, char&);
01218 extern template istream& operator>>(istream&, char*);
01219 extern template istream& operator>>(istream&, unsigned char&);
01220 extern template istream& operator>>(istream&, signed char&);
01221 extern template istream& operator>>(istream&, unsigned char*);
01222 extern template istream& operator>>(istream&, signed char*);
01223
01224 extern template class basic_istream<wchar_t>;
01225 extern template wistream& ws(wistream&);
01226 extern template wistream& operator>>(wistream&, wchar_t&);
01227 extern template wistream& operator>>(wistream&, wchar_t*);
01228 }