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