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
00050   template<typename _CharT, typename _Traits>
00051     class basic_istream : virtual public basic_ios<_CharT, _Traits>
00052     {
00053     public:
00054       // Types (inherited from basic_ios (27.4.4)):
00055       typedef _CharT                            char_type;
00056       typedef typename _Traits::int_type        int_type;
00057       typedef typename _Traits::pos_type        pos_type;
00058       typedef typename _Traits::off_type        off_type;
00059       typedef _Traits                           traits_type;
00060       
00061       // Non-standard Types:
00062       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00063       typedef basic_ios<_CharT, _Traits>        __ios_type;
00064       typedef basic_istream<_CharT, _Traits>        __istream_type;
00065       typedef istreambuf_iterator<_CharT, _Traits>  __istreambuf_iter;
00066       typedef num_get<_CharT, __istreambuf_iter>        __numget_type;
00067       typedef ctype<_CharT>                     __ctype_type;
00068 
00069     protected:
00070       // Data Members:
00071       streamsize        _M_gcount;
00072 
00073     public:
00074       // 27.6.1.1.1 Constructor/destructor:
00075       explicit 
00076       basic_istream(__streambuf_type* __sb)
00077       { 
00078     this->init(__sb);
00079     _M_gcount = streamsize(0);
00080       }
00081 
00082       virtual 
00083       ~basic_istream() 
00084       { _M_gcount = streamsize(0); }
00085 
00086       // 27.6.1.1.2 Prefix/suffix:
00087       class sentry;
00088       friend class sentry;
00089 
00090       // 27.6.1.2 Formatted input:
00091       // 27.6.1.2.3 basic_istream::operator>>
00092       __istream_type&
00093       operator>>(__istream_type& (*__pf)(__istream_type&));
00094 
00095       __istream_type&
00096       operator>>(__ios_type& (*__pf)(__ios_type&));
00097 
00098       __istream_type&
00099       operator>>(ios_base& (*__pf)(ios_base&));
00100       
00101       // 27.6.1.2.2 Arithmetic Extractors
00102       __istream_type& 
00103       operator>>(bool& __n);
00104       
00105       __istream_type& 
00106       operator>>(short& __n);
00107       
00108       __istream_type& 
00109       operator>>(unsigned short& __n);
00110 
00111       __istream_type& 
00112       operator>>(int& __n);
00113       
00114       __istream_type& 
00115       operator>>(unsigned int& __n);
00116 
00117       __istream_type& 
00118       operator>>(long& __n);
00119       
00120       __istream_type& 
00121       operator>>(unsigned long& __n);
00122 
00123 #ifdef _GLIBCPP_USE_LONG_LONG
00124       __istream_type& 
00125       operator>>(long long& __n);
00126 
00127       __istream_type& 
00128       operator>>(unsigned long long& __n);
00129 #endif
00130 
00131       __istream_type& 
00132       operator>>(float& __f);
00133 
00134       __istream_type& 
00135       operator>>(double& __f);
00136 
00137       __istream_type& 
00138       operator>>(long double& __f);
00139 
00140       __istream_type& 
00141       operator>>(void*& __p);
00142 
00143       __istream_type& 
00144       operator>>(__streambuf_type* __sb);
00145       
00146       // 27.6.1.3 Unformatted input:
00147       inline streamsize 
00148       gcount(void) const 
00149       { return _M_gcount; }
00150       
00151       int_type 
00152       get(void);
00153 
00154       __istream_type& 
00155       get(char_type& __c);
00156 
00157       __istream_type& 
00158       get(char_type* __s, streamsize __n, char_type __delim);
00159 
00160       inline __istream_type& 
00161       get(char_type* __s, streamsize __n)
00162       { return this->get(__s, __n, this->widen('\n')); }
00163 
00164       __istream_type&
00165       get(__streambuf_type& __sb, char_type __delim);
00166 
00167       inline __istream_type&
00168       get(__streambuf_type& __sb)
00169       { return this->get(__sb, this->widen('\n')); }
00170 
00171       __istream_type& 
00172       getline(char_type* __s, streamsize __n, char_type __delim);
00173 
00174       inline __istream_type& 
00175       getline(char_type* __s, streamsize __n)
00176       { return this->getline(__s, __n, this->widen('\n')); }
00177 
00178       __istream_type& 
00179       ignore(streamsize __n = 1, int_type __delim = traits_type::eof());
00180       
00181       int_type 
00182       peek(void);
00183       
00184       __istream_type& 
00185       read(char_type* __s, streamsize __n);
00186 
00187       streamsize 
00188       readsome(char_type* __s, streamsize __n);
00189       
00190       __istream_type& 
00191       putback(char_type __c);
00192 
00193       __istream_type& 
00194       unget(void);
00195 
00196       int 
00197       sync(void);
00198 
00199       pos_type 
00200       tellg(void);
00201 
00202       __istream_type& 
00203       seekg(pos_type);
00204 
00205       __istream_type& 
00206       seekg(off_type, ios_base::seekdir);
00207     };
00208   
00209   template<typename _CharT, typename _Traits>
00210     class basic_istream<_CharT, _Traits>::sentry
00211     {
00212     public:
00213       typedef _Traits                   traits_type;
00214       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00215       typedef basic_istream<_CharT, _Traits>        __istream_type;
00216       typedef typename __istream_type::__ctype_type     __ctype_type;
00217       typedef typename _Traits::int_type        __int_type;
00218 
00219       explicit 
00220       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00221 
00222       operator bool() { return _M_ok; }
00223 
00224     private:
00225       bool _M_ok;
00226     };
00227 
00228   // 27.6.1.2.3 Character extraction templates
00229   template<typename _CharT, typename _Traits>
00230     basic_istream<_CharT, _Traits>&
00231     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00232 
00233   template<class _Traits>
00234     basic_istream<char, _Traits>&
00235     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00236     { return (__in >> reinterpret_cast<char&>(__c)); }
00237 
00238   template<class _Traits>
00239     basic_istream<char, _Traits>&
00240     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00241     { return (__in >> reinterpret_cast<char&>(__c)); }
00242 
00243   template<typename _CharT, typename _Traits>
00244     basic_istream<_CharT, _Traits>&
00245     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00246   
00247   template<class _Traits>
00248     basic_istream<char,_Traits>&
00249     operator>>(basic_istream<char,_Traits>& __in, unsigned char* __s)
00250     { return (__in >> reinterpret_cast<char*>(__s)); }
00251 
00252   template<class _Traits>
00253     basic_istream<char,_Traits>&
00254     operator>>(basic_istream<char,_Traits>& __in, signed char* __s)
00255     { return (__in >> reinterpret_cast<char*>(__s)); }
00256 
00257   // 27.6.1.5 Template class basic_iostream
00258   template<typename _CharT, typename _Traits>
00259     class basic_iostream
00260     : public basic_istream<_CharT, _Traits>, 
00261       public basic_ostream<_CharT, _Traits>
00262     {
00263     public:
00264 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00265 // 271. basic_iostream missing typedefs
00266       // Types (inherited):
00267       typedef _CharT                            char_type;
00268       typedef typename _Traits::int_type        int_type;
00269       typedef typename _Traits::pos_type        pos_type;
00270       typedef typename _Traits::off_type        off_type;
00271       typedef _Traits                           traits_type;
00272 #endif
00273 
00274       // Non-standard Types:
00275       typedef basic_istream<_CharT, _Traits>        __istream_type;
00276       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00277 
00278       explicit 
00279       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00280       : __istream_type(__sb), __ostream_type(__sb)
00281       { }
00282 
00283       virtual 
00284       ~basic_iostream() { }
00285     };
00286 
00287   // 27.6.1.4 Standard basic_istream manipulators
00288   template<typename _CharT, typename _Traits>
00289     basic_istream<_CharT, _Traits>& 
00290     ws(basic_istream<_CharT, _Traits>& __is);
00291 } // namespace std
00292 
00293 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00294 # define export
00295 #endif
00296 #ifdef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
00297 # include <bits/istream.tcc>
00298 #endif
00299 
00300 #endif  /* _CPP_ISTREAM */

Generated on Tue Dec 23 12:34:01 2003 for libstdc++-v3 Source by doxygen 1.3.4