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

Generated on Thu Nov 1 13:11:59 2007 for libstdc++ by  doxygen 1.5.1