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