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     protected:
00077       // Data Members:
00084       streamsize        _M_gcount;
00085 
00086     public:
00087       // [27.6.1.1.1] constructor/destructor
00095       explicit 
00096       basic_istream(__streambuf_type* __sb)
00097       { 
00098     this->init(__sb);
00099     _M_gcount = streamsize(0);
00100       }
00101 
00107       virtual 
00108       ~basic_istream() 
00109       { _M_gcount = streamsize(0); }
00110 
00111       // [27.6.1.1.2] prefix/suffix
00112       class sentry;
00113       friend class sentry;
00114 
00115       // [27.6.1.2] formatted input
00116       // [27.6.1.2.3] basic_istream::operator>>
00118 
00125       __istream_type&
00126       operator>>(__istream_type& (*__pf)(__istream_type&));
00127 
00128       __istream_type&
00129       operator>>(__ios_type& (*__pf)(__ios_type&));
00130 
00131       __istream_type&
00132       operator>>(ios_base& (*__pf)(ios_base&));
00134       
00135       // [27.6.1.2.2] arithmetic extractors
00163       __istream_type& 
00164       operator>>(bool& __n);
00165       
00166       __istream_type& 
00167       operator>>(short& __n);
00168       
00169       __istream_type& 
00170       operator>>(unsigned short& __n);
00171 
00172       __istream_type& 
00173       operator>>(int& __n);
00174       
00175       __istream_type& 
00176       operator>>(unsigned int& __n);
00177 
00178       __istream_type& 
00179       operator>>(long& __n);
00180       
00181       __istream_type& 
00182       operator>>(unsigned long& __n);
00183 
00184 #ifdef _GLIBCPP_USE_LONG_LONG
00185       __istream_type& 
00186       operator>>(long long& __n);
00187 
00188       __istream_type& 
00189       operator>>(unsigned long long& __n);
00190 #endif
00191 
00192       __istream_type& 
00193       operator>>(float& __f);
00194 
00195       __istream_type& 
00196       operator>>(double& __f);
00197 
00198       __istream_type& 
00199       operator>>(long double& __f);
00200 
00201       __istream_type& 
00202       operator>>(void*& __p);
00203 
00224       __istream_type& 
00225       operator>>(__streambuf_type* __sb);
00227       
00228       // [27.6.1.3] unformatted input
00234       inline streamsize 
00235       gcount() const 
00236       { return _M_gcount; }
00237       
00266       int_type 
00267       get();
00268 
00280       __istream_type& 
00281       get(char_type& __c);
00282 
00307       __istream_type& 
00308       get(char_type* __s, streamsize __n, char_type __delim);
00309 
00318       inline __istream_type& 
00319       get(char_type* __s, streamsize __n)
00320       { return this->get(__s, __n, this->widen('\n')); }
00321 
00341       __istream_type&
00342       get(__streambuf_type& __sb, char_type __delim);
00343 
00351       inline __istream_type&
00352       get(__streambuf_type& __sb)
00353       { return this->get(__sb, this->widen('\n')); }
00354 
00380       __istream_type& 
00381       getline(char_type* __s, streamsize __n, char_type __delim);
00382 
00391       inline __istream_type& 
00392       getline(char_type* __s, streamsize __n)
00393       { return this->getline(__s, __n, this->widen('\n')); }
00394 
00410       __istream_type& 
00411       ignore(streamsize __n = 1, int_type __delim = traits_type::eof());
00412       
00421       int_type 
00422       peek();
00423       
00439       __istream_type& 
00440       read(char_type* __s, streamsize __n);
00441 
00458       streamsize 
00459       readsome(char_type* __s, streamsize __n);
00460       
00478       __istream_type& 
00479       putback(char_type __c);
00480 
00493       __istream_type& 
00494       unget();
00495 
00514       int 
00515       sync();
00516 
00528       pos_type 
00529       tellg();
00530 
00546       __istream_type& 
00547       seekg(pos_type);
00548 
00565       __istream_type& 
00566       seekg(off_type, ios_base::seekdir);
00568     };
00569   
00581   template<typename _CharT, typename _Traits>
00582     class basic_istream<_CharT, _Traits>::sentry
00583     {
00584     public:
00586       typedef _Traits                   traits_type;
00587       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00588       typedef basic_istream<_CharT, _Traits>        __istream_type;
00589       typedef typename __istream_type::__ctype_type     __ctype_type;
00590       typedef typename _Traits::int_type        __int_type;
00591 
00613       explicit 
00614       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00615 
00623       operator bool() { return _M_ok; }
00624 
00625     private:
00626       bool _M_ok;
00627     };
00628 
00629   // [27.6.1.2.3] character extraction templates
00631 
00642   template<typename _CharT, typename _Traits>
00643     basic_istream<_CharT, _Traits>&
00644     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00645 
00646   template<class _Traits>
00647     basic_istream<char, _Traits>&
00648     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00649     { return (__in >> reinterpret_cast<char&>(__c)); }
00650 
00651   template<class _Traits>
00652     basic_istream<char, _Traits>&
00653     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00654     { return (__in >> reinterpret_cast<char&>(__c)); }
00656 
00658 
00683   template<typename _CharT, typename _Traits>
00684     basic_istream<_CharT, _Traits>&
00685     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00686   
00687   template<class _Traits>
00688     basic_istream<char,_Traits>&
00689     operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s)
00690     { return (__in >> reinterpret_cast<char*>(__s)); }
00691 
00692   template<class _Traits>
00693     basic_istream<char,_Traits>&
00694     operator>>(basic_istream<char,_Traits>& __in, signed char* __s)
00695     { return (__in >> reinterpret_cast<char*>(__s)); }
00697 
00698   // 27.6.1.5 Template class basic_iostream
00705   template<typename _CharT, typename _Traits>
00706     class basic_iostream
00707     : public basic_istream<_CharT, _Traits>, 
00708       public basic_ostream<_CharT, _Traits>
00709     {
00710     public:
00711 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00712 // 271. basic_iostream missing typedefs
00713       // Types (inherited):
00714       typedef _CharT                            char_type;
00715       typedef typename _Traits::int_type        int_type;
00716       typedef typename _Traits::pos_type        pos_type;
00717       typedef typename _Traits::off_type        off_type;
00718       typedef _Traits                           traits_type;
00719 #endif
00720 
00721       // Non-standard Types:
00722       typedef basic_istream<_CharT, _Traits>        __istream_type;
00723       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00724 
00731       explicit 
00732       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00733       : __istream_type(__sb), __ostream_type(__sb)
00734       { }
00735 
00739       virtual 
00740       ~basic_iostream() { }
00741     };
00742 
00743   // [27.6.1.4] standard basic_istream manipulators
00764   template<typename _CharT, typename _Traits>
00765     basic_istream<_CharT, _Traits>& 
00766     ws(basic_istream<_CharT, _Traits>& __is);
00767 } // namespace std
00768 
00769 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00770 # define export
00771 #endif
00772 #ifdef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
00773 # include <bits/istream.tcc>
00774 #endif
00775 
00776 #endif  /* _CPP_ISTREAM */

Generated on Thu Nov 21 03:12:48 2002 for libstdc++-v3 Source by doxygen1.2.18-20021030