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

Generated on Wed Dec 31 12:48:55 2008 for libstdc++ by  doxygen 1.5.6