# istream

Go to the documentation of this file.

    00001 // Input streams -*- C++ -*-
    00002
    00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    00004 // 2006, 2007, 2008, 2009, 2010
    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 //
    00028 // ISO C++ 14882: 27.6.1  Input streams
    00029 //
    00030
    00031 /** @file istream
    00032  *  This is a Standard C++ Library header.
    00033  */
    00034
    00035 #ifndef _GLIBCXX_ISTREAM
    00036 #define _GLIBCXX_ISTREAM 1
    00037
    00038 #pragma GCC system_header
    00039
    00040 #include <ios>
    00041 #include <ostream>
    00042
    00043 _GLIBCXX_BEGIN_NAMESPACE(std)
    00044
    00045   // [27.6.1.1] Template class basic_istream
    00046   /**
    00047    *  @brief  Controlling input.
    00048    *  @ingroup io
    00049    *
    00050    *  This is the base class for all input streams.  It provides text
    00051    *  formatting of all builtin types, and communicates with any class
    00052    *  derived from basic_streambuf to do the actual input.
    00053   */
    00054   template<typename _CharT, typename _Traits>
    00055     class basic_istream : virtual public basic_ios<_CharT, _Traits>
    00056     {
    00057     public:
    00058       // Types (inherited from basic_ios (27.4.4)):
    00059       typedef _CharT                            char_type;
    00060       typedef typename _Traits::int_type        int_type;
    00061       typedef typename _Traits::pos_type        pos_type;
    00062       typedef typename _Traits::off_type        off_type;
    00063       typedef _Traits                           traits_type;
    00064
    00065       // Non-standard Types:
    00066       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
    00067       typedef basic_ios<_CharT, _Traits>        __ios_type;
    00068       typedef basic_istream<_CharT, _Traits>        __istream_type;
    00069       typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
    00070                             __num_get_type;
    00071       typedef ctype<_CharT>                     __ctype_type;
    00072
    00073     protected:
    00074       // Data Members:
    00075       /**
    00076        *  The number of characters extracted in the previous unformatted
    00077        *  function; see gcount().
    00078       */
    00079       streamsize        _M_gcount;
    00080
    00081     public:
    00082       // [27.6.1.1.1] constructor/destructor
    00083       /**
    00084        *  @brief  Base constructor.
    00085        *
    00086        *  This ctor is almost never called by the user directly, rather from
    00087        *  derived classes' initialization lists, which pass a pointer to
    00088        *  their own stream buffer.
    00089       */
    00090       explicit
    00091       basic_istream(__streambuf_type* __sb)
    00092       : _M_gcount(streamsize(0))
    00093       { this->init(__sb); }
    00094
    00095       /**
    00096        *  @brief  Base destructor.
    00097        *
    00098        *  This does very little apart from providing a virtual base dtor.
    00099       */
    00100       virtual
    00101       ~basic_istream()
    00102       { _M_gcount = streamsize(0); }
    00103
    00104       // [27.6.1.1.2] prefix/suffix
    00105       class sentry;
    00106       friend class sentry;
    00107
    00108       // [27.6.1.2] formatted input
    00109       // [27.6.1.2.3] basic_istream::operator>>
    00110       //@{
    00111       /**
    00112        *  @brief  Interface for manipulators.
    00113        *
    00114        *  Manipulators such as @c std::ws and @c std::dec use these
    00115        *  functions in constructs like
    00116        *  <code>std::cin >> std::ws</code>.
    00117        *  For more information, see the iomanip header.
    00118       */
    00119       __istream_type&
    00120       operator>>(__istream_type& (*__pf)(__istream_type&))
    00121       { return __pf(*this); }
    00122
    00123       __istream_type&
    00124       operator>>(__ios_type& (*__pf)(__ios_type&))
    00125       {
    00126     __pf(*this);
    00127     return *this;
    00128       }
    00129
    00130       __istream_type&
    00131       operator>>(ios_base& (*__pf)(ios_base&))
    00132       {
    00133     __pf(*this);
    00134     return *this;
    00135       }
    00136       //@}
    00137
    00138       // [27.6.1.2.2] arithmetic extractors
    00139       /**
    00140        *  @name Arithmetic Extractors
    00141        *
    00142        *  All the @c operator>> functions (aka <em>formatted input
    00143        *  functions</em>) have some common behavior.  Each starts by
    00144        *  constructing a temporary object of type std::basic_istream::sentry
    00145        *  with the second argument (noskipws) set to false.  This has several
    00146        *  effects, concluding with the setting of a status flag; see the
    00147        *  sentry documentation for more.
    00148        *
    00149        *  If the sentry status is good, the function tries to extract
    00150        *  whatever data is appropriate for the type of the argument.
    00151        *
    00152        *  If an exception is thrown during extraction, ios_base::badbit
    00153        *  will be turned on in the stream's error state without causing an
    00154        *  ios_base::failure to be thrown.  The original exception will then
    00155        *  be rethrown.
    00156       */
    00157       //@{
    00158       /**
    00159        *  @brief  Basic arithmetic extractors
    00160        *  @param  A variable of builtin type.
    00161        *  @return  @c *this if successful
    00162        *
    00163        *  These functions use the stream's current locale (specifically, the
    00164        *  @c num_get facet) to parse the input data.
    00165       */
    00166       __istream_type&
    00167       operator>>(bool& __n)
    00168       { return _M_extract(__n); }
    00169
    00170       __istream_type&
    00171       operator>>(short& __n);
    00172
    00173       __istream_type&
    00174       operator>>(unsigned short& __n)
    00175       { return _M_extract(__n); }
    00176
    00177       __istream_type&
    00178       operator>>(int& __n);
    00179
    00180       __istream_type&
    00181       operator>>(unsigned int& __n)
    00182       { return _M_extract(__n); }
    00183
    00184       __istream_type&
    00185       operator>>(long& __n)
    00186       { return _M_extract(__n); }
    00187
    00188       __istream_type&
    00189       operator>>(unsigned long& __n)
    00190       { return _M_extract(__n); }
    00191
    00192 #ifdef _GLIBCXX_USE_LONG_LONG
    00193       __istream_type&
    00194       operator>>(long long& __n)
    00195       { return _M_extract(__n); }
    00196
    00197       __istream_type&
    00198       operator>>(unsigned long long& __n)
    00199       { return _M_extract(__n); }
    00200 #endif
    00201
    00202       __istream_type&
    00203       operator>>(float& __f)
    00204       { return _M_extract(__f); }
    00205
    00206       __istream_type&
    00207       operator>>(double& __f)
    00208       { return _M_extract(__f); }
    00209
    00210       __istream_type&
    00211       operator>>(long double& __f)
    00212       { return _M_extract(__f); }
    00213
    00214       __istream_type&
    00215       operator>>(void*& __p)
    00216       { return _M_extract(__p); }
    00217
    00218       /**
    00219        *  @brief  Extracting into another streambuf.
    00220        *  @param  sb  A pointer to a streambuf
    00221        *
    00222        *  This function behaves like one of the basic arithmetic extractors,
    00223        *  in that it also constructs a sentry object and has the same error
    00224        *  handling behavior.
    00225        *
    00226        *  If @a sb is NULL, the stream will set failbit in its error state.
    00227        *
    00228        *  Characters are extracted from this stream and inserted into the
    00229        *  @a sb streambuf until one of the following occurs:
    00230        *
    00231        *  - the input stream reaches end-of-file,
    00232        *  - insertion into the output buffer fails (in this case, the
    00233        *    character that would have been inserted is not extracted), or
    00234        *  - an exception occurs (and in this case is caught)
    00235        *
    00236        *  If the function inserts no characters, failbit is set.
    00237       */
    00238       __istream_type&
    00239       operator>>(__streambuf_type* __sb);
    00240       //@}
    00241
    00242       // [27.6.1.3] unformatted input
    00243       /**
    00244        *  @brief  Character counting
    00245        *  @return  The number of characters extracted by the previous
    00246        *           unformatted input function dispatched for this stream.
    00247       */
    00248       streamsize
    00249       gcount() const
    00250       { return _M_gcount; }
    00251
    00252       /**
    00253        *  @name Unformatted Input Functions
    00254        *
    00255        *  All the unformatted input functions have some common behavior.
    00256        *  Each starts by constructing a temporary object of type
    00257        *  std::basic_istream::sentry with the second argument (noskipws)
    00258        *  set to true.  This has several effects, concluding with the
    00259        *  setting of a status flag; see the sentry documentation for more.
    00260        *
    00261        *  If the sentry status is good, the function tries to extract
    00262        *  whatever data is appropriate for the type of the argument.
    00263        *
    00264        *  The number of characters extracted is stored for later retrieval
    00265        *  by gcount().
    00266        *
    00267        *  If an exception is thrown during extraction, ios_base::badbit
    00268        *  will be turned on in the stream's error state without causing an
    00269        *  ios_base::failure to be thrown.  The original exception will then
    00270        *  be rethrown.
    00271       */
    00272       //@{
    00273       /**
    00274        *  @brief  Simple extraction.
    00275        *  @return  A character, or eof().
    00276        *
    00277        *  Tries to extract a character.  If none are available, sets failbit
    00278        *  and returns traits::eof().
    00279       */
    00280       int_type
    00281       get();
    00282
    00283       /**
    00284        *  @brief  Simple extraction.
    00285        *  @param  c  The character in which to store data.
    00286        *  @return  *this
    00287        *
    00288        *  Tries to extract a character and store it in @a c.  If none are
    00289        *  available, sets failbit and returns traits::eof().
    00290        *
    00291        *  @note  This function is not overloaded on signed char and
    00292        *         unsigned char.
    00293       */
    00294       __istream_type&
    00295       get(char_type& __c);
    00296
    00297       /**
    00298        *  @brief  Simple multiple-character extraction.
    00299        *  @param  s  Pointer to an array.
    00300        *  @param  n  Maximum number of characters to store in @a s.
    00301        *  @param  delim  A "stop" character.
    00302        *  @return  *this
    00303        *
    00304        *  Characters are extracted and stored into @a s until one of the
    00305        *  following happens:
    00306        *
    00307        *  - @c n-1 characters are stored
    00308        *  - the input sequence reaches EOF
    00309        *  - the next character equals @a delim, in which case the character
    00310        *    is not extracted
    00311        *
    00312        * If no characters are stored, failbit is set in the stream's error
    00313        * state.
    00314        *
    00315        * In any case, a null character is stored into the next location in
    00316        * the array.
    00317        *
    00318        *  @note  This function is not overloaded on signed char and
    00319        *         unsigned char.
    00320       */
    00321       __istream_type&
    00322       get(char_type* __s, streamsize __n, char_type __delim);
    00323
    00324       /**
    00325        *  @brief  Simple multiple-character extraction.
    00326        *  @param  s  Pointer to an array.
    00327        *  @param  n  Maximum number of characters to store in @a s.
    00328        *  @return  *this
    00329        *
    00330        *  Returns @c get(s,n,widen(&apos;\\n&apos;)).
    00331       */
    00332       __istream_type&
    00333       get(char_type* __s, streamsize __n)
    00334       { return this->get(__s, __n, this->widen('\n')); }
    00335
    00336       /**
    00337        *  @brief  Extraction into another streambuf.
    00338        *  @param  sb  A streambuf in which to store data.
    00339        *  @param  delim  A "stop" character.
    00340        *  @return  *this
    00341        *
    00342        *  Characters are extracted and inserted into @a sb until one of the
    00343        *  following happens:
    00344        *
    00345        *  - the input sequence reaches EOF
    00346        *  - insertion into the output buffer fails (in this case, the
    00347        *    character that would have been inserted is not extracted)
    00348        *  - the next character equals @a delim (in this case, the character
    00349        *    is not extracted)
    00350        *  - an exception occurs (and in this case is caught)
    00351        *
    00352        * If no characters are stored, failbit is set in the stream's error
    00353        * state.
    00354       */
    00355       __istream_type&
    00356       get(__streambuf_type& __sb, char_type __delim);
    00357
    00358       /**
    00359        *  @brief  Extraction into another streambuf.
    00360        *  @param  sb  A streambuf in which to store data.
    00361        *  @return  *this
    00362        *
    00363        *  Returns @c get(sb,widen(&apos;\\n&apos;)).
    00364       */
    00365       __istream_type&
    00366       get(__streambuf_type& __sb)
    00367       { return this->get(__sb, this->widen('\n')); }
    00368
    00369       /**
    00370        *  @brief  String extraction.
    00371        *  @param  s  A character array in which to store the data.
    00372        *  @param  n  Maximum number of characters to extract.
    00373        *  @param  delim  A "stop" character.
    00374        *  @return  *this
    00375        *
    00376        *  Extracts and stores characters into @a s until one of the
    00377        *  following happens.  Note that these criteria are required to be
    00378        *  tested in the order listed here, to allow an input line to exactly
    00379        *  fill the @a s array without setting failbit.
    00380        *
    00381        *  -# the input sequence reaches end-of-file, in which case eofbit
    00382        *     is set in the stream error state
    00383        *  -# the next character equals @c delim, in which case the character
    00384        *     is extracted (and therefore counted in @c gcount()) but not stored
    00385        *  -# @c n-1 characters are stored, in which case failbit is set
    00386        *     in the stream error state
    00387        *
    00388        *  If no characters are extracted, failbit is set.  (An empty line of
    00389        *  input should therefore not cause failbit to be set.)
    00390        *
    00391        *  In any case, a null character is stored in the next location in
    00392        *  the array.
    00393       */
    00394       __istream_type&
    00395       getline(char_type* __s, streamsize __n, char_type __delim);
    00396
    00397       /**
    00398        *  @brief  String extraction.
    00399        *  @param  s  A character array in which to store the data.
    00400        *  @param  n  Maximum number of characters to extract.
    00401        *  @return  *this
    00402        *
    00403        *  Returns @c getline(s,n,widen(&apos;\\n&apos;)).
    00404       */
    00405       __istream_type&
    00406       getline(char_type* __s, streamsize __n)
    00407       { return this->getline(__s, __n, this->widen('\n')); }
    00408
    00409       /**
    00410        *  @brief  Discarding characters
    00411        *  @param  n  Number of characters to discard.
    00412        *  @param  delim  A "stop" character.
    00413        *  @return  *this
    00414        *
    00415        *  Extracts characters and throws them away until one of the
    00416        *  following happens:
    00417        *  - if @a n @c != @c std::numeric_limits<int>::max(), @a n
    00418        *    characters are extracted
    00419        *  - the input sequence reaches end-of-file
    00420        *  - the next character equals @a delim (in this case, the character
    00421        *    is extracted); note that this condition will never occur if
    00422        *    @a delim equals @c traits::eof().
    00423        *
    00424        *  NB: Provide three overloads, instead of the single function
    00425        *  (with defaults) mandated by the Standard: this leads to a
    00426        *  better performing implementation, while still conforming to
    00427        *  the Standard.
    00428       */
    00429       __istream_type&
    00430       ignore();
    00431
    00432       __istream_type&
    00433       ignore(streamsize __n);
    00434
    00435       __istream_type&
    00436       ignore(streamsize __n, int_type __delim);
    00437
    00438       /**
    00439        *  @brief  Looking ahead in the stream
    00440        *  @return  The next character, or eof().
    00441        *
    00442        *  If, after constructing the sentry object, @c good() is false,
    00443        *  returns @c traits::eof().  Otherwise reads but does not extract
    00444        *  the next input character.
    00445       */
    00446       int_type
    00447       peek();
    00448
    00449       /**
    00450        *  @brief  Extraction without delimiters.
    00451        *  @param  s  A character array.
    00452        *  @param  n  Maximum number of characters to store.
    00453        *  @return  *this
    00454        *
    00455        *  If the stream state is @c good(), extracts characters and stores
    00456        *  them into @a s until one of the following happens:
    00457        *  - @a n characters are stored
    00458        *  - the input sequence reaches end-of-file, in which case the error
    00459        *    state is set to @c failbit|eofbit.
    00460        *
    00461        *  @note  This function is not overloaded on signed char and
    00462        *         unsigned char.
    00463       */
    00464       __istream_type&
    00465       read(char_type* __s, streamsize __n);
    00466
    00467       /**
    00468        *  @brief  Extraction until the buffer is exhausted, but no more.
    00469        *  @param  s  A character array.
    00470        *  @param  n  Maximum number of characters to store.
    00471        *  @return  The number of characters extracted.
    00472        *
    00473        *  Extracts characters and stores them into @a s depending on the
    00474        *  number of characters remaining in the streambuf's buffer,
    00475        *  @c rdbuf()->in_avail(), called @c A here:
    00476        *  - if @c A @c == @c -1, sets eofbit and extracts no characters
    00477        *  - if @c A @c == @c 0, extracts no characters
    00478        *  - if @c A @c > @c 0, extracts @c min(A,n)
    00479        *
    00480        *  The goal is to empty the current buffer, and to not request any
    00481        *  more from the external input sequence controlled by the streambuf.
    00482       */
    00483       streamsize
    00484       readsome(char_type* __s, streamsize __n);
    00485
    00486       /**
    00487        *  @brief  Unextracting a single character.
    00488        *  @param  c  The character to push back into the input stream.
    00489        *  @return  *this
    00490        *
    00491        *  If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c).
    00492        *
    00493        *  If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in
    00494        *  the error state.
    00495        *
    00496        *  @note  Since no characters are extracted, the next call to
    00497        *         @c gcount() will return 0, as required by DR 60.
    00498       */
    00499       __istream_type&
    00500       putback(char_type __c);
    00501
    00502       /**
    00503        *  @brief  Unextracting the previous character.
    00504        *  @return  *this
    00505        *
    00506        *  If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c).
    00507        *
    00508        *  If @c rdbuf() is null or if @c sungetc() fails, sets badbit in
    00509        *  the error state.
    00510        *
    00511        *  @note  Since no characters are extracted, the next call to
    00512        *         @c gcount() will return 0, as required by DR 60.
    00513       */
    00514       __istream_type&
    00515       unget();
    00516
    00517       /**
    00518        *  @brief  Synchronizing the stream buffer.
    00519        *  @return  0 on success, -1 on failure
    00520        *
    00521        *  If @c rdbuf() is a null pointer, returns -1.
    00522        *
    00523        *  Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1,
    00524        *  sets badbit and returns -1.
    00525        *
    00526        *  Otherwise, returns 0.
    00527        *
    00528        *  @note  This function does not count the number of characters
    00529        *         extracted, if any, and therefore does not affect the next
    00530        *         call to @c gcount().
    00531       */
    00532       int
    00533       sync();
    00534
    00535       /**
    00536        *  @brief  Getting the current read position.
    00537        *  @return  A file position object.
    00538        *
    00539        *  If @c fail() is not false, returns @c pos_type(-1) to indicate
    00540        *  failure.  Otherwise returns @c rdbuf()->pubseekoff(0,cur,in).
    00541        *
    00542        *  @note  This function does not count the number of characters
    00543        *         extracted, if any, and therefore does not affect the next
    00544        *         call to @c gcount().
    00545       */
    00546       pos_type
    00547       tellg();
    00548
    00549       /**
    00550        *  @brief  Changing the current read position.
    00551        *  @param  pos  A file position object.
    00552        *  @return  *this
    00553        *
    00554        *  If @c fail() is not true, calls @c rdbuf()->pubseekpos(pos).  If
    00555        *  that function fails, sets failbit.
    00556        *
    00557        *  @note  This function does not count the number of characters
    00558        *         extracted, if any, and therefore does not affect the next
    00559        *         call to @c gcount().
    00560       */
    00561       __istream_type&
    00562       seekg(pos_type);
    00563
    00564       /**
    00565        *  @brief  Changing the current read position.
    00566        *  @param  off  A file offset object.
    00567        *  @param  dir  The direction in which to seek.
    00568        *  @return  *this
    00569        *
    00570        *  If @c fail() is not true, calls @c rdbuf()->pubseekoff(off,dir).
    00571        *  If that function fails, sets failbit.
    00572        *
    00573        *  @note  This function does not count the number of characters
    00574        *         extracted, if any, and therefore does not affect the next
    00575        *         call to @c gcount().
    00576       */
    00577       __istream_type&
    00578       seekg(off_type, ios_base::seekdir);
    00579       //@}
    00580
    00581     protected:
    00582       basic_istream()
    00583       : _M_gcount(streamsize(0))
    00584       { this->init(0); }
    00585
    00586       template<typename _ValueT>
    00587         __istream_type&
    00588         _M_extract(_ValueT& __v);
    00589     };
    00590
    00591   // Explicit specialization declarations, defined in src/istream.cc.
    00592   template<>
    00593     basic_istream<char>&
    00594     basic_istream<char>::
    00595     getline(char_type* __s, streamsize __n, char_type __delim);
    00596
    00597   template<>
    00598     basic_istream<char>&
    00599     basic_istream<char>::
    00600     ignore(streamsize __n);
    00601
    00602   template<>
    00603     basic_istream<char>&
    00604     basic_istream<char>::
    00605     ignore(streamsize __n, int_type __delim);
    00606
    00607 #ifdef _GLIBCXX_USE_WCHAR_T
    00608   template<>
    00609     basic_istream<wchar_t>&
    00610     basic_istream<wchar_t>::
    00611     getline(char_type* __s, streamsize __n, char_type __delim);
    00612
    00613   template<>
    00614     basic_istream<wchar_t>&
    00615     basic_istream<wchar_t>::
    00616     ignore(streamsize __n);
    00617
    00618   template<>
    00619     basic_istream<wchar_t>&
    00620     basic_istream<wchar_t>::
    00621     ignore(streamsize __n, int_type __delim);
    00622 #endif
    00623
    00624   /**
    00625    *  @brief  Performs setup work for input streams.
    00626    *
    00627    *  Objects of this class are created before all of the standard
    00628    *  extractors are run.  It is responsible for <em>exception-safe
    00629    *  prefix and suffix operations,</em> although only prefix actions
    00630    *  are currently required by the standard.
    00631   */
    00632   template<typename _CharT, typename _Traits>
    00633     class basic_istream<_CharT, _Traits>::sentry
    00634     {
    00635       // Data Members.
    00636       bool _M_ok;
    00637
    00638     public:
    00639       /// Easy access to dependant types.
    00640       typedef _Traits                   traits_type;
    00641       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
    00642       typedef basic_istream<_CharT, _Traits>        __istream_type;
    00643       typedef typename __istream_type::__ctype_type     __ctype_type;
    00644       typedef typename _Traits::int_type        __int_type;
    00645
    00646       /**
    00647        *  @brief  The constructor performs all the work.
    00648        *  @param  is  The input stream to guard.
    00649        *  @param  noskipws  Whether to consume whitespace or not.
    00650        *
    00651        *  If the stream state is good (@a is.good() is true), then the
    00652        *  following actions are performed, otherwise the sentry state
    00653        *  is false (<em>not okay</em>) and failbit is set in the
    00654        *  stream state.
    00655        *
    00656        *  The sentry's preparatory actions are:
    00657        *
    00658        *  -# if the stream is tied to an output stream, @c is.tie()->flush()
    00659        *     is called to synchronize the output sequence
    00660        *  -# if @a noskipws is false, and @c ios_base::skipws is set in
    00661        *     @c is.flags(), the sentry extracts and discards whitespace
    00662        *     characters from the stream.  The currently imbued locale is
    00663        *     used to determine whether each character is whitespace.
    00664        *
    00665        *  If the stream state is still good, then the sentry state becomes
    00666        *  true (@a okay).
    00667       */
    00668       explicit
    00669       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
    00670
    00671       /**
    00672        *  @brief  Quick status checking.
    00673        *  @return  The sentry state.
    00674        *
    00675        *  For ease of use, sentries may be converted to booleans.  The
    00676        *  return value is that of the sentry state (true == okay).
    00677       */
    00678 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00679       explicit
    00680 #endif
    00681       operator bool() const
    00682       { return _M_ok; }
    00683     };
    00684
    00685   // [27.6.1.2.3] character extraction templates
    00686   //@{
    00687   /**
    00688    *  @brief  Character extractors
    00689    *  @param  in  An input stream.
    00690    *  @param  c  A character reference.
    00691    *  @return  in
    00692    *
    00693    *  Behaves like one of the formatted arithmetic extractors described in
    00694    *  std::basic_istream.  After constructing a sentry object with good
    00695    *  status, this function extracts a character (if one is available) and
    00696    *  stores it in @a c.  Otherwise, sets failbit in the input stream.
    00697   */
    00698   template<typename _CharT, typename _Traits>
    00699     basic_istream<_CharT, _Traits>&
    00700     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
    00701
    00702   template<class _Traits>
    00703     inline basic_istream<char, _Traits>&
    00704     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
    00705     { return (__in >> reinterpret_cast<char&>(__c)); }
    00706
    00707   template<class _Traits>
    00708     inline basic_istream<char, _Traits>&
    00709     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
    00710     { return (__in >> reinterpret_cast<char&>(__c)); }
    00711   //@}
    00712
    00713   //@{
    00714   /**
    00715    *  @brief  Character string extractors
    00716    *  @param  in  An input stream.
    00717    *  @param  s  A pointer to a character array.
    00718    *  @return  in
    00719    *
    00720    *  Behaves like one of the formatted arithmetic extractors described in
    00721    *  std::basic_istream.  After constructing a sentry object with good
    00722    *  status, this function extracts up to @c n characters and stores them
    00723    *  into the array starting at @a s.  @c n is defined as:
    00724    *
    00725    *  - if @c width() is greater than zero, @c n is width() otherwise
    00726    *  - @c n is <em>the number of elements of the largest array of *
    00727    *  - @c char_type that can store a terminating @c eos.</em>
    00728    *  - [27.6.1.2.3]/6
    00729    *
    00730    *  Characters are extracted and stored until one of the following happens:
    00731    *  - @c n-1 characters are stored
    00732    *  - EOF is reached
    00733    *  - the next character is whitespace according to the current locale
    00734    *  - the next character is a null byte (i.e., @c charT() )
    00735    *
    00736    *  @c width(0) is then called for the input stream.
    00737    *
    00738    *  If no characters are extracted, sets failbit.
    00739   */
    00740   template<typename _CharT, typename _Traits>
    00741     basic_istream<_CharT, _Traits>&
    00742     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
    00743
    00744   // Explicit specialization declaration, defined in src/istream.cc.
    00745   template<>
    00746     basic_istream<char>&
    00747     operator>>(basic_istream<char>& __in, char* __s);
    00748
    00749   template<class _Traits>
    00750     inline basic_istream<char, _Traits>&
    00751     operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
    00752     { return (__in >> reinterpret_cast<char*>(__s)); }
    00753
    00754   template<class _Traits>
    00755     inline basic_istream<char, _Traits>&
    00756     operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
    00757     { return (__in >> reinterpret_cast<char*>(__s)); }
    00758   //@}
    00759
    00760   // 27.6.1.5 Template class basic_iostream
    00761   /**
    00762    *  @brief  Merging istream and ostream capabilities.
    00763    *  @ingroup io
    00764    *
    00765    *  This class multiply inherits from the input and output stream classes
    00766    *  simply to provide a single interface.
    00767   */
    00768   template<typename _CharT, typename _Traits>
    00769     class basic_iostream
    00770     : public basic_istream<_CharT, _Traits>,
    00771       public basic_ostream<_CharT, _Traits>
    00772     {
    00773     public:
    00774       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00775       // 271. basic_iostream missing typedefs
    00776       // Types (inherited):
    00777       typedef _CharT                            char_type;
    00778       typedef typename _Traits::int_type        int_type;
    00779       typedef typename _Traits::pos_type        pos_type;
    00780       typedef typename _Traits::off_type        off_type;
    00781       typedef _Traits                           traits_type;
    00782
    00783       // Non-standard Types:
    00784       typedef basic_istream<_CharT, _Traits>        __istream_type;
    00785       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
    00786
    00787       /**
    00788        *  @brief  Constructor does nothing.
    00789        *
    00790        *  Both of the parent classes are initialized with the same
    00791        *  streambuf pointer passed to this constructor.
    00792       */
    00793       explicit
    00794       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
    00795       : __istream_type(__sb), __ostream_type(__sb) { }
    00796
    00797       /**
    00798        *  @brief  Destructor does nothing.
    00799       */
    00800       virtual
    00801       ~basic_iostream() { }
    00802
    00803     protected:
    00804       basic_iostream()
    00805       : __istream_type(), __ostream_type() { }
    00806     };
    00807
    00808   // [27.6.1.4] standard basic_istream manipulators
    00809   /**
    00810    *  @brief  Quick and easy way to eat whitespace
    00811    *
    00812    *  This manipulator extracts whitespace characters, stopping when the
    00813    *  next character is non-whitespace, or when the input sequence is empty.
    00814    *  If the sequence is empty, @c eofbit is set in the stream, but not
    00815    *  @c failbit.
    00816    *
    00817    *  The current locale is used to distinguish whitespace characters.
    00818    *
    00819    *  Example:
    00820    *  @code
    00821    *     MyClass   mc;
    00822    *
    00823    *     std::cin >> std::ws >> mc;
    00824    *  @endcode
    00825    *  will skip leading whitespace before calling operator>> on cin and your
    00826    *  object.  Note that the same effect can be achieved by creating a
    00827    *  std::basic_istream::sentry inside your definition of operator>>.
    00828   */
    00829   template<typename _CharT, typename _Traits>
    00830     basic_istream<_CharT, _Traits>&
    00831     ws(basic_istream<_CharT, _Traits>& __is);
    00832
    00833 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00834   // [27.7.1.6] Rvalue stream extraction
    00835   /**
    00836    *  @brief  Generic extractor for rvalue stream
    00837    *  @param  is  An input stream.
    00838    *  @param  x  A reference to the extraction target.
    00839    *  @return  is
    00840    *
    00841    *  This is just a forwarding function to allow extraction from
    00842    *  rvalue streams since they won't bind to the extractor functions
    00843    *  that take an lvalue reference.
    00844   */
    00845   template<typename _CharT, typename _Traits, typename _Tp>
    00846     inline basic_istream<_CharT, _Traits>&
    00847     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
    00848     { return (__is >> __x); }
    00849 #endif // __GXX_EXPERIMENTAL_CXX0X__
    00850
    00851 _GLIBCXX_END_NAMESPACE
    00852
    00853 #ifndef _GLIBCXX_EXPORT_TEMPLATE
    00854 # include <bits/istream.tcc>
    00855 #endif
    00856
    00857 #endif  /* _GLIBCXX_ISTREAM */