# istream.tcc

Go to the documentation of this file.

    00001 // istream classes -*- C++ -*-
    00002
    00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    00004 // 2006, 2007, 2008, 2009
    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 istream.tcc
    00028  *  This is an internal header file, included by other library headers.
    00029  *  You should not attempt to use it directly.
    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 <cxxabi-forced.h>
    00042
    00043 _GLIBCXX_BEGIN_NAMESPACE(std)
    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::iostate(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::iostate(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       long __l;
    00119       _M_extract(__l);
    00120       if (!this->fail())
    00121     {
    00122       if (__gnu_cxx::__numeric_traits<short>::__min <= __l
    00123           && __l <= __gnu_cxx::__numeric_traits<short>::__max)
    00124         __n = short(__l);
    00125       else
    00126         this->setstate(ios_base::failbit);
    00127     }
    00128       return *this;
    00129     }
    00130
    00131   template<typename _CharT, typename _Traits>
    00132     basic_istream<_CharT, _Traits>&
    00133     basic_istream<_CharT, _Traits>::
    00134     operator>>(int& __n)
    00135     {
    00136       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00137       // 118. basic_istream uses nonexistent num_get member functions.
    00138       long __l;
    00139       _M_extract(__l);
    00140       if (!this->fail())
    00141     {
    00142       if (__gnu_cxx::__numeric_traits<int>::__min <= __l
    00143           && __l <= __gnu_cxx::__numeric_traits<int>::__max)
    00144         __n = int(__l);
    00145       else
    00146         this->setstate(ios_base::failbit);
    00147     }
    00148       return *this;
    00149     }
    00150
    00151   template<typename _CharT, typename _Traits>
    00152     basic_istream<_CharT, _Traits>&
    00153     basic_istream<_CharT, _Traits>::
    00154     operator>>(__streambuf_type* __sbout)
    00155     {
    00156       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00157       sentry __cerb(*this, false);
    00158       if (__cerb && __sbout)
    00159     {
    00160       __try
    00161         {
    00162           bool __ineof;
    00163           if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
    00164         __err |= ios_base::failbit;
    00165           if (__ineof)
    00166         __err |= ios_base::eofbit;
    00167         }
    00168       __catch(__cxxabiv1::__forced_unwind&)
    00169         {
    00170           this->_M_setstate(ios_base::failbit);
    00171           __throw_exception_again;
    00172         }
    00173       __catch(...)
    00174         { this->_M_setstate(ios_base::failbit); }
    00175     }
    00176       else if (!__sbout)
    00177     __err |= ios_base::failbit;
    00178       if (__err)
    00179     this->setstate(__err);
    00180       return *this;
    00181     }
    00182
    00183   template<typename _CharT, typename _Traits>
    00184     typename basic_istream<_CharT, _Traits>::int_type
    00185     basic_istream<_CharT, _Traits>::
    00186     get(void)
    00187     {
    00188       const int_type __eof = traits_type::eof();
    00189       int_type __c = __eof;
    00190       _M_gcount = 0;
    00191       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00192       sentry __cerb(*this, true);
    00193       if (__cerb)
    00194     {
    00195       __try
    00196         {
    00197           __c = this->rdbuf()->sbumpc();
    00198           // 27.6.1.1 paragraph 3
    00199           if (!traits_type::eq_int_type(__c, __eof))
    00200         _M_gcount = 1;
    00201           else
    00202         __err |= ios_base::eofbit;
    00203         }
    00204       __catch(__cxxabiv1::__forced_unwind&)
    00205         {
    00206           this->_M_setstate(ios_base::badbit);
    00207           __throw_exception_again;
    00208         }
    00209       __catch(...)
    00210         { this->_M_setstate(ios_base::badbit); }
    00211     }
    00212       if (!_M_gcount)
    00213     __err |= ios_base::failbit;
    00214       if (__err)
    00215     this->setstate(__err);
    00216       return __c;
    00217     }
    00218
    00219   template<typename _CharT, typename _Traits>
    00220     basic_istream<_CharT, _Traits>&
    00221     basic_istream<_CharT, _Traits>::
    00222     get(char_type& __c)
    00223     {
    00224       _M_gcount = 0;
    00225       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00226       sentry __cerb(*this, true);
    00227       if (__cerb)
    00228     {
    00229       __try
    00230         {
    00231           const int_type __cb = this->rdbuf()->sbumpc();
    00232           // 27.6.1.1 paragraph 3
    00233           if (!traits_type::eq_int_type(__cb, traits_type::eof()))
    00234         {
    00235           _M_gcount = 1;
    00236           __c = traits_type::to_char_type(__cb);
    00237         }
    00238           else
    00239         __err |= ios_base::eofbit;
    00240         }
    00241       __catch(__cxxabiv1::__forced_unwind&)
    00242         {
    00243           this->_M_setstate(ios_base::badbit);
    00244           __throw_exception_again;
    00245         }
    00246       __catch(...)
    00247         { this->_M_setstate(ios_base::badbit); }
    00248     }
    00249       if (!_M_gcount)
    00250     __err |= ios_base::failbit;
    00251       if (__err)
    00252     this->setstate(__err);
    00253       return *this;
    00254     }
    00255
    00256   template<typename _CharT, typename _Traits>
    00257     basic_istream<_CharT, _Traits>&
    00258     basic_istream<_CharT, _Traits>::
    00259     get(char_type* __s, streamsize __n, char_type __delim)
    00260     {
    00261       _M_gcount = 0;
    00262       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00263       sentry __cerb(*this, true);
    00264       if (__cerb)
    00265     {
    00266       __try
    00267         {
    00268           const int_type __idelim = traits_type::to_int_type(__delim);
    00269           const int_type __eof = traits_type::eof();
    00270           __streambuf_type* __sb = this->rdbuf();
    00271           int_type __c = __sb->sgetc();
    00272
    00273           while (_M_gcount + 1 < __n
    00274              && !traits_type::eq_int_type(__c, __eof)
    00275              && !traits_type::eq_int_type(__c, __idelim))
    00276         {
    00277           *__s++ = traits_type::to_char_type(__c);
    00278           ++_M_gcount;
    00279           __c = __sb->snextc();
    00280         }
    00281           if (traits_type::eq_int_type(__c, __eof))
    00282         __err |= ios_base::eofbit;
    00283         }
    00284       __catch(__cxxabiv1::__forced_unwind&)
    00285         {
    00286           this->_M_setstate(ios_base::badbit);
    00287           __throw_exception_again;
    00288         }
    00289       __catch(...)
    00290         { this->_M_setstate(ios_base::badbit); }
    00291     }
    00292       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00293       // 243. get and getline when sentry reports failure.
    00294       if (__n > 0)
    00295     *__s = char_type();
    00296       if (!_M_gcount)
    00297     __err |= ios_base::failbit;
    00298       if (__err)
    00299     this->setstate(__err);
    00300       return *this;
    00301     }
    00302
    00303   template<typename _CharT, typename _Traits>
    00304     basic_istream<_CharT, _Traits>&
    00305     basic_istream<_CharT, _Traits>::
    00306     get(__streambuf_type& __sb, char_type __delim)
    00307     {
    00308       _M_gcount = 0;
    00309       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00310       sentry __cerb(*this, true);
    00311       if (__cerb)
    00312     {
    00313       __try
    00314         {
    00315           const int_type __idelim = traits_type::to_int_type(__delim);
    00316           const int_type __eof = traits_type::eof();
    00317           __streambuf_type* __this_sb = this->rdbuf();
    00318           int_type __c = __this_sb->sgetc();
    00319           char_type __c2 = traits_type::to_char_type(__c);
    00320
    00321           while (!traits_type::eq_int_type(__c, __eof)
    00322              && !traits_type::eq_int_type(__c, __idelim)
    00323              && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
    00324         {
    00325           ++_M_gcount;
    00326           __c = __this_sb->snextc();
    00327           __c2 = traits_type::to_char_type(__c);
    00328         }
    00329           if (traits_type::eq_int_type(__c, __eof))
    00330         __err |= ios_base::eofbit;
    00331         }
    00332       __catch(__cxxabiv1::__forced_unwind&)
    00333         {
    00334           this->_M_setstate(ios_base::badbit);
    00335           __throw_exception_again;
    00336         }
    00337       __catch(...)
    00338         { this->_M_setstate(ios_base::badbit); }
    00339     }
    00340       if (!_M_gcount)
    00341     __err |= ios_base::failbit;
    00342       if (__err)
    00343     this->setstate(__err);
    00344       return *this;
    00345     }
    00346
    00347   template<typename _CharT, typename _Traits>
    00348     basic_istream<_CharT, _Traits>&
    00349     basic_istream<_CharT, _Traits>::
    00350     getline(char_type* __s, streamsize __n, char_type __delim)
    00351     {
    00352       _M_gcount = 0;
    00353       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00354       sentry __cerb(*this, true);
    00355       if (__cerb)
    00356         {
    00357           __try
    00358             {
    00359               const int_type __idelim = traits_type::to_int_type(__delim);
    00360               const int_type __eof = traits_type::eof();
    00361               __streambuf_type* __sb = this->rdbuf();
    00362               int_type __c = __sb->sgetc();
    00363
    00364               while (_M_gcount + 1 < __n
    00365                      && !traits_type::eq_int_type(__c, __eof)
    00366                      && !traits_type::eq_int_type(__c, __idelim))
    00367                 {
    00368                   *__s++ = traits_type::to_char_type(__c);
    00369                   __c = __sb->snextc();
    00370                   ++_M_gcount;
    00371                 }
    00372               if (traits_type::eq_int_type(__c, __eof))
    00373                 __err |= ios_base::eofbit;
    00374               else
    00375                 {
    00376                   if (traits_type::eq_int_type(__c, __idelim))
    00377                     {
    00378                       __sb->sbumpc();
    00379                       ++_M_gcount;
    00380                     }
    00381                   else
    00382                     __err |= ios_base::failbit;
    00383                 }
    00384             }
    00385       __catch(__cxxabiv1::__forced_unwind&)
    00386         {
    00387           this->_M_setstate(ios_base::badbit);
    00388           __throw_exception_again;
    00389         }
    00390           __catch(...)
    00391             { this->_M_setstate(ios_base::badbit); }
    00392         }
    00393       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00394       // 243. get and getline when sentry reports failure.
    00395       if (__n > 0)
    00396     *__s = char_type();
    00397       if (!_M_gcount)
    00398         __err |= ios_base::failbit;
    00399       if (__err)
    00400         this->setstate(__err);
    00401       return *this;
    00402     }
    00403
    00404   // We provide three overloads, since the first two are much simpler
    00405   // than the general case. Also, the latter two can thus adopt the
    00406   // same "batchy" strategy used by getline above.
    00407   template<typename _CharT, typename _Traits>
    00408     basic_istream<_CharT, _Traits>&
    00409     basic_istream<_CharT, _Traits>::
    00410     ignore(void)
    00411     {
    00412       _M_gcount = 0;
    00413       sentry __cerb(*this, true);
    00414       if (__cerb)
    00415     {
    00416       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00417       __try
    00418         {
    00419           const int_type __eof = traits_type::eof();
    00420           __streambuf_type* __sb = this->rdbuf();
    00421
    00422           if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
    00423         __err |= ios_base::eofbit;
    00424           else
    00425         _M_gcount = 1;
    00426         }
    00427       __catch(__cxxabiv1::__forced_unwind&)
    00428         {
    00429           this->_M_setstate(ios_base::badbit);
    00430           __throw_exception_again;
    00431         }
    00432       __catch(...)
    00433         { this->_M_setstate(ios_base::badbit); }
    00434       if (__err)
    00435         this->setstate(__err);
    00436     }
    00437       return *this;
    00438     }
    00439
    00440   template<typename _CharT, typename _Traits>
    00441     basic_istream<_CharT, _Traits>&
    00442     basic_istream<_CharT, _Traits>::
    00443     ignore(streamsize __n)
    00444     {
    00445       _M_gcount = 0;
    00446       sentry __cerb(*this, true);
    00447       if (__cerb && __n > 0)
    00448         {
    00449           ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00450           __try
    00451             {
    00452               const int_type __eof = traits_type::eof();
    00453               __streambuf_type* __sb = this->rdbuf();
    00454               int_type __c = __sb->sgetc();
    00455
    00456           // N.B. On LFS-enabled platforms streamsize is still 32 bits
    00457           // wide: if we want to implement the standard mandated behavior
    00458           // for n == max() (see 27.6.1.3/24) we are at risk of signed
    00459           // integer overflow: thus these contortions. Also note that,
    00460           // by definition, when more than 2G chars are actually ignored,
    00461           // _M_gcount (the return value of gcount, that is) cannot be
    00462           // really correct, being unavoidably too small.
    00463           bool __large_ignore = false;
    00464           while (true)
    00465         {
    00466           while (_M_gcount < __n
    00467              && !traits_type::eq_int_type(__c, __eof))
    00468             {
    00469               ++_M_gcount;
    00470               __c = __sb->snextc();
    00471             }
    00472           if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
    00473               && !traits_type::eq_int_type(__c, __eof))
    00474             {
    00475               _M_gcount =
    00476             __gnu_cxx::__numeric_traits<streamsize>::__min;
    00477               __large_ignore = true;
    00478             }
    00479           else
    00480             break;
    00481         }
    00482
    00483           if (__large_ignore)
    00484         _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
    00485
    00486           if (traits_type::eq_int_type(__c, __eof))
    00487                 __err |= ios_base::eofbit;
    00488             }
    00489       __catch(__cxxabiv1::__forced_unwind&)
    00490         {
    00491           this->_M_setstate(ios_base::badbit);
    00492           __throw_exception_again;
    00493         }
    00494           __catch(...)
    00495             { this->_M_setstate(ios_base::badbit); }
    00496           if (__err)
    00497             this->setstate(__err);
    00498         }
    00499       return *this;
    00500     }
    00501
    00502   template<typename _CharT, typename _Traits>
    00503     basic_istream<_CharT, _Traits>&
    00504     basic_istream<_CharT, _Traits>::
    00505     ignore(streamsize __n, int_type __delim)
    00506     {
    00507       _M_gcount = 0;
    00508       sentry __cerb(*this, true);
    00509       if (__cerb && __n > 0)
    00510         {
    00511           ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00512           __try
    00513             {
    00514               const int_type __eof = traits_type::eof();
    00515               __streambuf_type* __sb = this->rdbuf();
    00516               int_type __c = __sb->sgetc();
    00517
    00518           // See comment above.
    00519           bool __large_ignore = false;
    00520           while (true)
    00521         {
    00522           while (_M_gcount < __n
    00523              && !traits_type::eq_int_type(__c, __eof)
    00524              && !traits_type::eq_int_type(__c, __delim))
    00525             {
    00526               ++_M_gcount;
    00527               __c = __sb->snextc();
    00528             }
    00529           if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
    00530               && !traits_type::eq_int_type(__c, __eof)
    00531               && !traits_type::eq_int_type(__c, __delim))
    00532             {
    00533               _M_gcount =
    00534             __gnu_cxx::__numeric_traits<streamsize>::__min;
    00535               __large_ignore = true;
    00536             }
    00537           else
    00538             break;
    00539         }
    00540
    00541           if (__large_ignore)
    00542         _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
    00543
    00544               if (traits_type::eq_int_type(__c, __eof))
    00545                 __err |= ios_base::eofbit;
    00546           else if (traits_type::eq_int_type(__c, __delim))
    00547         {
    00548           if (_M_gcount
    00549               < __gnu_cxx::__numeric_traits<streamsize>::__max)
    00550             ++_M_gcount;
    00551           __sb->sbumpc();
    00552         }
    00553             }
    00554       __catch(__cxxabiv1::__forced_unwind&)
    00555         {
    00556           this->_M_setstate(ios_base::badbit);
    00557           __throw_exception_again;
    00558         }
    00559           __catch(...)
    00560             { this->_M_setstate(ios_base::badbit); }
    00561           if (__err)
    00562             this->setstate(__err);
    00563         }
    00564       return *this;
    00565     }
    00566
    00567   template<typename _CharT, typename _Traits>
    00568     typename basic_istream<_CharT, _Traits>::int_type
    00569     basic_istream<_CharT, _Traits>::
    00570     peek(void)
    00571     {
    00572       int_type __c = traits_type::eof();
    00573       _M_gcount = 0;
    00574       sentry __cerb(*this, true);
    00575       if (__cerb)
    00576     {
    00577       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00578       __try
    00579         {
    00580           __c = this->rdbuf()->sgetc();
    00581           if (traits_type::eq_int_type(__c, traits_type::eof()))
    00582         __err |= ios_base::eofbit;
    00583         }
    00584       __catch(__cxxabiv1::__forced_unwind&)
    00585         {
    00586           this->_M_setstate(ios_base::badbit);
    00587           __throw_exception_again;
    00588         }
    00589       __catch(...)
    00590         { this->_M_setstate(ios_base::badbit); }
    00591       if (__err)
    00592         this->setstate(__err);
    00593     }
    00594       return __c;
    00595     }
    00596
    00597   template<typename _CharT, typename _Traits>
    00598     basic_istream<_CharT, _Traits>&
    00599     basic_istream<_CharT, _Traits>::
    00600     read(char_type* __s, streamsize __n)
    00601     {
    00602       _M_gcount = 0;
    00603       sentry __cerb(*this, true);
    00604       if (__cerb)
    00605     {
    00606       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00607       __try
    00608         {
    00609           _M_gcount = this->rdbuf()->sgetn(__s, __n);
    00610           if (_M_gcount != __n)
    00611         __err |= (ios_base::eofbit | ios_base::failbit);
    00612         }
    00613       __catch(__cxxabiv1::__forced_unwind&)
    00614         {
    00615           this->_M_setstate(ios_base::badbit);
    00616           __throw_exception_again;
    00617         }
    00618       __catch(...)
    00619         { this->_M_setstate(ios_base::badbit); }
    00620       if (__err)
    00621         this->setstate(__err);
    00622     }
    00623       return *this;
    00624     }
    00625
    00626   template<typename _CharT, typename _Traits>
    00627     streamsize
    00628     basic_istream<_CharT, _Traits>::
    00629     readsome(char_type* __s, streamsize __n)
    00630     {
    00631       _M_gcount = 0;
    00632       sentry __cerb(*this, true);
    00633       if (__cerb)
    00634     {
    00635       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00636       __try
    00637         {
    00638           // Cannot compare int_type with streamsize generically.
    00639           const streamsize __num = this->rdbuf()->in_avail();
    00640           if (__num > 0)
    00641         _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));
    00642           else if (__num == -1)
    00643         __err |= ios_base::eofbit;
    00644         }
    00645       __catch(__cxxabiv1::__forced_unwind&)
    00646         {
    00647           this->_M_setstate(ios_base::badbit);
    00648           __throw_exception_again;
    00649         }
    00650       __catch(...)
    00651         { this->_M_setstate(ios_base::badbit); }
    00652       if (__err)
    00653         this->setstate(__err);
    00654     }
    00655       return _M_gcount;
    00656     }
    00657
    00658   template<typename _CharT, typename _Traits>
    00659     basic_istream<_CharT, _Traits>&
    00660     basic_istream<_CharT, _Traits>::
    00661     putback(char_type __c)
    00662     {
    00663       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00664       // 60. What is a formatted input function?
    00665       _M_gcount = 0;
    00666       sentry __cerb(*this, true);
    00667       if (__cerb)
    00668     {
    00669       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00670       __try
    00671         {
    00672           const int_type __eof = traits_type::eof();
    00673           __streambuf_type* __sb = this->rdbuf();
    00674           if (!__sb
    00675           || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
    00676         __err |= ios_base::badbit;
    00677         }
    00678       __catch(__cxxabiv1::__forced_unwind&)
    00679         {
    00680           this->_M_setstate(ios_base::badbit);
    00681           __throw_exception_again;
    00682         }
    00683       __catch(...)
    00684         { this->_M_setstate(ios_base::badbit); }
    00685       if (__err)
    00686         this->setstate(__err);
    00687     }
    00688       return *this;
    00689     }
    00690
    00691   template<typename _CharT, typename _Traits>
    00692     basic_istream<_CharT, _Traits>&
    00693     basic_istream<_CharT, _Traits>::
    00694     unget(void)
    00695     {
    00696       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00697       // 60. What is a formatted input function?
    00698       _M_gcount = 0;
    00699       sentry __cerb(*this, true);
    00700       if (__cerb)
    00701     {
    00702       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00703       __try
    00704         {
    00705           const int_type __eof = traits_type::eof();
    00706           __streambuf_type* __sb = this->rdbuf();
    00707           if (!__sb
    00708           || traits_type::eq_int_type(__sb->sungetc(), __eof))
    00709         __err |= ios_base::badbit;
    00710         }
    00711       __catch(__cxxabiv1::__forced_unwind&)
    00712         {
    00713           this->_M_setstate(ios_base::badbit);
    00714           __throw_exception_again;
    00715         }
    00716       __catch(...)
    00717         { this->_M_setstate(ios_base::badbit); }
    00718       if (__err)
    00719         this->setstate(__err);
    00720     }
    00721       return *this;
    00722     }
    00723
    00724   template<typename _CharT, typename _Traits>
    00725     int
    00726     basic_istream<_CharT, _Traits>::
    00727     sync(void)
    00728     {
    00729       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00730       // DR60.  Do not change _M_gcount.
    00731       int __ret = -1;
    00732       sentry __cerb(*this, true);
    00733       if (__cerb)
    00734     {
    00735       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00736       __try
    00737         {
    00738           __streambuf_type* __sb = this->rdbuf();
    00739           if (__sb)
    00740         {
    00741           if (__sb->pubsync() == -1)
    00742             __err |= ios_base::badbit;
    00743           else
    00744             __ret = 0;
    00745         }
    00746         }
    00747       __catch(__cxxabiv1::__forced_unwind&)
    00748         {
    00749           this->_M_setstate(ios_base::badbit);
    00750           __throw_exception_again;
    00751         }
    00752       __catch(...)
    00753         { this->_M_setstate(ios_base::badbit); }
    00754       if (__err)
    00755         this->setstate(__err);
    00756     }
    00757       return __ret;
    00758     }
    00759
    00760   template<typename _CharT, typename _Traits>
    00761     typename basic_istream<_CharT, _Traits>::pos_type
    00762     basic_istream<_CharT, _Traits>::
    00763     tellg(void)
    00764     {
    00765       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00766       // DR60.  Do not change _M_gcount.
    00767       pos_type __ret = pos_type(-1);
    00768       __try
    00769     {
    00770       if (!this->fail())
    00771         __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
    00772                           ios_base::in);
    00773     }
    00774       __catch(__cxxabiv1::__forced_unwind&)
    00775     {
    00776       this->_M_setstate(ios_base::badbit);
    00777       __throw_exception_again;
    00778     }
    00779       __catch(...)
    00780     { this->_M_setstate(ios_base::badbit); }
    00781       return __ret;
    00782     }
    00783
    00784   template<typename _CharT, typename _Traits>
    00785     basic_istream<_CharT, _Traits>&
    00786     basic_istream<_CharT, _Traits>::
    00787     seekg(pos_type __pos)
    00788     {
    00789       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00790       // DR60.  Do not change _M_gcount.
    00791       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00792       __try
    00793     {
    00794       if (!this->fail())
    00795         {
    00796           // 136.  seekp, seekg setting wrong streams?
    00797           const pos_type __p = this->rdbuf()->pubseekpos(__pos,
    00798                                  ios_base::in);
    00799
    00800           // 129.  Need error indication from seekp() and seekg()
    00801           if (__p == pos_type(off_type(-1)))
    00802         __err |= ios_base::failbit;
    00803         }
    00804     }
    00805       __catch(__cxxabiv1::__forced_unwind&)
    00806     {
    00807       this->_M_setstate(ios_base::badbit);
    00808       __throw_exception_again;
    00809     }
    00810       __catch(...)
    00811     { this->_M_setstate(ios_base::badbit); }
    00812       if (__err)
    00813     this->setstate(__err);
    00814       return *this;
    00815     }
    00816
    00817   template<typename _CharT, typename _Traits>
    00818     basic_istream<_CharT, _Traits>&
    00819     basic_istream<_CharT, _Traits>::
    00820     seekg(off_type __off, ios_base::seekdir __dir)
    00821     {
    00822       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00823       // DR60.  Do not change _M_gcount.
    00824       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00825       __try
    00826     {
    00827       if (!this->fail())
    00828         {
    00829           // 136.  seekp, seekg setting wrong streams?
    00830           const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
    00831                                  ios_base::in);
    00832
    00833           // 129.  Need error indication from seekp() and seekg()
    00834           if (__p == pos_type(off_type(-1)))
    00835         __err |= ios_base::failbit;
    00836         }
    00837     }
    00838       __catch(__cxxabiv1::__forced_unwind&)
    00839     {
    00840       this->_M_setstate(ios_base::badbit);
    00841       __throw_exception_again;
    00842     }
    00843       __catch(...)
    00844     { this->_M_setstate(ios_base::badbit); }
    00845       if (__err)
    00846     this->setstate(__err);
    00847       return *this;
    00848     }
    00849
    00850   // 27.6.1.2.3 Character extraction templates
    00851   template<typename _CharT, typename _Traits>
    00852     basic_istream<_CharT, _Traits>&
    00853     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
    00854     {
    00855       typedef basic_istream<_CharT, _Traits>        __istream_type;
    00856       typedef typename __istream_type::int_type         __int_type;
    00857
    00858       typename __istream_type::sentry __cerb(__in, false);
    00859       if (__cerb)
    00860     {
    00861       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00862       __try
    00863         {
    00864           const __int_type __cb = __in.rdbuf()->sbumpc();
    00865           if (!_Traits::eq_int_type(__cb, _Traits::eof()))
    00866         __c = _Traits::to_char_type(__cb);
    00867           else
    00868         __err |= (ios_base::eofbit | ios_base::failbit);
    00869         }
    00870       __catch(__cxxabiv1::__forced_unwind&)
    00871         {
    00872           __in._M_setstate(ios_base::badbit);
    00873           __throw_exception_again;
    00874         }
    00875       __catch(...)
    00876         { __in._M_setstate(ios_base::badbit); }
    00877       if (__err)
    00878         __in.setstate(__err);
    00879     }
    00880       return __in;
    00881     }
    00882
    00883   template<typename _CharT, typename _Traits>
    00884     basic_istream<_CharT, _Traits>&
    00885     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
    00886     {
    00887       typedef basic_istream<_CharT, _Traits>        __istream_type;
    00888       typedef basic_streambuf<_CharT, _Traits>          __streambuf_type;
    00889       typedef typename _Traits::int_type        int_type;
    00890       typedef _CharT                    char_type;
    00891       typedef ctype<_CharT>             __ctype_type;
    00892
    00893       streamsize __extracted = 0;
    00894       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
    00895       typename __istream_type::sentry __cerb(__in, false);
    00896       if (__cerb)
    00897     {
    00898       __try
    00899         {
    00900           // Figure out how many characters to extract.
    00901           streamsize __num = __in.width();
    00902           if (__num <= 0)
    00903         __num = __gnu_cxx::__numeric_traits<streamsize>::__max;
    00904
    00905           const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
    00906
    00907           const int_type __eof = _Traits::eof();
    00908           __streambuf_type* __sb = __in.rdbuf();
    00909           int_type __c = __sb->sgetc();
    00910
    00911           while (__extracted < __num - 1
    00912              && !_Traits::eq_int_type(__c, __eof)
    00913              && !__ct.is(ctype_base::space,
    00914                  _Traits::to_char_type(__c)))
    00915         {
    00916           *__s++ = _Traits::to_char_type(__c);
    00917           ++__extracted;
    00918           __c = __sb->snextc();
    00919         }
    00920           if (_Traits::eq_int_type(__c, __eof))
    00921         __err |= ios_base::eofbit;
    00922
    00923           // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00924           // 68.  Extractors for char* should store null at end
    00925           *__s = char_type();
    00926           __in.width(0);
    00927         }
    00928       __catch(__cxxabiv1::__forced_unwind&)
    00929         {
    00930           __in._M_setstate(ios_base::badbit);
    00931           __throw_exception_again;
    00932         }
    00933       __catch(...)
    00934         { __in._M_setstate(ios_base::badbit); }
    00935     }
    00936       if (!__extracted)
    00937     __err |= ios_base::failbit;
    00938       if (__err)
    00939     __in.setstate(__err);
    00940       return __in;
    00941     }
    00942
    00943   // 27.6.1.4 Standard basic_istream manipulators
    00944   template<typename _CharT, typename _Traits>
    00945     basic_istream<_CharT, _Traits>&
    00946     ws(basic_istream<_CharT, _Traits>& __in)
    00947     {
    00948       typedef basic_istream<_CharT, _Traits>        __istream_type;
    00949       typedef basic_streambuf<_CharT, _Traits>          __streambuf_type;
    00950       typedef typename __istream_type::int_type     __int_type;
    00951       typedef ctype<_CharT>             __ctype_type;
    00952
    00953       const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
    00954       const __int_type __eof = _Traits::eof();
    00955       __streambuf_type* __sb = __in.rdbuf();
    00956       __int_type __c = __sb->sgetc();
    00957
    00958       while (!_Traits::eq_int_type(__c, __eof)
    00959          && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
    00960     __c = __sb->snextc();
    00961
    00962        if (_Traits::eq_int_type(__c, __eof))
    00963      __in.setstate(ios_base::eofbit);
    00964       return __in;
    00965     }
    00966
    00967   // Inhibit implicit instantiations for required instantiations,
    00968   // which are defined via explicit instantiations elsewhere.
    00969   // NB:  This syntax is a GNU extension.
    00970 #if _GLIBCXX_EXTERN_TEMPLATE
    00971   extern template class basic_istream<char>;
    00972   extern template istream& ws(istream&);
    00973   extern template istream& operator>>(istream&, char&);
    00974   extern template istream& operator>>(istream&, char*);
    00975   extern template istream& operator>>(istream&, unsigned char&);
    00976   extern template istream& operator>>(istream&, signed char&);
    00977   extern template istream& operator>>(istream&, unsigned char*);
    00978   extern template istream& operator>>(istream&, signed char*);
    00979
    00980   extern template istream& istream::_M_extract(unsigned short&);
    00981   extern template istream& istream::_M_extract(unsigned int&);
    00982   extern template istream& istream::_M_extract(long&);
    00983   extern template istream& istream::_M_extract(unsigned long&);
    00984   extern template istream& istream::_M_extract(bool&);
    00985 #ifdef _GLIBCXX_USE_LONG_LONG
    00986   extern template istream& istream::_M_extract(long long&);
    00987   extern template istream& istream::_M_extract(unsigned long long&);
    00988 #endif
    00989   extern template istream& istream::_M_extract(float&);
    00990   extern template istream& istream::_M_extract(double&);
    00991   extern template istream& istream::_M_extract(long double&);
    00992   extern template istream& istream::_M_extract(void*&);
    00993
    00994   extern template class basic_iostream<char>;
    00995
    00996 #ifdef _GLIBCXX_USE_WCHAR_T
    00997   extern template class basic_istream<wchar_t>;
    00998   extern template wistream& ws(wistream&);
    00999   extern template wistream& operator>>(wistream&, wchar_t&);
    01000   extern template wistream& operator>>(wistream&, wchar_t*);
    01001
    01002   extern template wistream& wistream::_M_extract(unsigned short&);
    01003   extern template wistream& wistream::_M_extract(unsigned int&);
    01004   extern template wistream& wistream::_M_extract(long&);
    01005   extern template wistream& wistream::_M_extract(unsigned long&);
    01006   extern template wistream& wistream::_M_extract(bool&);
    01007 #ifdef _GLIBCXX_USE_LONG_LONG
    01008   extern template wistream& wistream::_M_extract(long long&);
    01009   extern template wistream& wistream::_M_extract(unsigned long long&);
    01010 #endif
    01011   extern template wistream& wistream::_M_extract(float&);
    01012   extern template wistream& wistream::_M_extract(double&);
    01013   extern template wistream& wistream::_M_extract(long double&);
    01014   extern template wistream& wistream::_M_extract(void*&);
    01015
    01016   extern template class basic_iostream<wchar_t>;
    01017 #endif
    01018 #endif
    01019
    01020 _GLIBCXX_END_NAMESPACE
    01021
    01022 #endif