istream

Go to the documentation of this file.
00001 // Input streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 //
00031 // ISO C++ 14882: 27.6.1  Input streams
00032 //
00033 
00039 #ifndef _CPP_ISTREAM
00040 #define _CPP_ISTREAM    1
00041 
00042 #pragma GCC system_header
00043 
00044 #include <ios>
00045 #include <limits> // For numeric_limits
00046 
00047 namespace std
00048 {
00049   // [27.6.1.1] Template class basic_istream
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 istreambuf_iterator<_CharT, _Traits>  __istreambuf_iter;
00073       typedef num_get<_CharT, __istreambuf_iter>        __numget_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:
00092       streamsize        _M_gcount;
00093 
00094     public:
00095       // [27.6.1.1.1] constructor/destructor
00103       explicit 
00104       basic_istream(__streambuf_type* __sb)
00105       { 
00106     this->init(__sb);
00107     _M_gcount = streamsize(0);
00108       }
00109 
00115       virtual 
00116       ~basic_istream() 
00117       { _M_gcount = streamsize(0); }
00118 
00119       // [27.6.1.1.2] prefix/suffix
00120       class sentry;
00121       friend class sentry;
00122 
00123       // [27.6.1.2] formatted input
00124       // [27.6.1.2.3] basic_istream::operator>>
00126 
00133       __istream_type&
00134       operator>>(__istream_type& (*__pf)(__istream_type&));
00135 
00136       __istream_type&
00137       operator>>(__ios_type& (*__pf)(__ios_type&));
00138 
00139       __istream_type&
00140       operator>>(ios_base& (*__pf)(ios_base&));
00142       
00143       // [27.6.1.2.2] arithmetic extractors
00171       __istream_type& 
00172       operator>>(bool& __n);
00173       
00174       __istream_type& 
00175       operator>>(short& __n);
00176       
00177       __istream_type& 
00178       operator>>(unsigned short& __n);
00179 
00180       __istream_type& 
00181       operator>>(int& __n);
00182       
00183       __istream_type& 
00184       operator>>(unsigned int& __n);
00185 
00186       __istream_type& 
00187       operator>>(long& __n);
00188       
00189       __istream_type& 
00190       operator>>(unsigned long& __n);
00191 
00192 #ifdef _GLIBCPP_USE_LONG_LONG
00193       __istream_type& 
00194       operator>>(long long& __n);
00195 
00196       __istream_type& 
00197       operator>>(unsigned long long& __n);
00198 #endif
00199 
00200       __istream_type& 
00201       operator>>(float& __f);
00202 
00203       __istream_type& 
00204       operator>>(double& __f);
00205 
00206       __istream_type& 
00207       operator>>(long double& __f);
00208 
00209       __istream_type& 
00210       operator>>(void*& __p);
00211 
00232       __istream_type& 
00233       operator>>(__streambuf_type* __sb);
00235       
00236       // [27.6.1.3] unformatted input
00242       inline streamsize 
00243       gcount() const 
00244       { return _M_gcount; }
00245       
00274       int_type 
00275       get();
00276 
00288       __istream_type& 
00289       get(char_type& __c);
00290 
00315       __istream_type& 
00316       get(char_type* __s, streamsize __n, char_type __delim);
00317 
00326       inline __istream_type& 
00327       get(char_type* __s, streamsize __n)
00328       { return this->get(__s, __n, this->widen('\n')); }
00329 
00349       __istream_type&
00350       get(__streambuf_type& __sb, char_type __delim);
00351 
00359       inline __istream_type&
00360       get(__streambuf_type& __sb)
00361       { return this->get(__sb, this->widen('\n')); }
00362 
00388       __istream_type& 
00389       getline(char_type* __s, streamsize __n, char_type __delim);
00390 
00399       inline __istream_type& 
00400       getline(char_type* __s, streamsize __n)
00401       { return this->getline(__s, __n, this->widen('\n')); }
00402 
00418       __istream_type& 
00419       ignore(streamsize __n = 1, int_type __delim = traits_type::eof());
00420       
00429       int_type 
00430       peek();
00431       
00447       __istream_type& 
00448       read(char_type* __s, streamsize __n);
00449 
00466       streamsize 
00467       readsome(char_type* __s, streamsize __n);
00468       
00482       __istream_type& 
00483       putback(char_type __c);
00484 
00497       __istream_type& 
00498       unget();
00499 
00515       int 
00516       sync();
00517 
00529       pos_type 
00530       tellg();
00531 
00544       __istream_type& 
00545       seekg(pos_type);
00546 
00560       __istream_type& 
00561       seekg(off_type, ios_base::seekdir);
00563     };
00564   
00576   template<typename _CharT, typename _Traits>
00577     class basic_istream<_CharT, _Traits>::sentry
00578     {
00579     public:
00581       typedef _Traits                   traits_type;
00582       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00583       typedef basic_istream<_CharT, _Traits>        __istream_type;
00584       typedef typename __istream_type::__ctype_type     __ctype_type;
00585       typedef typename _Traits::int_type        __int_type;
00586 
00608       explicit 
00609       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00610 
00618       operator bool() { return _M_ok; }
00619 
00620     private:
00621       bool _M_ok;
00622     };
00623 
00624   // [27.6.1.2.3] character extraction templates
00626 
00637   template<typename _CharT, typename _Traits>
00638     basic_istream<_CharT, _Traits>&
00639     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00640 
00641   template<class _Traits>
00642     basic_istream<char, _Traits>&
00643     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00644     { return (__in >> reinterpret_cast<char&>(__c)); }
00645 
00646   template<class _Traits>
00647     basic_istream<char, _Traits>&
00648     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00649     { return (__in >> reinterpret_cast<char&>(__c)); }
00651 
00653 
00678   template<typename _CharT, typename _Traits>
00679     basic_istream<_CharT, _Traits>&
00680     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00681   
00682   template<class _Traits>
00683     basic_istream<char,_Traits>&
00684     operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s)
00685     { return (__in >> reinterpret_cast<char*>(__s)); }
00686 
00687   template<class _Traits>
00688     basic_istream<char,_Traits>&
00689     operator>>(basic_istream<char,_Traits>& __in, signed char* __s)
00690     { return (__in >> reinterpret_cast<char*>(__s)); }
00692 
00693   // 27.6.1.5 Template class basic_iostream
00700   template<typename _CharT, typename _Traits>
00701     class basic_iostream
00702     : public basic_istream<_CharT, _Traits>, 
00703       public basic_ostream<_CharT, _Traits>
00704     {
00705     public:
00706 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00707 // 271. basic_iostream missing typedefs
00708       // Types (inherited):
00709       typedef _CharT                            char_type;
00710       typedef typename _Traits::int_type        int_type;
00711       typedef typename _Traits::pos_type        pos_type;
00712       typedef typename _Traits::off_type        off_type;
00713       typedef _Traits                           traits_type;
00714 #endif
00715 
00716       // Non-standard Types:
00717       typedef basic_istream<_CharT, _Traits>        __istream_type;
00718       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00719 
00726       explicit 
00727       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00728       : __istream_type(__sb), __ostream_type(__sb)
00729       { }
00730 
00734       virtual 
00735       ~basic_iostream() { }
00736     };
00737 
00738   // [27.6.1.4] standard basic_istream manipulators
00759   template<typename _CharT, typename _Traits>
00760     basic_istream<_CharT, _Traits>& 
00761     ws(basic_istream<_CharT, _Traits>& __is);
00762 } // namespace std
00763 
00764 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00765 # define export
00766 #endif
00767 #ifdef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
00768 # include <bits/istream.tcc>
00769 #endif
00770 
00771 #endif  /* _CPP_ISTREAM */

Generated on Tue Apr 29 20:16:21 2003 for libstdc++-v3 Source by doxygen1.3