libstdc++
|
00001 // istream classes -*- C++ -*- 00002 00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 00004 // 2006, 2007, 2008, 2009, 2010, 2011 00005 // Free Software Foundation, Inc. 00006 // 00007 // This file is part of the GNU ISO C++ Library. This library is free 00008 // software; you can redistribute it and/or modify it under the 00009 // terms of the GNU General Public License as published by the 00010 // Free Software Foundation; either version 3, or (at your option) 00011 // any later version. 00012 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 00018 // Under Section 7 of GPL version 3, you are granted additional 00019 // permissions described in the GCC Runtime Library Exception, version 00020 // 3.1, as published by the Free Software Foundation. 00021 00022 // You should have received a copy of the GNU General Public License and 00023 // a copy of the GCC Runtime Library Exception along with this program; 00024 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00025 // <http://www.gnu.org/licenses/>. 00026 00027 /** @file bits/istream.tcc 00028 * This is an internal header file, included by other library headers. 00029 * Do not attempt to use it directly. @headername{istream} 00030 */ 00031 00032 // 00033 // ISO C++ 14882: 27.6.1 Input streams 00034 // 00035 00036 #ifndef _ISTREAM_TCC 00037 #define _ISTREAM_TCC 1 00038 00039 #pragma GCC system_header 00040 00041 #include <bits/cxxabi_forced.h> 00042 00043 namespace std _GLIBCXX_VISIBILITY(default) 00044 { 00045 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00046 00047 template<typename _CharT, typename _Traits> 00048 basic_istream<_CharT, _Traits>::sentry:: 00049 sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false) 00050 { 00051 ios_base::iostate __err = ios_base::goodbit; 00052 if (__in.good()) 00053 { 00054 if (__in.tie()) 00055 __in.tie()->flush(); 00056 if (!__noskip && bool(__in.flags() & ios_base::skipws)) 00057 { 00058 const __int_type __eof = traits_type::eof(); 00059 __streambuf_type* __sb = __in.rdbuf(); 00060 __int_type __c = __sb->sgetc(); 00061 00062 const __ctype_type& __ct = __check_facet(__in._M_ctype); 00063 while (!traits_type::eq_int_type(__c, __eof) 00064 && __ct.is(ctype_base::space, 00065 traits_type::to_char_type(__c))) 00066 __c = __sb->snextc(); 00067 00068 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00069 // 195. Should basic_istream::sentry's constructor ever 00070 // set eofbit? 00071 if (traits_type::eq_int_type(__c, __eof)) 00072 __err |= ios_base::eofbit; 00073 } 00074 } 00075 00076 if (__in.good() && __err == ios_base::goodbit) 00077 _M_ok = true; 00078 else 00079 { 00080 __err |= ios_base::failbit; 00081 __in.setstate(__err); 00082 } 00083 } 00084 00085 template<typename _CharT, typename _Traits> 00086 template<typename _ValueT> 00087 basic_istream<_CharT, _Traits>& 00088 basic_istream<_CharT, _Traits>:: 00089 _M_extract(_ValueT& __v) 00090 { 00091 sentry __cerb(*this, false); 00092 if (__cerb) 00093 { 00094 ios_base::iostate __err = ios_base::goodbit; 00095 __try 00096 { 00097 const __num_get_type& __ng = __check_facet(this->_M_num_get); 00098 __ng.get(*this, 0, *this, __err, __v); 00099 } 00100 __catch(__cxxabiv1::__forced_unwind&) 00101 { 00102 this->_M_setstate(ios_base::badbit); 00103 __throw_exception_again; 00104 } 00105 __catch(...) 00106 { this->_M_setstate(ios_base::badbit); } 00107 if (__err) 00108 this->setstate(__err); 00109 } 00110 return *this; 00111 } 00112 00113 template<typename _CharT, typename _Traits> 00114 basic_istream<_CharT, _Traits>& 00115 basic_istream<_CharT, _Traits>:: 00116 operator>>(short& __n) 00117 { 00118 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00119 // 118. basic_istream uses nonexistent num_get member functions. 00120 sentry __cerb(*this, false); 00121 if (__cerb) 00122 { 00123 ios_base::iostate __err = ios_base::goodbit; 00124 __try 00125 { 00126 long __l; 00127 const __num_get_type& __ng = __check_facet(this->_M_num_get); 00128 __ng.get(*this, 0, *this, __err, __l); 00129 00130 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00131 // 696. istream::operator>>(int&) broken. 00132 if (__l < __gnu_cxx::__numeric_traits<short>::__min) 00133 { 00134 __err |= ios_base::failbit; 00135 __n = __gnu_cxx::__numeric_traits<short>::__min; 00136 } 00137 else if (__l > __gnu_cxx::__numeric_traits<short>::__max) 00138 { 00139 __err |= ios_base::failbit; 00140 __n = __gnu_cxx::__numeric_traits<short>::__max; 00141 } 00142 else 00143 __n = short(__l); 00144 } 00145 __catch(__cxxabiv1::__forced_unwind&) 00146 { 00147 this->_M_setstate(ios_base::badbit); 00148 __throw_exception_again; 00149 } 00150 __catch(...) 00151 { this->_M_setstate(ios_base::badbit); } 00152 if (__err) 00153 this->setstate(__err); 00154 } 00155 return *this; 00156 } 00157 00158 template<typename _CharT, typename _Traits> 00159 basic_istream<_CharT, _Traits>& 00160 basic_istream<_CharT, _Traits>:: 00161 operator>>(int& __n) 00162 { 00163 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00164 // 118. basic_istream uses nonexistent num_get member functions. 00165 sentry __cerb(*this, false); 00166 if (__cerb) 00167 { 00168 ios_base::iostate __err = ios_base::goodbit; 00169 __try 00170 { 00171 long __l; 00172 const __num_get_type& __ng = __check_facet(this->_M_num_get); 00173 __ng.get(*this, 0, *this, __err, __l); 00174 00175 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00176 // 696. istream::operator>>(int&) broken. 00177 if (__l < __gnu_cxx::__numeric_traits<int>::__min) 00178 { 00179 __err |= ios_base::failbit; 00180 __n = __gnu_cxx::__numeric_traits<int>::__min; 00181 } 00182 else if (__l > __gnu_cxx::__numeric_traits<int>::__max) 00183 { 00184 __err |= ios_base::failbit; 00185 __n = __gnu_cxx::__numeric_traits<int>::__max; 00186 } 00187 else 00188 __n = int(__l); 00189 } 00190 __catch(__cxxabiv1::__forced_unwind&) 00191 { 00192 this->_M_setstate(ios_base::badbit); 00193 __throw_exception_again; 00194 } 00195 __catch(...) 00196 { this->_M_setstate(ios_base::badbit); } 00197 if (__err) 00198 this->setstate(__err); 00199 } 00200 return *this; 00201 } 00202 00203 template<typename _CharT, typename _Traits> 00204 basic_istream<_CharT, _Traits>& 00205 basic_istream<_CharT, _Traits>:: 00206 operator>>(__streambuf_type* __sbout) 00207 { 00208 ios_base::iostate __err = ios_base::goodbit; 00209 sentry __cerb(*this, false); 00210 if (__cerb && __sbout) 00211 { 00212 __try 00213 { 00214 bool __ineof; 00215 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof)) 00216 __err |= ios_base::failbit; 00217 if (__ineof) 00218 __err |= ios_base::eofbit; 00219 } 00220 __catch(__cxxabiv1::__forced_unwind&) 00221 { 00222 this->_M_setstate(ios_base::failbit); 00223 __throw_exception_again; 00224 } 00225 __catch(...) 00226 { this->_M_setstate(ios_base::failbit); } 00227 } 00228 else if (!__sbout) 00229 __err |= ios_base::failbit; 00230 if (__err) 00231 this->setstate(__err); 00232 return *this; 00233 } 00234 00235 template<typename _CharT, typename _Traits> 00236 typename basic_istream<_CharT, _Traits>::int_type 00237 basic_istream<_CharT, _Traits>:: 00238 get(void) 00239 { 00240 const int_type __eof = traits_type::eof(); 00241 int_type __c = __eof; 00242 _M_gcount = 0; 00243 ios_base::iostate __err = ios_base::goodbit; 00244 sentry __cerb(*this, true); 00245 if (__cerb) 00246 { 00247 __try 00248 { 00249 __c = this->rdbuf()->sbumpc(); 00250 // 27.6.1.1 paragraph 3 00251 if (!traits_type::eq_int_type(__c, __eof)) 00252 _M_gcount = 1; 00253 else 00254 __err |= ios_base::eofbit; 00255 } 00256 __catch(__cxxabiv1::__forced_unwind&) 00257 { 00258 this->_M_setstate(ios_base::badbit); 00259 __throw_exception_again; 00260 } 00261 __catch(...) 00262 { this->_M_setstate(ios_base::badbit); } 00263 } 00264 if (!_M_gcount) 00265 __err |= ios_base::failbit; 00266 if (__err) 00267 this->setstate(__err); 00268 return __c; 00269 } 00270 00271 template<typename _CharT, typename _Traits> 00272 basic_istream<_CharT, _Traits>& 00273 basic_istream<_CharT, _Traits>:: 00274 get(char_type& __c) 00275 { 00276 _M_gcount = 0; 00277 ios_base::iostate __err = ios_base::goodbit; 00278 sentry __cerb(*this, true); 00279 if (__cerb) 00280 { 00281 __try 00282 { 00283 const int_type __cb = this->rdbuf()->sbumpc(); 00284 // 27.6.1.1 paragraph 3 00285 if (!traits_type::eq_int_type(__cb, traits_type::eof())) 00286 { 00287 _M_gcount = 1; 00288 __c = traits_type::to_char_type(__cb); 00289 } 00290 else 00291 __err |= ios_base::eofbit; 00292 } 00293 __catch(__cxxabiv1::__forced_unwind&) 00294 { 00295 this->_M_setstate(ios_base::badbit); 00296 __throw_exception_again; 00297 } 00298 __catch(...) 00299 { this->_M_setstate(ios_base::badbit); } 00300 } 00301 if (!_M_gcount) 00302 __err |= ios_base::failbit; 00303 if (__err) 00304 this->setstate(__err); 00305 return *this; 00306 } 00307 00308 template<typename _CharT, typename _Traits> 00309 basic_istream<_CharT, _Traits>& 00310 basic_istream<_CharT, _Traits>:: 00311 get(char_type* __s, streamsize __n, char_type __delim) 00312 { 00313 _M_gcount = 0; 00314 ios_base::iostate __err = ios_base::goodbit; 00315 sentry __cerb(*this, true); 00316 if (__cerb) 00317 { 00318 __try 00319 { 00320 const int_type __idelim = traits_type::to_int_type(__delim); 00321 const int_type __eof = traits_type::eof(); 00322 __streambuf_type* __sb = this->rdbuf(); 00323 int_type __c = __sb->sgetc(); 00324 00325 while (_M_gcount + 1 < __n 00326 && !traits_type::eq_int_type(__c, __eof) 00327 && !traits_type::eq_int_type(__c, __idelim)) 00328 { 00329 *__s++ = traits_type::to_char_type(__c); 00330 ++_M_gcount; 00331 __c = __sb->snextc(); 00332 } 00333 if (traits_type::eq_int_type(__c, __eof)) 00334 __err |= ios_base::eofbit; 00335 } 00336 __catch(__cxxabiv1::__forced_unwind&) 00337 { 00338 this->_M_setstate(ios_base::badbit); 00339 __throw_exception_again; 00340 } 00341 __catch(...) 00342 { this->_M_setstate(ios_base::badbit); } 00343 } 00344 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00345 // 243. get and getline when sentry reports failure. 00346 if (__n > 0) 00347 *__s = char_type(); 00348 if (!_M_gcount) 00349 __err |= ios_base::failbit; 00350 if (__err) 00351 this->setstate(__err); 00352 return *this; 00353 } 00354 00355 template<typename _CharT, typename _Traits> 00356 basic_istream<_CharT, _Traits>& 00357 basic_istream<_CharT, _Traits>:: 00358 get(__streambuf_type& __sb, char_type __delim) 00359 { 00360 _M_gcount = 0; 00361 ios_base::iostate __err = ios_base::goodbit; 00362 sentry __cerb(*this, true); 00363 if (__cerb) 00364 { 00365 __try 00366 { 00367 const int_type __idelim = traits_type::to_int_type(__delim); 00368 const int_type __eof = traits_type::eof(); 00369 __streambuf_type* __this_sb = this->rdbuf(); 00370 int_type __c = __this_sb->sgetc(); 00371 char_type __c2 = traits_type::to_char_type(__c); 00372 00373 while (!traits_type::eq_int_type(__c, __eof) 00374 && !traits_type::eq_int_type(__c, __idelim) 00375 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof)) 00376 { 00377 ++_M_gcount; 00378 __c = __this_sb->snextc(); 00379 __c2 = traits_type::to_char_type(__c); 00380 } 00381 if (traits_type::eq_int_type(__c, __eof)) 00382 __err |= ios_base::eofbit; 00383 } 00384 __catch(__cxxabiv1::__forced_unwind&) 00385 { 00386 this->_M_setstate(ios_base::badbit); 00387 __throw_exception_again; 00388 } 00389 __catch(...) 00390 { this->_M_setstate(ios_base::badbit); } 00391 } 00392 if (!_M_gcount) 00393 __err |= ios_base::failbit; 00394 if (__err) 00395 this->setstate(__err); 00396 return *this; 00397 } 00398 00399 template<typename _CharT, typename _Traits> 00400 basic_istream<_CharT, _Traits>& 00401 basic_istream<_CharT, _Traits>:: 00402 getline(char_type* __s, streamsize __n, char_type __delim) 00403 { 00404 _M_gcount = 0; 00405 ios_base::iostate __err = ios_base::goodbit; 00406 sentry __cerb(*this, true); 00407 if (__cerb) 00408 { 00409 __try 00410 { 00411 const int_type __idelim = traits_type::to_int_type(__delim); 00412 const int_type __eof = traits_type::eof(); 00413 __streambuf_type* __sb = this->rdbuf(); 00414 int_type __c = __sb->sgetc(); 00415 00416 while (_M_gcount + 1 < __n 00417 && !traits_type::eq_int_type(__c, __eof) 00418 && !traits_type::eq_int_type(__c, __idelim)) 00419 { 00420 *__s++ = traits_type::to_char_type(__c); 00421 __c = __sb->snextc(); 00422 ++_M_gcount; 00423 } 00424 if (traits_type::eq_int_type(__c, __eof)) 00425 __err |= ios_base::eofbit; 00426 else 00427 { 00428 if (traits_type::eq_int_type(__c, __idelim)) 00429 { 00430 __sb->sbumpc(); 00431 ++_M_gcount; 00432 } 00433 else 00434 __err |= ios_base::failbit; 00435 } 00436 } 00437 __catch(__cxxabiv1::__forced_unwind&) 00438 { 00439 this->_M_setstate(ios_base::badbit); 00440 __throw_exception_again; 00441 } 00442 __catch(...) 00443 { this->_M_setstate(ios_base::badbit); } 00444 } 00445 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00446 // 243. get and getline when sentry reports failure. 00447 if (__n > 0) 00448 *__s = char_type(); 00449 if (!_M_gcount) 00450 __err |= ios_base::failbit; 00451 if (__err) 00452 this->setstate(__err); 00453 return *this; 00454 } 00455 00456 // We provide three overloads, since the first two are much simpler 00457 // than the general case. Also, the latter two can thus adopt the 00458 // same "batchy" strategy used by getline above. 00459 template<typename _CharT, typename _Traits> 00460 basic_istream<_CharT, _Traits>& 00461 basic_istream<_CharT, _Traits>:: 00462 ignore(void) 00463 { 00464 _M_gcount = 0; 00465 sentry __cerb(*this, true); 00466 if (__cerb) 00467 { 00468 ios_base::iostate __err = ios_base::goodbit; 00469 __try 00470 { 00471 const int_type __eof = traits_type::eof(); 00472 __streambuf_type* __sb = this->rdbuf(); 00473 00474 if (traits_type::eq_int_type(__sb->sbumpc(), __eof)) 00475 __err |= ios_base::eofbit; 00476 else 00477 _M_gcount = 1; 00478 } 00479 __catch(__cxxabiv1::__forced_unwind&) 00480 { 00481 this->_M_setstate(ios_base::badbit); 00482 __throw_exception_again; 00483 } 00484 __catch(...) 00485 { this->_M_setstate(ios_base::badbit); } 00486 if (__err) 00487 this->setstate(__err); 00488 } 00489 return *this; 00490 } 00491 00492 template<typename _CharT, typename _Traits> 00493 basic_istream<_CharT, _Traits>& 00494 basic_istream<_CharT, _Traits>:: 00495 ignore(streamsize __n) 00496 { 00497 _M_gcount = 0; 00498 sentry __cerb(*this, true); 00499 if (__cerb && __n > 0) 00500 { 00501 ios_base::iostate __err = ios_base::goodbit; 00502 __try 00503 { 00504 const int_type __eof = traits_type::eof(); 00505 __streambuf_type* __sb = this->rdbuf(); 00506 int_type __c = __sb->sgetc(); 00507 00508 // N.B. On LFS-enabled platforms streamsize is still 32 bits 00509 // wide: if we want to implement the standard mandated behavior 00510 // for n == max() (see 27.6.1.3/24) we are at risk of signed 00511 // integer overflow: thus these contortions. Also note that, 00512 // by definition, when more than 2G chars are actually ignored, 00513 // _M_gcount (the return value of gcount, that is) cannot be 00514 // really correct, being unavoidably too small. 00515 bool __large_ignore = false; 00516 while (true) 00517 { 00518 while (_M_gcount < __n 00519 && !traits_type::eq_int_type(__c, __eof)) 00520 { 00521 ++_M_gcount; 00522 __c = __sb->snextc(); 00523 } 00524 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max 00525 && !traits_type::eq_int_type(__c, __eof)) 00526 { 00527 _M_gcount = 00528 __gnu_cxx::__numeric_traits<streamsize>::__min; 00529 __large_ignore = true; 00530 } 00531 else 00532 break; 00533 } 00534 00535 if (__large_ignore) 00536 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max; 00537 00538 if (traits_type::eq_int_type(__c, __eof)) 00539 __err |= ios_base::eofbit; 00540 } 00541 __catch(__cxxabiv1::__forced_unwind&) 00542 { 00543 this->_M_setstate(ios_base::badbit); 00544 __throw_exception_again; 00545 } 00546 __catch(...) 00547 { this->_M_setstate(ios_base::badbit); } 00548 if (__err) 00549 this->setstate(__err); 00550 } 00551 return *this; 00552 } 00553 00554 template<typename _CharT, typename _Traits> 00555 basic_istream<_CharT, _Traits>& 00556 basic_istream<_CharT, _Traits>:: 00557 ignore(streamsize __n, int_type __delim) 00558 { 00559 _M_gcount = 0; 00560 sentry __cerb(*this, true); 00561 if (__cerb && __n > 0) 00562 { 00563 ios_base::iostate __err = ios_base::goodbit; 00564 __try 00565 { 00566 const int_type __eof = traits_type::eof(); 00567 __streambuf_type* __sb = this->rdbuf(); 00568 int_type __c = __sb->sgetc(); 00569 00570 // See comment above. 00571 bool __large_ignore = false; 00572 while (true) 00573 { 00574 while (_M_gcount < __n 00575 && !traits_type::eq_int_type(__c, __eof) 00576 && !traits_type::eq_int_type(__c, __delim)) 00577 { 00578 ++_M_gcount; 00579 __c = __sb->snextc(); 00580 } 00581 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max 00582 && !traits_type::eq_int_type(__c, __eof) 00583 && !traits_type::eq_int_type(__c, __delim)) 00584 { 00585 _M_gcount = 00586 __gnu_cxx::__numeric_traits<streamsize>::__min; 00587 __large_ignore = true; 00588 } 00589 else 00590 break; 00591 } 00592 00593 if (__large_ignore) 00594 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max; 00595 00596 if (traits_type::eq_int_type(__c, __eof)) 00597 __err |= ios_base::eofbit; 00598 else if (traits_type::eq_int_type(__c, __delim)) 00599 { 00600 if (_M_gcount 00601 < __gnu_cxx::__numeric_traits<streamsize>::__max) 00602 ++_M_gcount; 00603 __sb->sbumpc(); 00604 } 00605 } 00606 __catch(__cxxabiv1::__forced_unwind&) 00607 { 00608 this->_M_setstate(ios_base::badbit); 00609 __throw_exception_again; 00610 } 00611 __catch(...) 00612 { this->_M_setstate(ios_base::badbit); } 00613 if (__err) 00614 this->setstate(__err); 00615 } 00616 return *this; 00617 } 00618 00619 template<typename _CharT, typename _Traits> 00620 typename basic_istream<_CharT, _Traits>::int_type 00621 basic_istream<_CharT, _Traits>:: 00622 peek(void) 00623 { 00624 int_type __c = traits_type::eof(); 00625 _M_gcount = 0; 00626 sentry __cerb(*this, true); 00627 if (__cerb) 00628 { 00629 ios_base::iostate __err = ios_base::goodbit; 00630 __try 00631 { 00632 __c = this->rdbuf()->sgetc(); 00633 if (traits_type::eq_int_type(__c, traits_type::eof())) 00634 __err |= ios_base::eofbit; 00635 } 00636 __catch(__cxxabiv1::__forced_unwind&) 00637 { 00638 this->_M_setstate(ios_base::badbit); 00639 __throw_exception_again; 00640 } 00641 __catch(...) 00642 { this->_M_setstate(ios_base::badbit); } 00643 if (__err) 00644 this->setstate(__err); 00645 } 00646 return __c; 00647 } 00648 00649 template<typename _CharT, typename _Traits> 00650 basic_istream<_CharT, _Traits>& 00651 basic_istream<_CharT, _Traits>:: 00652 read(char_type* __s, streamsize __n) 00653 { 00654 _M_gcount = 0; 00655 sentry __cerb(*this, true); 00656 if (__cerb) 00657 { 00658 ios_base::iostate __err = ios_base::goodbit; 00659 __try 00660 { 00661 _M_gcount = this->rdbuf()->sgetn(__s, __n); 00662 if (_M_gcount != __n) 00663 __err |= (ios_base::eofbit | ios_base::failbit); 00664 } 00665 __catch(__cxxabiv1::__forced_unwind&) 00666 { 00667 this->_M_setstate(ios_base::badbit); 00668 __throw_exception_again; 00669 } 00670 __catch(...) 00671 { this->_M_setstate(ios_base::badbit); } 00672 if (__err) 00673 this->setstate(__err); 00674 } 00675 return *this; 00676 } 00677 00678 template<typename _CharT, typename _Traits> 00679 streamsize 00680 basic_istream<_CharT, _Traits>:: 00681 readsome(char_type* __s, streamsize __n) 00682 { 00683 _M_gcount = 0; 00684 sentry __cerb(*this, true); 00685 if (__cerb) 00686 { 00687 ios_base::iostate __err = ios_base::goodbit; 00688 __try 00689 { 00690 // Cannot compare int_type with streamsize generically. 00691 const streamsize __num = this->rdbuf()->in_avail(); 00692 if (__num > 0) 00693 _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n)); 00694 else if (__num == -1) 00695 __err |= ios_base::eofbit; 00696 } 00697 __catch(__cxxabiv1::__forced_unwind&) 00698 { 00699 this->_M_setstate(ios_base::badbit); 00700 __throw_exception_again; 00701 } 00702 __catch(...) 00703 { this->_M_setstate(ios_base::badbit); } 00704 if (__err) 00705 this->setstate(__err); 00706 } 00707 return _M_gcount; 00708 } 00709 00710 template<typename _CharT, typename _Traits> 00711 basic_istream<_CharT, _Traits>& 00712 basic_istream<_CharT, _Traits>:: 00713 putback(char_type __c) 00714 { 00715 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00716 // 60. What is a formatted input function? 00717 _M_gcount = 0; 00718 // Clear eofbit per N3168. 00719 this->clear(this->rdstate() & ~ios_base::eofbit); 00720 sentry __cerb(*this, true); 00721 if (__cerb) 00722 { 00723 ios_base::iostate __err = ios_base::goodbit; 00724 __try 00725 { 00726 const int_type __eof = traits_type::eof(); 00727 __streambuf_type* __sb = this->rdbuf(); 00728 if (!__sb 00729 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof)) 00730 __err |= ios_base::badbit; 00731 } 00732 __catch(__cxxabiv1::__forced_unwind&) 00733 { 00734 this->_M_setstate(ios_base::badbit); 00735 __throw_exception_again; 00736 } 00737 __catch(...) 00738 { this->_M_setstate(ios_base::badbit); } 00739 if (__err) 00740 this->setstate(__err); 00741 } 00742 return *this; 00743 } 00744 00745 template<typename _CharT, typename _Traits> 00746 basic_istream<_CharT, _Traits>& 00747 basic_istream<_CharT, _Traits>:: 00748 unget(void) 00749 { 00750 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00751 // 60. What is a formatted input function? 00752 _M_gcount = 0; 00753 // Clear eofbit per N3168. 00754 this->clear(this->rdstate() & ~ios_base::eofbit); 00755 sentry __cerb(*this, true); 00756 if (__cerb) 00757 { 00758 ios_base::iostate __err = ios_base::goodbit; 00759 __try 00760 { 00761 const int_type __eof = traits_type::eof(); 00762 __streambuf_type* __sb = this->rdbuf(); 00763 if (!__sb 00764 || traits_type::eq_int_type(__sb->sungetc(), __eof)) 00765 __err |= ios_base::badbit; 00766 } 00767 __catch(__cxxabiv1::__forced_unwind&) 00768 { 00769 this->_M_setstate(ios_base::badbit); 00770 __throw_exception_again; 00771 } 00772 __catch(...) 00773 { this->_M_setstate(ios_base::badbit); } 00774 if (__err) 00775 this->setstate(__err); 00776 } 00777 return *this; 00778 } 00779 00780 template<typename _CharT, typename _Traits> 00781 int 00782 basic_istream<_CharT, _Traits>:: 00783 sync(void) 00784 { 00785 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00786 // DR60. Do not change _M_gcount. 00787 int __ret = -1; 00788 sentry __cerb(*this, true); 00789 if (__cerb) 00790 { 00791 ios_base::iostate __err = ios_base::goodbit; 00792 __try 00793 { 00794 __streambuf_type* __sb = this->rdbuf(); 00795 if (__sb) 00796 { 00797 if (__sb->pubsync() == -1) 00798 __err |= ios_base::badbit; 00799 else 00800 __ret = 0; 00801 } 00802 } 00803 __catch(__cxxabiv1::__forced_unwind&) 00804 { 00805 this->_M_setstate(ios_base::badbit); 00806 __throw_exception_again; 00807 } 00808 __catch(...) 00809 { this->_M_setstate(ios_base::badbit); } 00810 if (__err) 00811 this->setstate(__err); 00812 } 00813 return __ret; 00814 } 00815 00816 template<typename _CharT, typename _Traits> 00817 typename basic_istream<_CharT, _Traits>::pos_type 00818 basic_istream<_CharT, _Traits>:: 00819 tellg(void) 00820 { 00821 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00822 // DR60. Do not change _M_gcount. 00823 pos_type __ret = pos_type(-1); 00824 sentry __cerb(*this, true); 00825 if (__cerb) 00826 { 00827 __try 00828 { 00829 if (!this->fail()) 00830 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, 00831 ios_base::in); 00832 } 00833 __catch(__cxxabiv1::__forced_unwind&) 00834 { 00835 this->_M_setstate(ios_base::badbit); 00836 __throw_exception_again; 00837 } 00838 __catch(...) 00839 { this->_M_setstate(ios_base::badbit); } 00840 } 00841 return __ret; 00842 } 00843 00844 template<typename _CharT, typename _Traits> 00845 basic_istream<_CharT, _Traits>& 00846 basic_istream<_CharT, _Traits>:: 00847 seekg(pos_type __pos) 00848 { 00849 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00850 // DR60. Do not change _M_gcount. 00851 // Clear eofbit per N3168. 00852 this->clear(this->rdstate() & ~ios_base::eofbit); 00853 sentry __cerb(*this, true); 00854 if (__cerb) 00855 { 00856 ios_base::iostate __err = ios_base::goodbit; 00857 __try 00858 { 00859 if (!this->fail()) 00860 { 00861 // 136. seekp, seekg setting wrong streams? 00862 const pos_type __p = this->rdbuf()->pubseekpos(__pos, 00863 ios_base::in); 00864 00865 // 129. Need error indication from seekp() and seekg() 00866 if (__p == pos_type(off_type(-1))) 00867 __err |= ios_base::failbit; 00868 } 00869 } 00870 __catch(__cxxabiv1::__forced_unwind&) 00871 { 00872 this->_M_setstate(ios_base::badbit); 00873 __throw_exception_again; 00874 } 00875 __catch(...) 00876 { this->_M_setstate(ios_base::badbit); } 00877 if (__err) 00878 this->setstate(__err); 00879 } 00880 return *this; 00881 } 00882 00883 template<typename _CharT, typename _Traits> 00884 basic_istream<_CharT, _Traits>& 00885 basic_istream<_CharT, _Traits>:: 00886 seekg(off_type __off, ios_base::seekdir __dir) 00887 { 00888 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00889 // DR60. Do not change _M_gcount. 00890 // Clear eofbit per N3168. 00891 this->clear(this->rdstate() & ~ios_base::eofbit); 00892 sentry __cerb(*this, true); 00893 if (__cerb) 00894 { 00895 ios_base::iostate __err = ios_base::goodbit; 00896 __try 00897 { 00898 if (!this->fail()) 00899 { 00900 // 136. seekp, seekg setting wrong streams? 00901 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir, 00902 ios_base::in); 00903 00904 // 129. Need error indication from seekp() and seekg() 00905 if (__p == pos_type(off_type(-1))) 00906 __err |= ios_base::failbit; 00907 } 00908 } 00909 __catch(__cxxabiv1::__forced_unwind&) 00910 { 00911 this->_M_setstate(ios_base::badbit); 00912 __throw_exception_again; 00913 } 00914 __catch(...) 00915 { this->_M_setstate(ios_base::badbit); } 00916 if (__err) 00917 this->setstate(__err); 00918 } 00919 return *this; 00920 } 00921 00922 // 27.6.1.2.3 Character extraction templates 00923 template<typename _CharT, typename _Traits> 00924 basic_istream<_CharT, _Traits>& 00925 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) 00926 { 00927 typedef basic_istream<_CharT, _Traits> __istream_type; 00928 typedef typename __istream_type::int_type __int_type; 00929 00930 typename __istream_type::sentry __cerb(__in, false); 00931 if (__cerb) 00932 { 00933 ios_base::iostate __err = ios_base::goodbit; 00934 __try 00935 { 00936 const __int_type __cb = __in.rdbuf()->sbumpc(); 00937 if (!_Traits::eq_int_type(__cb, _Traits::eof())) 00938 __c = _Traits::to_char_type(__cb); 00939 else 00940 __err |= (ios_base::eofbit | ios_base::failbit); 00941 } 00942 __catch(__cxxabiv1::__forced_unwind&) 00943 { 00944 __in._M_setstate(ios_base::badbit); 00945 __throw_exception_again; 00946 } 00947 __catch(...) 00948 { __in._M_setstate(ios_base::badbit); } 00949 if (__err) 00950 __in.setstate(__err); 00951 } 00952 return __in; 00953 } 00954 00955 template<typename _CharT, typename _Traits> 00956 basic_istream<_CharT, _Traits>& 00957 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s) 00958 { 00959 typedef basic_istream<_CharT, _Traits> __istream_type; 00960 typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 00961 typedef typename _Traits::int_type int_type; 00962 typedef _CharT char_type; 00963 typedef ctype<_CharT> __ctype_type; 00964 00965 streamsize __extracted = 0; 00966 ios_base::iostate __err = ios_base::goodbit; 00967 typename __istream_type::sentry __cerb(__in, false); 00968 if (__cerb) 00969 { 00970 __try 00971 { 00972 // Figure out how many characters to extract. 00973 streamsize __num = __in.width(); 00974 if (__num <= 0) 00975 __num = __gnu_cxx::__numeric_traits<streamsize>::__max; 00976 00977 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); 00978 00979 const int_type __eof = _Traits::eof(); 00980 __streambuf_type* __sb = __in.rdbuf(); 00981 int_type __c = __sb->sgetc(); 00982 00983 while (__extracted < __num - 1 00984 && !_Traits::eq_int_type(__c, __eof) 00985 && !__ct.is(ctype_base::space, 00986 _Traits::to_char_type(__c))) 00987 { 00988 *__s++ = _Traits::to_char_type(__c); 00989 ++__extracted; 00990 __c = __sb->snextc(); 00991 } 00992 if (_Traits::eq_int_type(__c, __eof)) 00993 __err |= ios_base::eofbit; 00994 00995 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00996 // 68. Extractors for char* should store null at end 00997 *__s = char_type(); 00998 __in.width(0); 00999 } 01000 __catch(__cxxabiv1::__forced_unwind&) 01001 { 01002 __in._M_setstate(ios_base::badbit); 01003 __throw_exception_again; 01004 } 01005 __catch(...) 01006 { __in._M_setstate(ios_base::badbit); } 01007 } 01008 if (!__extracted) 01009 __err |= ios_base::failbit; 01010 if (__err) 01011 __in.setstate(__err); 01012 return __in; 01013 } 01014 01015 // 27.6.1.4 Standard basic_istream manipulators 01016 template<typename _CharT, typename _Traits> 01017 basic_istream<_CharT, _Traits>& 01018 ws(basic_istream<_CharT, _Traits>& __in) 01019 { 01020 typedef basic_istream<_CharT, _Traits> __istream_type; 01021 typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 01022 typedef typename __istream_type::int_type __int_type; 01023 typedef ctype<_CharT> __ctype_type; 01024 01025 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); 01026 const __int_type __eof = _Traits::eof(); 01027 __streambuf_type* __sb = __in.rdbuf(); 01028 __int_type __c = __sb->sgetc(); 01029 01030 while (!_Traits::eq_int_type(__c, __eof) 01031 && __ct.is(ctype_base::space, _Traits::to_char_type(__c))) 01032 __c = __sb->snextc(); 01033 01034 if (_Traits::eq_int_type(__c, __eof)) 01035 __in.setstate(ios_base::eofbit); 01036 return __in; 01037 } 01038 01039 // Inhibit implicit instantiations for required instantiations, 01040 // which are defined via explicit instantiations elsewhere. 01041 #if _GLIBCXX_EXTERN_TEMPLATE 01042 extern template class basic_istream<char>; 01043 extern template istream& ws(istream&); 01044 extern template istream& operator>>(istream&, char&); 01045 extern template istream& operator>>(istream&, char*); 01046 extern template istream& operator>>(istream&, unsigned char&); 01047 extern template istream& operator>>(istream&, signed char&); 01048 extern template istream& operator>>(istream&, unsigned char*); 01049 extern template istream& operator>>(istream&, signed char*); 01050 01051 extern template istream& istream::_M_extract(unsigned short&); 01052 extern template istream& istream::_M_extract(unsigned int&); 01053 extern template istream& istream::_M_extract(long&); 01054 extern template istream& istream::_M_extract(unsigned long&); 01055 extern template istream& istream::_M_extract(bool&); 01056 #ifdef _GLIBCXX_USE_LONG_LONG 01057 extern template istream& istream::_M_extract(long long&); 01058 extern template istream& istream::_M_extract(unsigned long long&); 01059 #endif 01060 extern template istream& istream::_M_extract(float&); 01061 extern template istream& istream::_M_extract(double&); 01062 extern template istream& istream::_M_extract(long double&); 01063 extern template istream& istream::_M_extract(void*&); 01064 01065 extern template class basic_iostream<char>; 01066 01067 #ifdef _GLIBCXX_USE_WCHAR_T 01068 extern template class basic_istream<wchar_t>; 01069 extern template wistream& ws(wistream&); 01070 extern template wistream& operator>>(wistream&, wchar_t&); 01071 extern template wistream& operator>>(wistream&, wchar_t*); 01072 01073 extern template wistream& wistream::_M_extract(unsigned short&); 01074 extern template wistream& wistream::_M_extract(unsigned int&); 01075 extern template wistream& wistream::_M_extract(long&); 01076 extern template wistream& wistream::_M_extract(unsigned long&); 01077 extern template wistream& wistream::_M_extract(bool&); 01078 #ifdef _GLIBCXX_USE_LONG_LONG 01079 extern template wistream& wistream::_M_extract(long long&); 01080 extern template wistream& wistream::_M_extract(unsigned long long&); 01081 #endif 01082 extern template wistream& wistream::_M_extract(float&); 01083 extern template wistream& wistream::_M_extract(double&); 01084 extern template wistream& wistream::_M_extract(long double&); 01085 extern template wistream& wistream::_M_extract(void*&); 01086 01087 extern template class basic_iostream<wchar_t>; 01088 #endif 01089 #endif 01090 01091 _GLIBCXX_END_NAMESPACE_VERSION 01092 } // namespace std 01093 01094 #endif