1*e4b17023SJohn Marino// Input streams -*- C++ -*- 2*e4b17023SJohn Marino 3*e4b17023SJohn Marino// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 4*e4b17023SJohn Marino// 2006, 2007, 2008, 2009, 2010, 2011 5*e4b17023SJohn Marino// Free Software Foundation, Inc. 6*e4b17023SJohn Marino// 7*e4b17023SJohn Marino// This file is part of the GNU ISO C++ Library. This library is free 8*e4b17023SJohn Marino// software; you can redistribute it and/or modify it under the 9*e4b17023SJohn Marino// terms of the GNU General Public License as published by the 10*e4b17023SJohn Marino// Free Software Foundation; either version 3, or (at your option) 11*e4b17023SJohn Marino// any later version. 12*e4b17023SJohn Marino 13*e4b17023SJohn Marino// This library is distributed in the hope that it will be useful, 14*e4b17023SJohn Marino// but WITHOUT ANY WARRANTY; without even the implied warranty of 15*e4b17023SJohn Marino// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*e4b17023SJohn Marino// GNU General Public License for more details. 17*e4b17023SJohn Marino 18*e4b17023SJohn Marino// Under Section 7 of GPL version 3, you are granted additional 19*e4b17023SJohn Marino// permissions described in the GCC Runtime Library Exception, version 20*e4b17023SJohn Marino// 3.1, as published by the Free Software Foundation. 21*e4b17023SJohn Marino 22*e4b17023SJohn Marino// You should have received a copy of the GNU General Public License and 23*e4b17023SJohn Marino// a copy of the GCC Runtime Library Exception along with this program; 24*e4b17023SJohn Marino// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 25*e4b17023SJohn Marino// <http://www.gnu.org/licenses/>. 26*e4b17023SJohn Marino 27*e4b17023SJohn Marino// 28*e4b17023SJohn Marino// ISO C++ 14882: 27.6.1 Input streams 29*e4b17023SJohn Marino// 30*e4b17023SJohn Marino 31*e4b17023SJohn Marino/** @file include/istream 32*e4b17023SJohn Marino * This is a Standard C++ Library header. 33*e4b17023SJohn Marino */ 34*e4b17023SJohn Marino 35*e4b17023SJohn Marino#ifndef _GLIBCXX_ISTREAM 36*e4b17023SJohn Marino#define _GLIBCXX_ISTREAM 1 37*e4b17023SJohn Marino 38*e4b17023SJohn Marino#pragma GCC system_header 39*e4b17023SJohn Marino 40*e4b17023SJohn Marino#include <ios> 41*e4b17023SJohn Marino#include <ostream> 42*e4b17023SJohn Marino 43*e4b17023SJohn Marinonamespace std _GLIBCXX_VISIBILITY(default) 44*e4b17023SJohn Marino{ 45*e4b17023SJohn Marino_GLIBCXX_BEGIN_NAMESPACE_VERSION 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino /** 48*e4b17023SJohn Marino * @brief Template class basic_istream. 49*e4b17023SJohn Marino * @ingroup io 50*e4b17023SJohn Marino * 51*e4b17023SJohn Marino * This is the base class for all input streams. It provides text 52*e4b17023SJohn Marino * formatting of all builtin types, and communicates with any class 53*e4b17023SJohn Marino * derived from basic_streambuf to do the actual input. 54*e4b17023SJohn Marino */ 55*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 56*e4b17023SJohn Marino class basic_istream : virtual public basic_ios<_CharT, _Traits> 57*e4b17023SJohn Marino { 58*e4b17023SJohn Marino public: 59*e4b17023SJohn Marino // Types (inherited from basic_ios (27.4.4)): 60*e4b17023SJohn Marino typedef _CharT char_type; 61*e4b17023SJohn Marino typedef typename _Traits::int_type int_type; 62*e4b17023SJohn Marino typedef typename _Traits::pos_type pos_type; 63*e4b17023SJohn Marino typedef typename _Traits::off_type off_type; 64*e4b17023SJohn Marino typedef _Traits traits_type; 65*e4b17023SJohn Marino 66*e4b17023SJohn Marino // Non-standard Types: 67*e4b17023SJohn Marino typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 68*e4b17023SJohn Marino typedef basic_ios<_CharT, _Traits> __ios_type; 69*e4b17023SJohn Marino typedef basic_istream<_CharT, _Traits> __istream_type; 70*e4b17023SJohn Marino typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > 71*e4b17023SJohn Marino __num_get_type; 72*e4b17023SJohn Marino typedef ctype<_CharT> __ctype_type; 73*e4b17023SJohn Marino 74*e4b17023SJohn Marino protected: 75*e4b17023SJohn Marino // Data Members: 76*e4b17023SJohn Marino /** 77*e4b17023SJohn Marino * The number of characters extracted in the previous unformatted 78*e4b17023SJohn Marino * function; see gcount(). 79*e4b17023SJohn Marino */ 80*e4b17023SJohn Marino streamsize _M_gcount; 81*e4b17023SJohn Marino 82*e4b17023SJohn Marino public: 83*e4b17023SJohn Marino /** 84*e4b17023SJohn Marino * @brief Base constructor. 85*e4b17023SJohn Marino * 86*e4b17023SJohn Marino * This ctor is almost never called by the user directly, rather from 87*e4b17023SJohn Marino * derived classes' initialization lists, which pass a pointer to 88*e4b17023SJohn Marino * their own stream buffer. 89*e4b17023SJohn Marino */ 90*e4b17023SJohn Marino explicit 91*e4b17023SJohn Marino basic_istream(__streambuf_type* __sb) 92*e4b17023SJohn Marino : _M_gcount(streamsize(0)) 93*e4b17023SJohn Marino { this->init(__sb); } 94*e4b17023SJohn Marino 95*e4b17023SJohn Marino /** 96*e4b17023SJohn Marino * @brief Base destructor. 97*e4b17023SJohn Marino * 98*e4b17023SJohn Marino * This does very little apart from providing a virtual base dtor. 99*e4b17023SJohn Marino */ 100*e4b17023SJohn Marino virtual 101*e4b17023SJohn Marino ~basic_istream() 102*e4b17023SJohn Marino { _M_gcount = streamsize(0); } 103*e4b17023SJohn Marino 104*e4b17023SJohn Marino /// Safe prefix/suffix operations. 105*e4b17023SJohn Marino class sentry; 106*e4b17023SJohn Marino friend class sentry; 107*e4b17023SJohn Marino 108*e4b17023SJohn Marino //@{ 109*e4b17023SJohn Marino /** 110*e4b17023SJohn Marino * @brief Interface for manipulators. 111*e4b17023SJohn Marino * 112*e4b17023SJohn Marino * Manipulators such as @c std::ws and @c std::dec use these 113*e4b17023SJohn Marino * functions in constructs like 114*e4b17023SJohn Marino * <code>std::cin >> std::ws</code>. 115*e4b17023SJohn Marino * For more information, see the iomanip header. 116*e4b17023SJohn Marino */ 117*e4b17023SJohn Marino __istream_type& 118*e4b17023SJohn Marino operator>>(__istream_type& (*__pf)(__istream_type&)) 119*e4b17023SJohn Marino { return __pf(*this); } 120*e4b17023SJohn Marino 121*e4b17023SJohn Marino __istream_type& 122*e4b17023SJohn Marino operator>>(__ios_type& (*__pf)(__ios_type&)) 123*e4b17023SJohn Marino { 124*e4b17023SJohn Marino __pf(*this); 125*e4b17023SJohn Marino return *this; 126*e4b17023SJohn Marino } 127*e4b17023SJohn Marino 128*e4b17023SJohn Marino __istream_type& 129*e4b17023SJohn Marino operator>>(ios_base& (*__pf)(ios_base&)) 130*e4b17023SJohn Marino { 131*e4b17023SJohn Marino __pf(*this); 132*e4b17023SJohn Marino return *this; 133*e4b17023SJohn Marino } 134*e4b17023SJohn Marino //@} 135*e4b17023SJohn Marino 136*e4b17023SJohn Marino //@{ 137*e4b17023SJohn Marino /** 138*e4b17023SJohn Marino * @name Extractors 139*e4b17023SJohn Marino * 140*e4b17023SJohn Marino * All the @c operator>> functions (aka <em>formatted input 141*e4b17023SJohn Marino * functions</em>) have some common behavior. Each starts by 142*e4b17023SJohn Marino * constructing a temporary object of type std::basic_istream::sentry 143*e4b17023SJohn Marino * with the second argument (noskipws) set to false. This has several 144*e4b17023SJohn Marino * effects, concluding with the setting of a status flag; see the 145*e4b17023SJohn Marino * sentry documentation for more. 146*e4b17023SJohn Marino * 147*e4b17023SJohn Marino * If the sentry status is good, the function tries to extract 148*e4b17023SJohn Marino * whatever data is appropriate for the type of the argument. 149*e4b17023SJohn Marino * 150*e4b17023SJohn Marino * If an exception is thrown during extraction, ios_base::badbit 151*e4b17023SJohn Marino * will be turned on in the stream's error state without causing an 152*e4b17023SJohn Marino * ios_base::failure to be thrown. The original exception will then 153*e4b17023SJohn Marino * be rethrown. 154*e4b17023SJohn Marino */ 155*e4b17023SJohn Marino 156*e4b17023SJohn Marino //@{ 157*e4b17023SJohn Marino /** 158*e4b17023SJohn Marino * @brief Integer arithmetic extractors 159*e4b17023SJohn Marino * @param __n A variable of builtin integral type. 160*e4b17023SJohn Marino * @return @c *this if successful 161*e4b17023SJohn Marino * 162*e4b17023SJohn Marino * These functions use the stream's current locale (specifically, the 163*e4b17023SJohn Marino * @c num_get facet) to parse the input data. 164*e4b17023SJohn Marino */ 165*e4b17023SJohn Marino __istream_type& 166*e4b17023SJohn Marino operator>>(bool& __n) 167*e4b17023SJohn Marino { return _M_extract(__n); } 168*e4b17023SJohn Marino 169*e4b17023SJohn Marino __istream_type& 170*e4b17023SJohn Marino operator>>(short& __n); 171*e4b17023SJohn Marino 172*e4b17023SJohn Marino __istream_type& 173*e4b17023SJohn Marino operator>>(unsigned short& __n) 174*e4b17023SJohn Marino { return _M_extract(__n); } 175*e4b17023SJohn Marino 176*e4b17023SJohn Marino __istream_type& 177*e4b17023SJohn Marino operator>>(int& __n); 178*e4b17023SJohn Marino 179*e4b17023SJohn Marino __istream_type& 180*e4b17023SJohn Marino operator>>(unsigned int& __n) 181*e4b17023SJohn Marino { return _M_extract(__n); } 182*e4b17023SJohn Marino 183*e4b17023SJohn Marino __istream_type& 184*e4b17023SJohn Marino operator>>(long& __n) 185*e4b17023SJohn Marino { return _M_extract(__n); } 186*e4b17023SJohn Marino 187*e4b17023SJohn Marino __istream_type& 188*e4b17023SJohn Marino operator>>(unsigned long& __n) 189*e4b17023SJohn Marino { return _M_extract(__n); } 190*e4b17023SJohn Marino 191*e4b17023SJohn Marino#ifdef _GLIBCXX_USE_LONG_LONG 192*e4b17023SJohn Marino __istream_type& 193*e4b17023SJohn Marino operator>>(long long& __n) 194*e4b17023SJohn Marino { return _M_extract(__n); } 195*e4b17023SJohn Marino 196*e4b17023SJohn Marino __istream_type& 197*e4b17023SJohn Marino operator>>(unsigned long long& __n) 198*e4b17023SJohn Marino { return _M_extract(__n); } 199*e4b17023SJohn Marino#endif 200*e4b17023SJohn Marino //@} 201*e4b17023SJohn Marino 202*e4b17023SJohn Marino //@{ 203*e4b17023SJohn Marino /** 204*e4b17023SJohn Marino * @brief Floating point arithmetic extractors 205*e4b17023SJohn Marino * @param __f A variable of builtin floating point type. 206*e4b17023SJohn Marino * @return @c *this if successful 207*e4b17023SJohn Marino * 208*e4b17023SJohn Marino * These functions use the stream's current locale (specifically, the 209*e4b17023SJohn Marino * @c num_get facet) to parse the input data. 210*e4b17023SJohn Marino */ 211*e4b17023SJohn Marino __istream_type& 212*e4b17023SJohn Marino operator>>(float& __f) 213*e4b17023SJohn Marino { return _M_extract(__f); } 214*e4b17023SJohn Marino 215*e4b17023SJohn Marino __istream_type& 216*e4b17023SJohn Marino operator>>(double& __f) 217*e4b17023SJohn Marino { return _M_extract(__f); } 218*e4b17023SJohn Marino 219*e4b17023SJohn Marino __istream_type& 220*e4b17023SJohn Marino operator>>(long double& __f) 221*e4b17023SJohn Marino { return _M_extract(__f); } 222*e4b17023SJohn Marino //@} 223*e4b17023SJohn Marino 224*e4b17023SJohn Marino /** 225*e4b17023SJohn Marino * @brief Basic arithmetic extractors 226*e4b17023SJohn Marino * @param __p A variable of pointer type. 227*e4b17023SJohn Marino * @return @c *this if successful 228*e4b17023SJohn Marino * 229*e4b17023SJohn Marino * These functions use the stream's current locale (specifically, the 230*e4b17023SJohn Marino * @c num_get facet) to parse the input data. 231*e4b17023SJohn Marino */ 232*e4b17023SJohn Marino __istream_type& 233*e4b17023SJohn Marino operator>>(void*& __p) 234*e4b17023SJohn Marino { return _M_extract(__p); } 235*e4b17023SJohn Marino 236*e4b17023SJohn Marino /** 237*e4b17023SJohn Marino * @brief Extracting into another streambuf. 238*e4b17023SJohn Marino * @param __sb A pointer to a streambuf 239*e4b17023SJohn Marino * 240*e4b17023SJohn Marino * This function behaves like one of the basic arithmetic extractors, 241*e4b17023SJohn Marino * in that it also constructs a sentry object and has the same error 242*e4b17023SJohn Marino * handling behavior. 243*e4b17023SJohn Marino * 244*e4b17023SJohn Marino * If @p __sb is NULL, the stream will set failbit in its error state. 245*e4b17023SJohn Marino * 246*e4b17023SJohn Marino * Characters are extracted from this stream and inserted into the 247*e4b17023SJohn Marino * @p __sb streambuf until one of the following occurs: 248*e4b17023SJohn Marino * 249*e4b17023SJohn Marino * - the input stream reaches end-of-file, 250*e4b17023SJohn Marino * - insertion into the output buffer fails (in this case, the 251*e4b17023SJohn Marino * character that would have been inserted is not extracted), or 252*e4b17023SJohn Marino * - an exception occurs (and in this case is caught) 253*e4b17023SJohn Marino * 254*e4b17023SJohn Marino * If the function inserts no characters, failbit is set. 255*e4b17023SJohn Marino */ 256*e4b17023SJohn Marino __istream_type& 257*e4b17023SJohn Marino operator>>(__streambuf_type* __sb); 258*e4b17023SJohn Marino //@} 259*e4b17023SJohn Marino 260*e4b17023SJohn Marino // [27.6.1.3] unformatted input 261*e4b17023SJohn Marino /** 262*e4b17023SJohn Marino * @brief Character counting 263*e4b17023SJohn Marino * @return The number of characters extracted by the previous 264*e4b17023SJohn Marino * unformatted input function dispatched for this stream. 265*e4b17023SJohn Marino */ 266*e4b17023SJohn Marino streamsize 267*e4b17023SJohn Marino gcount() const 268*e4b17023SJohn Marino { return _M_gcount; } 269*e4b17023SJohn Marino 270*e4b17023SJohn Marino //@{ 271*e4b17023SJohn Marino /** 272*e4b17023SJohn Marino * @name Unformatted Input Functions 273*e4b17023SJohn Marino * 274*e4b17023SJohn Marino * All the unformatted input functions have some common behavior. 275*e4b17023SJohn Marino * Each starts by constructing a temporary object of type 276*e4b17023SJohn Marino * std::basic_istream::sentry with the second argument (noskipws) 277*e4b17023SJohn Marino * set to true. This has several effects, concluding with the 278*e4b17023SJohn Marino * setting of a status flag; see the sentry documentation for more. 279*e4b17023SJohn Marino * 280*e4b17023SJohn Marino * If the sentry status is good, the function tries to extract 281*e4b17023SJohn Marino * whatever data is appropriate for the type of the argument. 282*e4b17023SJohn Marino * 283*e4b17023SJohn Marino * The number of characters extracted is stored for later retrieval 284*e4b17023SJohn Marino * by gcount(). 285*e4b17023SJohn Marino * 286*e4b17023SJohn Marino * If an exception is thrown during extraction, ios_base::badbit 287*e4b17023SJohn Marino * will be turned on in the stream's error state without causing an 288*e4b17023SJohn Marino * ios_base::failure to be thrown. The original exception will then 289*e4b17023SJohn Marino * be rethrown. 290*e4b17023SJohn Marino */ 291*e4b17023SJohn Marino 292*e4b17023SJohn Marino /** 293*e4b17023SJohn Marino * @brief Simple extraction. 294*e4b17023SJohn Marino * @return A character, or eof(). 295*e4b17023SJohn Marino * 296*e4b17023SJohn Marino * Tries to extract a character. If none are available, sets failbit 297*e4b17023SJohn Marino * and returns traits::eof(). 298*e4b17023SJohn Marino */ 299*e4b17023SJohn Marino int_type 300*e4b17023SJohn Marino get(); 301*e4b17023SJohn Marino 302*e4b17023SJohn Marino /** 303*e4b17023SJohn Marino * @brief Simple extraction. 304*e4b17023SJohn Marino * @param __c The character in which to store data. 305*e4b17023SJohn Marino * @return *this 306*e4b17023SJohn Marino * 307*e4b17023SJohn Marino * Tries to extract a character and store it in @a __c. If none are 308*e4b17023SJohn Marino * available, sets failbit and returns traits::eof(). 309*e4b17023SJohn Marino * 310*e4b17023SJohn Marino * @note This function is not overloaded on signed char and 311*e4b17023SJohn Marino * unsigned char. 312*e4b17023SJohn Marino */ 313*e4b17023SJohn Marino __istream_type& 314*e4b17023SJohn Marino get(char_type& __c); 315*e4b17023SJohn Marino 316*e4b17023SJohn Marino /** 317*e4b17023SJohn Marino * @brief Simple multiple-character extraction. 318*e4b17023SJohn Marino * @param __s Pointer to an array. 319*e4b17023SJohn Marino * @param __n Maximum number of characters to store in @a __s. 320*e4b17023SJohn Marino * @param __delim A "stop" character. 321*e4b17023SJohn Marino * @return *this 322*e4b17023SJohn Marino * 323*e4b17023SJohn Marino * Characters are extracted and stored into @a __s until one of the 324*e4b17023SJohn Marino * following happens: 325*e4b17023SJohn Marino * 326*e4b17023SJohn Marino * - @c __n-1 characters are stored 327*e4b17023SJohn Marino * - the input sequence reaches EOF 328*e4b17023SJohn Marino * - the next character equals @a __delim, in which case the character 329*e4b17023SJohn Marino * is not extracted 330*e4b17023SJohn Marino * 331*e4b17023SJohn Marino * If no characters are stored, failbit is set in the stream's error 332*e4b17023SJohn Marino * state. 333*e4b17023SJohn Marino * 334*e4b17023SJohn Marino * In any case, a null character is stored into the next location in 335*e4b17023SJohn Marino * the array. 336*e4b17023SJohn Marino * 337*e4b17023SJohn Marino * @note This function is not overloaded on signed char and 338*e4b17023SJohn Marino * unsigned char. 339*e4b17023SJohn Marino */ 340*e4b17023SJohn Marino __istream_type& 341*e4b17023SJohn Marino get(char_type* __s, streamsize __n, char_type __delim); 342*e4b17023SJohn Marino 343*e4b17023SJohn Marino /** 344*e4b17023SJohn Marino * @brief Simple multiple-character extraction. 345*e4b17023SJohn Marino * @param __s Pointer to an array. 346*e4b17023SJohn Marino * @param __n Maximum number of characters to store in @a s. 347*e4b17023SJohn Marino * @return *this 348*e4b17023SJohn Marino * 349*e4b17023SJohn Marino * Returns @c get(__s,__n,widen('\\n')). 350*e4b17023SJohn Marino */ 351*e4b17023SJohn Marino __istream_type& 352*e4b17023SJohn Marino get(char_type* __s, streamsize __n) 353*e4b17023SJohn Marino { return this->get(__s, __n, this->widen('\n')); } 354*e4b17023SJohn Marino 355*e4b17023SJohn Marino /** 356*e4b17023SJohn Marino * @brief Extraction into another streambuf. 357*e4b17023SJohn Marino * @param __sb A streambuf in which to store data. 358*e4b17023SJohn Marino * @param __delim A "stop" character. 359*e4b17023SJohn Marino * @return *this 360*e4b17023SJohn Marino * 361*e4b17023SJohn Marino * Characters are extracted and inserted into @a __sb until one of the 362*e4b17023SJohn Marino * following happens: 363*e4b17023SJohn Marino * 364*e4b17023SJohn Marino * - the input sequence reaches EOF 365*e4b17023SJohn Marino * - insertion into the output buffer fails (in this case, the 366*e4b17023SJohn Marino * character that would have been inserted is not extracted) 367*e4b17023SJohn Marino * - the next character equals @a __delim (in this case, the character 368*e4b17023SJohn Marino * is not extracted) 369*e4b17023SJohn Marino * - an exception occurs (and in this case is caught) 370*e4b17023SJohn Marino * 371*e4b17023SJohn Marino * If no characters are stored, failbit is set in the stream's error 372*e4b17023SJohn Marino * state. 373*e4b17023SJohn Marino */ 374*e4b17023SJohn Marino __istream_type& 375*e4b17023SJohn Marino get(__streambuf_type& __sb, char_type __delim); 376*e4b17023SJohn Marino 377*e4b17023SJohn Marino /** 378*e4b17023SJohn Marino * @brief Extraction into another streambuf. 379*e4b17023SJohn Marino * @param __sb A streambuf in which to store data. 380*e4b17023SJohn Marino * @return *this 381*e4b17023SJohn Marino * 382*e4b17023SJohn Marino * Returns @c get(__sb,widen('\\n')). 383*e4b17023SJohn Marino */ 384*e4b17023SJohn Marino __istream_type& 385*e4b17023SJohn Marino get(__streambuf_type& __sb) 386*e4b17023SJohn Marino { return this->get(__sb, this->widen('\n')); } 387*e4b17023SJohn Marino 388*e4b17023SJohn Marino /** 389*e4b17023SJohn Marino * @brief String extraction. 390*e4b17023SJohn Marino * @param __s A character array in which to store the data. 391*e4b17023SJohn Marino * @param __n Maximum number of characters to extract. 392*e4b17023SJohn Marino * @param __delim A "stop" character. 393*e4b17023SJohn Marino * @return *this 394*e4b17023SJohn Marino * 395*e4b17023SJohn Marino * Extracts and stores characters into @a __s until one of the 396*e4b17023SJohn Marino * following happens. Note that these criteria are required to be 397*e4b17023SJohn Marino * tested in the order listed here, to allow an input line to exactly 398*e4b17023SJohn Marino * fill the @a __s array without setting failbit. 399*e4b17023SJohn Marino * 400*e4b17023SJohn Marino * -# the input sequence reaches end-of-file, in which case eofbit 401*e4b17023SJohn Marino * is set in the stream error state 402*e4b17023SJohn Marino * -# the next character equals @c __delim, in which case the character 403*e4b17023SJohn Marino * is extracted (and therefore counted in @c gcount()) but not stored 404*e4b17023SJohn Marino * -# @c __n-1 characters are stored, in which case failbit is set 405*e4b17023SJohn Marino * in the stream error state 406*e4b17023SJohn Marino * 407*e4b17023SJohn Marino * If no characters are extracted, failbit is set. (An empty line of 408*e4b17023SJohn Marino * input should therefore not cause failbit to be set.) 409*e4b17023SJohn Marino * 410*e4b17023SJohn Marino * In any case, a null character is stored in the next location in 411*e4b17023SJohn Marino * the array. 412*e4b17023SJohn Marino */ 413*e4b17023SJohn Marino __istream_type& 414*e4b17023SJohn Marino getline(char_type* __s, streamsize __n, char_type __delim); 415*e4b17023SJohn Marino 416*e4b17023SJohn Marino /** 417*e4b17023SJohn Marino * @brief String extraction. 418*e4b17023SJohn Marino * @param __s A character array in which to store the data. 419*e4b17023SJohn Marino * @param __n Maximum number of characters to extract. 420*e4b17023SJohn Marino * @return *this 421*e4b17023SJohn Marino * 422*e4b17023SJohn Marino * Returns @c getline(__s,__n,widen('\\n')). 423*e4b17023SJohn Marino */ 424*e4b17023SJohn Marino __istream_type& 425*e4b17023SJohn Marino getline(char_type* __s, streamsize __n) 426*e4b17023SJohn Marino { return this->getline(__s, __n, this->widen('\n')); } 427*e4b17023SJohn Marino 428*e4b17023SJohn Marino /** 429*e4b17023SJohn Marino * @brief Discarding characters 430*e4b17023SJohn Marino * @param __n Number of characters to discard. 431*e4b17023SJohn Marino * @param __delim A "stop" character. 432*e4b17023SJohn Marino * @return *this 433*e4b17023SJohn Marino * 434*e4b17023SJohn Marino * Extracts characters and throws them away until one of the 435*e4b17023SJohn Marino * following happens: 436*e4b17023SJohn Marino * - if @a __n @c != @c std::numeric_limits<int>::max(), @a __n 437*e4b17023SJohn Marino * characters are extracted 438*e4b17023SJohn Marino * - the input sequence reaches end-of-file 439*e4b17023SJohn Marino * - the next character equals @a __delim (in this case, the character 440*e4b17023SJohn Marino * is extracted); note that this condition will never occur if 441*e4b17023SJohn Marino * @a __delim equals @c traits::eof(). 442*e4b17023SJohn Marino * 443*e4b17023SJohn Marino * NB: Provide three overloads, instead of the single function 444*e4b17023SJohn Marino * (with defaults) mandated by the Standard: this leads to a 445*e4b17023SJohn Marino * better performing implementation, while still conforming to 446*e4b17023SJohn Marino * the Standard. 447*e4b17023SJohn Marino */ 448*e4b17023SJohn Marino __istream_type& 449*e4b17023SJohn Marino ignore(streamsize __n, int_type __delim); 450*e4b17023SJohn Marino 451*e4b17023SJohn Marino __istream_type& 452*e4b17023SJohn Marino ignore(streamsize __n); 453*e4b17023SJohn Marino 454*e4b17023SJohn Marino __istream_type& 455*e4b17023SJohn Marino ignore(); 456*e4b17023SJohn Marino 457*e4b17023SJohn Marino /** 458*e4b17023SJohn Marino * @brief Looking ahead in the stream 459*e4b17023SJohn Marino * @return The next character, or eof(). 460*e4b17023SJohn Marino * 461*e4b17023SJohn Marino * If, after constructing the sentry object, @c good() is false, 462*e4b17023SJohn Marino * returns @c traits::eof(). Otherwise reads but does not extract 463*e4b17023SJohn Marino * the next input character. 464*e4b17023SJohn Marino */ 465*e4b17023SJohn Marino int_type 466*e4b17023SJohn Marino peek(); 467*e4b17023SJohn Marino 468*e4b17023SJohn Marino /** 469*e4b17023SJohn Marino * @brief Extraction without delimiters. 470*e4b17023SJohn Marino * @param __s A character array. 471*e4b17023SJohn Marino * @param __n Maximum number of characters to store. 472*e4b17023SJohn Marino * @return *this 473*e4b17023SJohn Marino * 474*e4b17023SJohn Marino * If the stream state is @c good(), extracts characters and stores 475*e4b17023SJohn Marino * them into @a __s until one of the following happens: 476*e4b17023SJohn Marino * - @a __n characters are stored 477*e4b17023SJohn Marino * - the input sequence reaches end-of-file, in which case the error 478*e4b17023SJohn Marino * state is set to @c failbit|eofbit. 479*e4b17023SJohn Marino * 480*e4b17023SJohn Marino * @note This function is not overloaded on signed char and 481*e4b17023SJohn Marino * unsigned char. 482*e4b17023SJohn Marino */ 483*e4b17023SJohn Marino __istream_type& 484*e4b17023SJohn Marino read(char_type* __s, streamsize __n); 485*e4b17023SJohn Marino 486*e4b17023SJohn Marino /** 487*e4b17023SJohn Marino * @brief Extraction until the buffer is exhausted, but no more. 488*e4b17023SJohn Marino * @param __s A character array. 489*e4b17023SJohn Marino * @param __n Maximum number of characters to store. 490*e4b17023SJohn Marino * @return The number of characters extracted. 491*e4b17023SJohn Marino * 492*e4b17023SJohn Marino * Extracts characters and stores them into @a __s depending on the 493*e4b17023SJohn Marino * number of characters remaining in the streambuf's buffer, 494*e4b17023SJohn Marino * @c rdbuf()->in_avail(), called @c A here: 495*e4b17023SJohn Marino * - if @c A @c == @c -1, sets eofbit and extracts no characters 496*e4b17023SJohn Marino * - if @c A @c == @c 0, extracts no characters 497*e4b17023SJohn Marino * - if @c A @c > @c 0, extracts @c min(A,n) 498*e4b17023SJohn Marino * 499*e4b17023SJohn Marino * The goal is to empty the current buffer, and to not request any 500*e4b17023SJohn Marino * more from the external input sequence controlled by the streambuf. 501*e4b17023SJohn Marino */ 502*e4b17023SJohn Marino streamsize 503*e4b17023SJohn Marino readsome(char_type* __s, streamsize __n); 504*e4b17023SJohn Marino 505*e4b17023SJohn Marino /** 506*e4b17023SJohn Marino * @brief Unextracting a single character. 507*e4b17023SJohn Marino * @param __c The character to push back into the input stream. 508*e4b17023SJohn Marino * @return *this 509*e4b17023SJohn Marino * 510*e4b17023SJohn Marino * If @c rdbuf() is not null, calls @c rdbuf()->sputbackc(c). 511*e4b17023SJohn Marino * 512*e4b17023SJohn Marino * If @c rdbuf() is null or if @c sputbackc() fails, sets badbit in 513*e4b17023SJohn Marino * the error state. 514*e4b17023SJohn Marino * 515*e4b17023SJohn Marino * @note This function first clears eofbit. Since no characters 516*e4b17023SJohn Marino * are extracted, the next call to @c gcount() will return 0, 517*e4b17023SJohn Marino * as required by DR 60. 518*e4b17023SJohn Marino */ 519*e4b17023SJohn Marino __istream_type& 520*e4b17023SJohn Marino putback(char_type __c); 521*e4b17023SJohn Marino 522*e4b17023SJohn Marino /** 523*e4b17023SJohn Marino * @brief Unextracting the previous character. 524*e4b17023SJohn Marino * @return *this 525*e4b17023SJohn Marino * 526*e4b17023SJohn Marino * If @c rdbuf() is not null, calls @c rdbuf()->sungetc(c). 527*e4b17023SJohn Marino * 528*e4b17023SJohn Marino * If @c rdbuf() is null or if @c sungetc() fails, sets badbit in 529*e4b17023SJohn Marino * the error state. 530*e4b17023SJohn Marino * 531*e4b17023SJohn Marino * @note This function first clears eofbit. Since no characters 532*e4b17023SJohn Marino * are extracted, the next call to @c gcount() will return 0, 533*e4b17023SJohn Marino * as required by DR 60. 534*e4b17023SJohn Marino */ 535*e4b17023SJohn Marino __istream_type& 536*e4b17023SJohn Marino unget(); 537*e4b17023SJohn Marino 538*e4b17023SJohn Marino /** 539*e4b17023SJohn Marino * @brief Synchronizing the stream buffer. 540*e4b17023SJohn Marino * @return 0 on success, -1 on failure 541*e4b17023SJohn Marino * 542*e4b17023SJohn Marino * If @c rdbuf() is a null pointer, returns -1. 543*e4b17023SJohn Marino * 544*e4b17023SJohn Marino * Otherwise, calls @c rdbuf()->pubsync(), and if that returns -1, 545*e4b17023SJohn Marino * sets badbit and returns -1. 546*e4b17023SJohn Marino * 547*e4b17023SJohn Marino * Otherwise, returns 0. 548*e4b17023SJohn Marino * 549*e4b17023SJohn Marino * @note This function does not count the number of characters 550*e4b17023SJohn Marino * extracted, if any, and therefore does not affect the next 551*e4b17023SJohn Marino * call to @c gcount(). 552*e4b17023SJohn Marino */ 553*e4b17023SJohn Marino int 554*e4b17023SJohn Marino sync(); 555*e4b17023SJohn Marino 556*e4b17023SJohn Marino /** 557*e4b17023SJohn Marino * @brief Getting the current read position. 558*e4b17023SJohn Marino * @return A file position object. 559*e4b17023SJohn Marino * 560*e4b17023SJohn Marino * If @c fail() is not false, returns @c pos_type(-1) to indicate 561*e4b17023SJohn Marino * failure. Otherwise returns @c rdbuf()->pubseekoff(0,cur,in). 562*e4b17023SJohn Marino * 563*e4b17023SJohn Marino * @note This function does not count the number of characters 564*e4b17023SJohn Marino * extracted, if any, and therefore does not affect the next 565*e4b17023SJohn Marino * call to @c gcount(). At variance with putback, unget and 566*e4b17023SJohn Marino * seekg, eofbit is not cleared first. 567*e4b17023SJohn Marino */ 568*e4b17023SJohn Marino pos_type 569*e4b17023SJohn Marino tellg(); 570*e4b17023SJohn Marino 571*e4b17023SJohn Marino /** 572*e4b17023SJohn Marino * @brief Changing the current read position. 573*e4b17023SJohn Marino * @param __pos A file position object. 574*e4b17023SJohn Marino * @return *this 575*e4b17023SJohn Marino * 576*e4b17023SJohn Marino * If @c fail() is not true, calls @c rdbuf()->pubseekpos(__pos). If 577*e4b17023SJohn Marino * that function fails, sets failbit. 578*e4b17023SJohn Marino * 579*e4b17023SJohn Marino * @note This function first clears eofbit. It does not count the 580*e4b17023SJohn Marino * number of characters extracted, if any, and therefore does 581*e4b17023SJohn Marino * not affect the next call to @c gcount(). 582*e4b17023SJohn Marino */ 583*e4b17023SJohn Marino __istream_type& 584*e4b17023SJohn Marino seekg(pos_type); 585*e4b17023SJohn Marino 586*e4b17023SJohn Marino /** 587*e4b17023SJohn Marino * @brief Changing the current read position. 588*e4b17023SJohn Marino * @param __off A file offset object. 589*e4b17023SJohn Marino * @param __dir The direction in which to seek. 590*e4b17023SJohn Marino * @return *this 591*e4b17023SJohn Marino * 592*e4b17023SJohn Marino * If @c fail() is not true, calls @c rdbuf()->pubseekoff(__off,__dir). 593*e4b17023SJohn Marino * If that function fails, sets failbit. 594*e4b17023SJohn Marino * 595*e4b17023SJohn Marino * @note This function first clears eofbit. It does not count the 596*e4b17023SJohn Marino * number of characters extracted, if any, and therefore does 597*e4b17023SJohn Marino * not affect the next call to @c gcount(). 598*e4b17023SJohn Marino */ 599*e4b17023SJohn Marino __istream_type& 600*e4b17023SJohn Marino seekg(off_type, ios_base::seekdir); 601*e4b17023SJohn Marino //@} 602*e4b17023SJohn Marino 603*e4b17023SJohn Marino protected: 604*e4b17023SJohn Marino basic_istream() 605*e4b17023SJohn Marino : _M_gcount(streamsize(0)) 606*e4b17023SJohn Marino { this->init(0); } 607*e4b17023SJohn Marino 608*e4b17023SJohn Marino template<typename _ValueT> 609*e4b17023SJohn Marino __istream_type& 610*e4b17023SJohn Marino _M_extract(_ValueT& __v); 611*e4b17023SJohn Marino }; 612*e4b17023SJohn Marino 613*e4b17023SJohn Marino /// Explicit specialization declarations, defined in src/istream.cc. 614*e4b17023SJohn Marino template<> 615*e4b17023SJohn Marino basic_istream<char>& 616*e4b17023SJohn Marino basic_istream<char>:: 617*e4b17023SJohn Marino getline(char_type* __s, streamsize __n, char_type __delim); 618*e4b17023SJohn Marino 619*e4b17023SJohn Marino template<> 620*e4b17023SJohn Marino basic_istream<char>& 621*e4b17023SJohn Marino basic_istream<char>:: 622*e4b17023SJohn Marino ignore(streamsize __n); 623*e4b17023SJohn Marino 624*e4b17023SJohn Marino template<> 625*e4b17023SJohn Marino basic_istream<char>& 626*e4b17023SJohn Marino basic_istream<char>:: 627*e4b17023SJohn Marino ignore(streamsize __n, int_type __delim); 628*e4b17023SJohn Marino 629*e4b17023SJohn Marino#ifdef _GLIBCXX_USE_WCHAR_T 630*e4b17023SJohn Marino template<> 631*e4b17023SJohn Marino basic_istream<wchar_t>& 632*e4b17023SJohn Marino basic_istream<wchar_t>:: 633*e4b17023SJohn Marino getline(char_type* __s, streamsize __n, char_type __delim); 634*e4b17023SJohn Marino 635*e4b17023SJohn Marino template<> 636*e4b17023SJohn Marino basic_istream<wchar_t>& 637*e4b17023SJohn Marino basic_istream<wchar_t>:: 638*e4b17023SJohn Marino ignore(streamsize __n); 639*e4b17023SJohn Marino 640*e4b17023SJohn Marino template<> 641*e4b17023SJohn Marino basic_istream<wchar_t>& 642*e4b17023SJohn Marino basic_istream<wchar_t>:: 643*e4b17023SJohn Marino ignore(streamsize __n, int_type __delim); 644*e4b17023SJohn Marino#endif 645*e4b17023SJohn Marino 646*e4b17023SJohn Marino /** 647*e4b17023SJohn Marino * @brief Performs setup work for input streams. 648*e4b17023SJohn Marino * 649*e4b17023SJohn Marino * Objects of this class are created before all of the standard 650*e4b17023SJohn Marino * extractors are run. It is responsible for <em>exception-safe 651*e4b17023SJohn Marino * prefix and suffix operations,</em> although only prefix actions 652*e4b17023SJohn Marino * are currently required by the standard. 653*e4b17023SJohn Marino */ 654*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 655*e4b17023SJohn Marino class basic_istream<_CharT, _Traits>::sentry 656*e4b17023SJohn Marino { 657*e4b17023SJohn Marino // Data Members. 658*e4b17023SJohn Marino bool _M_ok; 659*e4b17023SJohn Marino 660*e4b17023SJohn Marino public: 661*e4b17023SJohn Marino /// Easy access to dependant types. 662*e4b17023SJohn Marino typedef _Traits traits_type; 663*e4b17023SJohn Marino typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 664*e4b17023SJohn Marino typedef basic_istream<_CharT, _Traits> __istream_type; 665*e4b17023SJohn Marino typedef typename __istream_type::__ctype_type __ctype_type; 666*e4b17023SJohn Marino typedef typename _Traits::int_type __int_type; 667*e4b17023SJohn Marino 668*e4b17023SJohn Marino /** 669*e4b17023SJohn Marino * @brief The constructor performs all the work. 670*e4b17023SJohn Marino * @param __is The input stream to guard. 671*e4b17023SJohn Marino * @param __noskipws Whether to consume whitespace or not. 672*e4b17023SJohn Marino * 673*e4b17023SJohn Marino * If the stream state is good (@a __is.good() is true), then the 674*e4b17023SJohn Marino * following actions are performed, otherwise the sentry state 675*e4b17023SJohn Marino * is false (<em>not okay</em>) and failbit is set in the 676*e4b17023SJohn Marino * stream state. 677*e4b17023SJohn Marino * 678*e4b17023SJohn Marino * The sentry's preparatory actions are: 679*e4b17023SJohn Marino * 680*e4b17023SJohn Marino * -# if the stream is tied to an output stream, @c is.tie()->flush() 681*e4b17023SJohn Marino * is called to synchronize the output sequence 682*e4b17023SJohn Marino * -# if @a __noskipws is false, and @c ios_base::skipws is set in 683*e4b17023SJohn Marino * @c is.flags(), the sentry extracts and discards whitespace 684*e4b17023SJohn Marino * characters from the stream. The currently imbued locale is 685*e4b17023SJohn Marino * used to determine whether each character is whitespace. 686*e4b17023SJohn Marino * 687*e4b17023SJohn Marino * If the stream state is still good, then the sentry state becomes 688*e4b17023SJohn Marino * true (@a okay). 689*e4b17023SJohn Marino */ 690*e4b17023SJohn Marino explicit 691*e4b17023SJohn Marino sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false); 692*e4b17023SJohn Marino 693*e4b17023SJohn Marino /** 694*e4b17023SJohn Marino * @brief Quick status checking. 695*e4b17023SJohn Marino * @return The sentry state. 696*e4b17023SJohn Marino * 697*e4b17023SJohn Marino * For ease of use, sentries may be converted to booleans. The 698*e4b17023SJohn Marino * return value is that of the sentry state (true == okay). 699*e4b17023SJohn Marino */ 700*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 701*e4b17023SJohn Marino explicit 702*e4b17023SJohn Marino#endif 703*e4b17023SJohn Marino operator bool() const 704*e4b17023SJohn Marino { return _M_ok; } 705*e4b17023SJohn Marino }; 706*e4b17023SJohn Marino 707*e4b17023SJohn Marino //@{ 708*e4b17023SJohn Marino /** 709*e4b17023SJohn Marino * @brief Character extractors 710*e4b17023SJohn Marino * @param __in An input stream. 711*e4b17023SJohn Marino * @param __c A character reference. 712*e4b17023SJohn Marino * @return in 713*e4b17023SJohn Marino * 714*e4b17023SJohn Marino * Behaves like one of the formatted arithmetic extractors described in 715*e4b17023SJohn Marino * std::basic_istream. After constructing a sentry object with good 716*e4b17023SJohn Marino * status, this function extracts a character (if one is available) and 717*e4b17023SJohn Marino * stores it in @a __c. Otherwise, sets failbit in the input stream. 718*e4b17023SJohn Marino */ 719*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 720*e4b17023SJohn Marino basic_istream<_CharT, _Traits>& 721*e4b17023SJohn Marino operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c); 722*e4b17023SJohn Marino 723*e4b17023SJohn Marino template<class _Traits> 724*e4b17023SJohn Marino inline basic_istream<char, _Traits>& 725*e4b17023SJohn Marino operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) 726*e4b17023SJohn Marino { return (__in >> reinterpret_cast<char&>(__c)); } 727*e4b17023SJohn Marino 728*e4b17023SJohn Marino template<class _Traits> 729*e4b17023SJohn Marino inline basic_istream<char, _Traits>& 730*e4b17023SJohn Marino operator>>(basic_istream<char, _Traits>& __in, signed char& __c) 731*e4b17023SJohn Marino { return (__in >> reinterpret_cast<char&>(__c)); } 732*e4b17023SJohn Marino //@} 733*e4b17023SJohn Marino 734*e4b17023SJohn Marino //@{ 735*e4b17023SJohn Marino /** 736*e4b17023SJohn Marino * @brief Character string extractors 737*e4b17023SJohn Marino * @param __in An input stream. 738*e4b17023SJohn Marino * @param __s A pointer to a character array. 739*e4b17023SJohn Marino * @return __in 740*e4b17023SJohn Marino * 741*e4b17023SJohn Marino * Behaves like one of the formatted arithmetic extractors described in 742*e4b17023SJohn Marino * std::basic_istream. After constructing a sentry object with good 743*e4b17023SJohn Marino * status, this function extracts up to @c n characters and stores them 744*e4b17023SJohn Marino * into the array starting at @a __s. @c n is defined as: 745*e4b17023SJohn Marino * 746*e4b17023SJohn Marino * - if @c width() is greater than zero, @c n is width() otherwise 747*e4b17023SJohn Marino * - @c n is <em>the number of elements of the largest array of * 748*e4b17023SJohn Marino * - @c char_type that can store a terminating @c eos.</em> 749*e4b17023SJohn Marino * - [27.6.1.2.3]/6 750*e4b17023SJohn Marino * 751*e4b17023SJohn Marino * Characters are extracted and stored until one of the following happens: 752*e4b17023SJohn Marino * - @c n-1 characters are stored 753*e4b17023SJohn Marino * - EOF is reached 754*e4b17023SJohn Marino * - the next character is whitespace according to the current locale 755*e4b17023SJohn Marino * - the next character is a null byte (i.e., @c charT() ) 756*e4b17023SJohn Marino * 757*e4b17023SJohn Marino * @c width(0) is then called for the input stream. 758*e4b17023SJohn Marino * 759*e4b17023SJohn Marino * If no characters are extracted, sets failbit. 760*e4b17023SJohn Marino */ 761*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 762*e4b17023SJohn Marino basic_istream<_CharT, _Traits>& 763*e4b17023SJohn Marino operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s); 764*e4b17023SJohn Marino 765*e4b17023SJohn Marino // Explicit specialization declaration, defined in src/istream.cc. 766*e4b17023SJohn Marino template<> 767*e4b17023SJohn Marino basic_istream<char>& 768*e4b17023SJohn Marino operator>>(basic_istream<char>& __in, char* __s); 769*e4b17023SJohn Marino 770*e4b17023SJohn Marino template<class _Traits> 771*e4b17023SJohn Marino inline basic_istream<char, _Traits>& 772*e4b17023SJohn Marino operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s) 773*e4b17023SJohn Marino { return (__in >> reinterpret_cast<char*>(__s)); } 774*e4b17023SJohn Marino 775*e4b17023SJohn Marino template<class _Traits> 776*e4b17023SJohn Marino inline basic_istream<char, _Traits>& 777*e4b17023SJohn Marino operator>>(basic_istream<char, _Traits>& __in, signed char* __s) 778*e4b17023SJohn Marino { return (__in >> reinterpret_cast<char*>(__s)); } 779*e4b17023SJohn Marino //@} 780*e4b17023SJohn Marino 781*e4b17023SJohn Marino /** 782*e4b17023SJohn Marino * @brief Template class basic_iostream 783*e4b17023SJohn Marino * @ingroup io 784*e4b17023SJohn Marino * 785*e4b17023SJohn Marino * This class multiply inherits from the input and output stream classes 786*e4b17023SJohn Marino * simply to provide a single interface. 787*e4b17023SJohn Marino */ 788*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 789*e4b17023SJohn Marino class basic_iostream 790*e4b17023SJohn Marino : public basic_istream<_CharT, _Traits>, 791*e4b17023SJohn Marino public basic_ostream<_CharT, _Traits> 792*e4b17023SJohn Marino { 793*e4b17023SJohn Marino public: 794*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 795*e4b17023SJohn Marino // 271. basic_iostream missing typedefs 796*e4b17023SJohn Marino // Types (inherited): 797*e4b17023SJohn Marino typedef _CharT char_type; 798*e4b17023SJohn Marino typedef typename _Traits::int_type int_type; 799*e4b17023SJohn Marino typedef typename _Traits::pos_type pos_type; 800*e4b17023SJohn Marino typedef typename _Traits::off_type off_type; 801*e4b17023SJohn Marino typedef _Traits traits_type; 802*e4b17023SJohn Marino 803*e4b17023SJohn Marino // Non-standard Types: 804*e4b17023SJohn Marino typedef basic_istream<_CharT, _Traits> __istream_type; 805*e4b17023SJohn Marino typedef basic_ostream<_CharT, _Traits> __ostream_type; 806*e4b17023SJohn Marino 807*e4b17023SJohn Marino /** 808*e4b17023SJohn Marino * @brief Constructor does nothing. 809*e4b17023SJohn Marino * 810*e4b17023SJohn Marino * Both of the parent classes are initialized with the same 811*e4b17023SJohn Marino * streambuf pointer passed to this constructor. 812*e4b17023SJohn Marino */ 813*e4b17023SJohn Marino explicit 814*e4b17023SJohn Marino basic_iostream(basic_streambuf<_CharT, _Traits>* __sb) 815*e4b17023SJohn Marino : __istream_type(__sb), __ostream_type(__sb) { } 816*e4b17023SJohn Marino 817*e4b17023SJohn Marino /** 818*e4b17023SJohn Marino * @brief Destructor does nothing. 819*e4b17023SJohn Marino */ 820*e4b17023SJohn Marino virtual 821*e4b17023SJohn Marino ~basic_iostream() { } 822*e4b17023SJohn Marino 823*e4b17023SJohn Marino protected: 824*e4b17023SJohn Marino basic_iostream() 825*e4b17023SJohn Marino : __istream_type(), __ostream_type() { } 826*e4b17023SJohn Marino }; 827*e4b17023SJohn Marino 828*e4b17023SJohn Marino /** 829*e4b17023SJohn Marino * @brief Quick and easy way to eat whitespace 830*e4b17023SJohn Marino * 831*e4b17023SJohn Marino * This manipulator extracts whitespace characters, stopping when the 832*e4b17023SJohn Marino * next character is non-whitespace, or when the input sequence is empty. 833*e4b17023SJohn Marino * If the sequence is empty, @c eofbit is set in the stream, but not 834*e4b17023SJohn Marino * @c failbit. 835*e4b17023SJohn Marino * 836*e4b17023SJohn Marino * The current locale is used to distinguish whitespace characters. 837*e4b17023SJohn Marino * 838*e4b17023SJohn Marino * Example: 839*e4b17023SJohn Marino * @code 840*e4b17023SJohn Marino * MyClass mc; 841*e4b17023SJohn Marino * 842*e4b17023SJohn Marino * std::cin >> std::ws >> mc; 843*e4b17023SJohn Marino * @endcode 844*e4b17023SJohn Marino * will skip leading whitespace before calling operator>> on cin and your 845*e4b17023SJohn Marino * object. Note that the same effect can be achieved by creating a 846*e4b17023SJohn Marino * std::basic_istream::sentry inside your definition of operator>>. 847*e4b17023SJohn Marino */ 848*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 849*e4b17023SJohn Marino basic_istream<_CharT, _Traits>& 850*e4b17023SJohn Marino ws(basic_istream<_CharT, _Traits>& __is); 851*e4b17023SJohn Marino 852*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 853*e4b17023SJohn Marino // [27.7.1.6] Rvalue stream extraction 854*e4b17023SJohn Marino /** 855*e4b17023SJohn Marino * @brief Generic extractor for rvalue stream 856*e4b17023SJohn Marino * @param __is An input stream. 857*e4b17023SJohn Marino * @param __x A reference to the extraction target. 858*e4b17023SJohn Marino * @return is 859*e4b17023SJohn Marino * 860*e4b17023SJohn Marino * This is just a forwarding function to allow extraction from 861*e4b17023SJohn Marino * rvalue streams since they won't bind to the extractor functions 862*e4b17023SJohn Marino * that take an lvalue reference. 863*e4b17023SJohn Marino */ 864*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Tp> 865*e4b17023SJohn Marino inline basic_istream<_CharT, _Traits>& 866*e4b17023SJohn Marino operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) 867*e4b17023SJohn Marino { return (__is >> __x); } 868*e4b17023SJohn Marino#endif // __GXX_EXPERIMENTAL_CXX0X__ 869*e4b17023SJohn Marino 870*e4b17023SJohn Marino_GLIBCXX_END_NAMESPACE_VERSION 871*e4b17023SJohn Marino} // namespace 872*e4b17023SJohn Marino 873*e4b17023SJohn Marino#include <bits/istream.tcc> 874*e4b17023SJohn Marino 875*e4b17023SJohn Marino#endif /* _GLIBCXX_ISTREAM */ 876