istream

Go to the documentation of this file.
00001 // Input streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 //
00032 // ISO C++ 14882: 27.6.1  Input streams
00033 //
00034 
00040 #ifndef _GLIBCXX_ISTREAM
00041 #define _GLIBCXX_ISTREAM 1
00042 
00043 #pragma GCC system_header
00044 
00045 #include <ios>
00046 #include <limits> // For numeric_limits
00047 
00048 namespace std
00049 {
00050   // [27.6.1.1] Template class basic_istream
00058   template<typename _CharT, typename _Traits>
00059     class basic_istream : virtual public basic_ios<_CharT, _Traits>
00060     {
00061     public:
00062       // Types (inherited from basic_ios (27.4.4)):
00063       typedef _CharT                            char_type;
00064       typedef typename _Traits::int_type        int_type;
00065       typedef typename _Traits::pos_type        pos_type;
00066       typedef typename _Traits::off_type        off_type;
00067       typedef _Traits                           traits_type;
00068       
00069       // Non-standard Types:
00070       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00071       typedef basic_ios<_CharT, _Traits>        __ios_type;
00072       typedef basic_istream<_CharT, _Traits>        __istream_type;
00073       typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >        
00074                             __num_get_type;
00075       typedef ctype<_CharT>                     __ctype_type;
00076 
00077       template<typename _CharT2, typename _Traits2>
00078         friend basic_istream<_CharT2, _Traits2>&
00079         operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2&);
00080  
00081       template<typename _CharT2, typename _Traits2>
00082         friend basic_istream<_CharT2, _Traits2>&
00083         operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*);
00084  
00085     protected:
00086       // Data Members:
00093       streamsize        _M_gcount;
00094 
00095     public:
00096       // [27.6.1.1.1] constructor/destructor
00104       explicit 
00105       basic_istream(__streambuf_type* __sb): _M_gcount(streamsize(0))
00106       { this->init(__sb); }
00107 
00113       virtual 
00114       ~basic_istream() 
00115       { _M_gcount = streamsize(0); }
00116 
00117       // [27.6.1.1.2] prefix/suffix
00118       class sentry;
00119       friend class sentry;
00120 
00121       // [27.6.1.2] formatted input
00122       // [27.6.1.2.3] basic_istream::operator>>
00124 
00131       inline __istream_type&
00132       operator>>(__istream_type& (*__pf)(__istream_type&));
00133 
00134       inline __istream_type&
00135       operator>>(__ios_type& (*__pf)(__ios_type&));
00136 
00137       inline __istream_type&
00138       operator>>(ios_base& (*__pf)(ios_base&));
00140       
00141       // [27.6.1.2.2] arithmetic extractors
00169       __istream_type& 
00170       operator>>(bool& __n);
00171       
00172       __istream_type& 
00173       operator>>(short& __n);
00174       
00175       __istream_type& 
00176       operator>>(unsigned short& __n);
00177 
00178       __istream_type& 
00179       operator>>(int& __n);
00180       
00181       __istream_type& 
00182       operator>>(unsigned int& __n);
00183 
00184       __istream_type& 
00185       operator>>(long& __n);
00186       
00187       __istream_type& 
00188       operator>>(unsigned long& __n);
00189 
00190 #ifdef _GLIBCXX_USE_LONG_LONG
00191       __istream_type& 
00192       operator>>(long long& __n);
00193 
00194       __istream_type& 
00195       operator>>(unsigned long long& __n);
00196 #endif
00197 
00198       __istream_type& 
00199       operator>>(float& __f);
00200 
00201       __istream_type& 
00202       operator>>(double& __f);
00203 
00204       __istream_type& 
00205       operator>>(long double& __f);
00206 
00207       __istream_type& 
00208       operator>>(void*& __p);
00209 
00230       __istream_type& 
00231       operator>>(__streambuf_type* __sb);
00233       
00234       // [27.6.1.3] unformatted input
00240       inline streamsize 
00241       gcount() const 
00242       { return _M_gcount; }
00243       
00272       int_type 
00273       get();
00274 
00286       __istream_type& 
00287       get(char_type& __c);
00288 
00313       __istream_type& 
00314       get(char_type* __s, streamsize __n, char_type __delim);
00315 
00324       inline __istream_type& 
00325       get(char_type* __s, streamsize __n)
00326       { return this->get(__s, __n, this->widen('\n')); }
00327 
00347       __istream_type&
00348       get(__streambuf_type& __sb, char_type __delim);
00349 
00357       inline __istream_type&
00358       get(__streambuf_type& __sb)
00359       { return this->get(__sb, this->widen('\n')); }
00360 
00386       __istream_type& 
00387       getline(char_type* __s, streamsize __n, char_type __delim);
00388 
00397       inline __istream_type& 
00398       getline(char_type* __s, streamsize __n)
00399       { return this->getline(__s, __n, this->widen('\n')); }
00400 
00416       __istream_type& 
00417       ignore(streamsize __n = 1, int_type __delim = traits_type::eof());
00418       
00427       int_type 
00428       peek();
00429       
00445       __istream_type& 
00446       read(char_type* __s, streamsize __n);
00447 
00464       streamsize 
00465       readsome(char_type* __s, streamsize __n);
00466       
00480       __istream_type& 
00481       putback(char_type __c);
00482 
00495       __istream_type& 
00496       unget();
00497 
00513       int 
00514       sync();
00515 
00527       pos_type 
00528       tellg();
00529 
00542       __istream_type& 
00543       seekg(pos_type);
00544 
00558       __istream_type& 
00559       seekg(off_type, ios_base::seekdir);
00561 
00562     protected:
00563       explicit 
00564       basic_istream(): _M_gcount(streamsize(0)) { }
00565     };
00566   
00578   template<typename _CharT, typename _Traits>
00579     class basic_istream<_CharT, _Traits>::sentry
00580     {
00581     public:
00583       typedef _Traits                   traits_type;
00584       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00585       typedef basic_istream<_CharT, _Traits>        __istream_type;
00586       typedef typename __istream_type::__ctype_type     __ctype_type;
00587       typedef typename _Traits::int_type        __int_type;
00588 
00610       explicit 
00611       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00612 
00620       operator bool() const { return _M_ok; }
00621 
00622     private:
00623       bool _M_ok;
00624     };
00625 
00626   // [27.6.1.2.3] character extraction templates
00628 
00639   template<typename _CharT, typename _Traits>
00640     basic_istream<_CharT, _Traits>&
00641     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00642 
00643   template<class _Traits>
00644     basic_istream<char, _Traits>&
00645     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00646     { return (__in >> reinterpret_cast<char&>(__c)); }
00647 
00648   template<class _Traits>
00649     basic_istream<char, _Traits>&
00650     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00651     { return (__in >> reinterpret_cast<char&>(__c)); }
00653 
00655 
00680   template<typename _CharT, typename _Traits>
00681     basic_istream<_CharT, _Traits>&
00682     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00683   
00684   template<class _Traits>
00685     basic_istream<char,_Traits>&
00686     operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s)
00687     { return (__in >> reinterpret_cast<char*>(__s)); }
00688 
00689   template<class _Traits>
00690     basic_istream<char,_Traits>&
00691     operator>>(basic_istream<char,_Traits>& __in, signed char* __s)
00692     { return (__in >> reinterpret_cast<char*>(__s)); }
00694 
00695   // 27.6.1.5 Template class basic_iostream
00702   template<typename _CharT, typename _Traits>
00703     class basic_iostream
00704     : public basic_istream<_CharT, _Traits>, 
00705       public basic_ostream<_CharT, _Traits>
00706     {
00707     public:
00708       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00709       // 271. basic_iostream missing typedefs
00710       // Types (inherited):
00711       typedef _CharT                            char_type;
00712       typedef typename _Traits::int_type        int_type;
00713       typedef typename _Traits::pos_type        pos_type;
00714       typedef typename _Traits::off_type        off_type;
00715       typedef _Traits                           traits_type;
00716 
00717       // Non-standard Types:
00718       typedef basic_istream<_CharT, _Traits>        __istream_type;
00719       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00720 
00727       explicit 
00728       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00729       : __istream_type(), __ostream_type()
00730       { this->init(__sb); }
00731 
00735       virtual 
00736       ~basic_iostream() { }
00737 
00738     protected:
00739       explicit 
00740       basic_iostream() : __istream_type(), __ostream_type()
00741       { }
00742     };
00743 
00744   // [27.6.1.4] standard basic_istream manipulators
00765   template<typename _CharT, typename _Traits>
00766     basic_istream<_CharT, _Traits>& 
00767     ws(basic_istream<_CharT, _Traits>& __is);
00768 } // namespace std
00769 
00770 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00771 # include <bits/istream.tcc>
00772 #endif
00773 
00774 #endif  /* _GLIBCXX_ISTREAM */

Generated on Tue Jan 30 17:31:50 2007 for GNU C++ STL by doxygen 1.3.6