istream

Go to the documentation of this file.
00001 // Input streams -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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 
00039 #ifndef _GLIBCXX_ISTREAM
00040 #define _GLIBCXX_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 num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >        
00073                             __num_get_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): _M_gcount(streamsize(0))
00105       { this->init(__sb); }
00106 
00112       virtual 
00113       ~basic_istream() 
00114       { _M_gcount = streamsize(0); }
00115 
00116       // [27.6.1.1.2] prefix/suffix
00117       class sentry;
00118       friend class sentry;
00119 
00120       // [27.6.1.2] formatted input
00121       // [27.6.1.2.3] basic_istream::operator>>
00123 
00130       inline __istream_type&
00131       operator>>(__istream_type& (*__pf)(__istream_type&));
00132 
00133       inline __istream_type&
00134       operator>>(__ios_type& (*__pf)(__ios_type&));
00135 
00136       inline __istream_type&
00137       operator>>(ios_base& (*__pf)(ios_base&));
00139       
00140       // [27.6.1.2.2] arithmetic extractors
00168       __istream_type& 
00169       operator>>(bool& __n);
00170       
00171       __istream_type& 
00172       operator>>(short& __n);
00173       
00174       __istream_type& 
00175       operator>>(unsigned short& __n);
00176 
00177       __istream_type& 
00178       operator>>(int& __n);
00179       
00180       __istream_type& 
00181       operator>>(unsigned int& __n);
00182 
00183       __istream_type& 
00184       operator>>(long& __n);
00185       
00186       __istream_type& 
00187       operator>>(unsigned long& __n);
00188 
00189 #ifdef _GLIBCXX_USE_LONG_LONG
00190       __istream_type& 
00191       operator>>(long long& __n);
00192 
00193       __istream_type& 
00194       operator>>(unsigned long long& __n);
00195 #endif
00196 
00197       __istream_type& 
00198       operator>>(float& __f);
00199 
00200       __istream_type& 
00201       operator>>(double& __f);
00202 
00203       __istream_type& 
00204       operator>>(long double& __f);
00205 
00206       __istream_type& 
00207       operator>>(void*& __p);
00208 
00229       __istream_type& 
00230       operator>>(__streambuf_type* __sb);
00232       
00233       // [27.6.1.3] unformatted input
00239       inline streamsize 
00240       gcount() const 
00241       { return _M_gcount; }
00242       
00271       int_type 
00272       get();
00273 
00285       __istream_type& 
00286       get(char_type& __c);
00287 
00312       __istream_type& 
00313       get(char_type* __s, streamsize __n, char_type __delim);
00314 
00323       inline __istream_type& 
00324       get(char_type* __s, streamsize __n)
00325       { return this->get(__s, __n, this->widen('\n')); }
00326 
00346       __istream_type&
00347       get(__streambuf_type& __sb, char_type __delim);
00348 
00356       inline __istream_type&
00357       get(__streambuf_type& __sb)
00358       { return this->get(__sb, this->widen('\n')); }
00359 
00385       __istream_type& 
00386       getline(char_type* __s, streamsize __n, char_type __delim);
00387 
00396       inline __istream_type& 
00397       getline(char_type* __s, streamsize __n)
00398       { return this->getline(__s, __n, this->widen('\n')); }
00399 
00420       __istream_type& 
00421       ignore();
00422 
00423       __istream_type& 
00424       ignore(streamsize __n);
00425 
00426       __istream_type& 
00427       ignore(streamsize __n, int_type __delim);
00428       
00437       int_type 
00438       peek();
00439       
00455       __istream_type& 
00456       read(char_type* __s, streamsize __n);
00457 
00474       streamsize 
00475       readsome(char_type* __s, streamsize __n);
00476       
00490       __istream_type& 
00491       putback(char_type __c);
00492 
00505       __istream_type& 
00506       unget();
00507 
00523       int 
00524       sync();
00525 
00537       pos_type 
00538       tellg();
00539 
00552       __istream_type& 
00553       seekg(pos_type);
00554 
00568       __istream_type& 
00569       seekg(off_type, ios_base::seekdir);
00571 
00572     protected:
00573       explicit 
00574       basic_istream(): _M_gcount(streamsize(0)) { }
00575     };
00576 
00577   // Explicit specialization declarations, defined in src/istream.cc.
00578   template<> 
00579     basic_istream<char>& 
00580     basic_istream<char>::
00581     getline(char_type* __s, streamsize __n, char_type __delim);
00582   
00583   template<>
00584     basic_istream<char>&
00585     basic_istream<char>::
00586     ignore(streamsize __n);
00587   
00588   template<>
00589     basic_istream<char>&
00590     basic_istream<char>::
00591     ignore(streamsize __n, int_type __delim);
00592 
00593 #ifdef _GLIBCXX_USE_WCHAR_T
00594   template<> 
00595     basic_istream<wchar_t>& 
00596     basic_istream<wchar_t>::
00597     getline(char_type* __s, streamsize __n, char_type __delim);
00598 
00599   template<>
00600     basic_istream<wchar_t>&
00601     basic_istream<wchar_t>::
00602     ignore(streamsize __n);
00603   
00604   template<>
00605     basic_istream<wchar_t>&
00606     basic_istream<wchar_t>::
00607     ignore(streamsize __n, int_type __delim);
00608 #endif
00609 
00621   template<typename _CharT, typename _Traits>
00622     class basic_istream<_CharT, _Traits>::sentry
00623     {
00624     public:
00626       typedef _Traits                   traits_type;
00627       typedef basic_streambuf<_CharT, _Traits>      __streambuf_type;
00628       typedef basic_istream<_CharT, _Traits>        __istream_type;
00629       typedef typename __istream_type::__ctype_type     __ctype_type;
00630       typedef typename _Traits::int_type        __int_type;
00631 
00653       explicit 
00654       sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
00655 
00663       operator bool() const { return _M_ok; }
00664 
00665     private:
00666       bool _M_ok;
00667     };
00668 
00669   // [27.6.1.2.3] character extraction templates
00671 
00682   template<typename _CharT, typename _Traits>
00683     basic_istream<_CharT, _Traits>&
00684     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c);
00685 
00686   template<class _Traits>
00687     basic_istream<char, _Traits>&
00688     operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c)
00689     { return (__in >> reinterpret_cast<char&>(__c)); }
00690 
00691   template<class _Traits>
00692     basic_istream<char, _Traits>&
00693     operator>>(basic_istream<char, _Traits>& __in, signed char& __c)
00694     { return (__in >> reinterpret_cast<char&>(__c)); }
00696 
00698 
00723   template<typename _CharT, typename _Traits>
00724     basic_istream<_CharT, _Traits>&
00725     operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s);
00726 
00727   // Explicit specialization declaration, defined in src/istream.cc.
00728   template<>
00729     basic_istream<char>&
00730     operator>>(basic_istream<char>& __in, char* __s);
00731 
00732   template<class _Traits>
00733     basic_istream<char, _Traits>&
00734     operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s)
00735     { return (__in >> reinterpret_cast<char*>(__s)); }
00736 
00737   template<class _Traits>
00738     basic_istream<char, _Traits>&
00739     operator>>(basic_istream<char, _Traits>& __in, signed char* __s)
00740     { return (__in >> reinterpret_cast<char*>(__s)); }
00742 
00743   // 27.6.1.5 Template class basic_iostream
00750   template<typename _CharT, typename _Traits>
00751     class basic_iostream
00752     : public basic_istream<_CharT, _Traits>, 
00753       public basic_ostream<_CharT, _Traits>
00754     {
00755     public:
00756       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00757       // 271. basic_iostream missing typedefs
00758       // Types (inherited):
00759       typedef _CharT                            char_type;
00760       typedef typename _Traits::int_type        int_type;
00761       typedef typename _Traits::pos_type        pos_type;
00762       typedef typename _Traits::off_type        off_type;
00763       typedef _Traits                           traits_type;
00764 
00765       // Non-standard Types:
00766       typedef basic_istream<_CharT, _Traits>        __istream_type;
00767       typedef basic_ostream<_CharT, _Traits>        __ostream_type;
00768 
00775       explicit 
00776       basic_iostream(basic_streambuf<_CharT, _Traits>* __sb)
00777       : __istream_type(), __ostream_type()
00778       { this->init(__sb); }
00779 
00783       virtual 
00784       ~basic_iostream() { }
00785 
00786     protected:
00787       explicit 
00788       basic_iostream() : __istream_type(), __ostream_type()
00789       { }
00790     };
00791 
00792   // [27.6.1.4] standard basic_istream manipulators
00813   template<typename _CharT, typename _Traits>
00814     basic_istream<_CharT, _Traits>& 
00815     ws(basic_istream<_CharT, _Traits>& __is);
00816 } // namespace std
00817 
00818 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00819 # include <bits/istream.tcc>
00820 #endif
00821 
00822 #endif  /* _GLIBCXX_ISTREAM */

Generated on Tue Feb 2 16:56:10 2010 for GNU C++ STL by  doxygen 1.4.7