Whole document tree
    

Whole document tree

basic_ios.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

basic_ios.h

Go to the documentation of this file.
00001 // Iostreams base classes -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2001 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 #ifndef _CPP_BITS_BASICIOS_H
00031 #define _CPP_BITS_BASICIOS_H 1
00032 
00033 #pragma GCC system_header
00034 
00035 #include <bits/sbuf_iter.h>
00036 #include <bits/locale_facets.h>
00037 
00038 namespace std 
00039 {
00040   // 27.4.5  Template class basic_ios
00041   template<typename _CharT, typename _Traits>
00042     class basic_ios : public ios_base
00043     {
00044     public:
00045       // Types:
00046       typedef _CharT                char_type;
00047       typedef typename _Traits::int_type    int_type;
00048       typedef typename _Traits::pos_type    pos_type;
00049       typedef typename _Traits::off_type    off_type;
00050       typedef _Traits               traits_type;
00051 
00052       // Non-standard Types:
00053       typedef ctype<_CharT>                     __ctype_type;
00054       typedef ostreambuf_iterator<_CharT, _Traits>      __ostreambuf_iter;
00055       typedef num_put<_CharT, __ostreambuf_iter>        __numput_type;
00056       typedef istreambuf_iterator<_CharT, _Traits>  __istreambuf_iter;
00057       typedef num_get<_CharT, __istreambuf_iter>        __numget_type;
00058       
00059       // Data members:
00060     private:
00061       basic_ostream<_CharT, _Traits>*   _M_tie;
00062       char_type             _M_fill;
00063       iostate               _M_exception;
00064 
00065     protected:
00066       basic_streambuf<_CharT, _Traits>* _M_streambuf;
00067       iostate               _M_streambuf_state;
00068 
00069       // Cached use_facet<ctype>, which is based on the current locale info.
00070       const __ctype_type*       _M_ios_fctype;      
00071       // From ostream.
00072       const __numput_type*      _M_fnumput;
00073       // From istream.
00074       const __numget_type*      _M_fnumget;
00075 
00076     public:
00077       inline const __ctype_type*    
00078       _M_get_fctype_ios(void)
00079       { return _M_ios_fctype; }
00080 
00081       operator void*() const 
00082       { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
00083 
00084       inline bool 
00085       operator!() const 
00086       { return this->fail(); }
00087 
00088       inline iostate 
00089       rdstate() const 
00090       { return _M_streambuf_state; }
00091 
00092       inline void 
00093       clear(iostate __state = goodbit)
00094       { 
00095     if (this->rdbuf())
00096       _M_streambuf_state = __state;
00097     else
00098       _M_streambuf_state = __state | badbit;
00099     if ((this->rdstate() & this->exceptions()))
00100       __throw_ios_failure("basic_ios::clear(iostate) caused exception");
00101       }
00102 
00103       inline void 
00104       setstate(iostate __state) 
00105       { this->clear(this->rdstate() | __state); }
00106 
00107       inline bool 
00108       good() const 
00109       { return this->rdstate() == 0; }
00110 
00111       inline bool 
00112       eof() const 
00113       { return (this->rdstate() & eofbit) != 0; }
00114 
00115       inline bool 
00116       fail() const 
00117       { return (this->rdstate() & (badbit | failbit)) != 0; }
00118 
00119       inline bool 
00120       bad() const 
00121       { return (this->rdstate() & badbit) != 0; }
00122 
00123       inline iostate 
00124       exceptions() const 
00125       { return _M_exception; }
00126 
00127       inline void 
00128       exceptions(iostate __except) 
00129       { 
00130     _M_exception = __except; 
00131     this->clear(_M_streambuf_state); 
00132       }
00133 
00134       // Constructor/destructor:
00135       explicit 
00136       basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base() 
00137       { this->init(__sb); }
00138 
00139       virtual 
00140       ~basic_ios() { }
00141       
00142       // Members:
00143       inline basic_ostream<_CharT, _Traits>*
00144       tie() const      
00145       { return _M_tie; }
00146 
00147       inline basic_ostream<_CharT, _Traits>*
00148       tie(basic_ostream<_CharT, _Traits>* __tiestr)
00149       {
00150     basic_ostream<_CharT, _Traits>* __old = _M_tie;
00151     _M_tie = __tiestr;
00152     return __old;
00153       }
00154 
00155       inline basic_streambuf<_CharT, _Traits>*
00156       rdbuf() const    
00157       { return _M_streambuf; }
00158 
00159       basic_streambuf<_CharT, _Traits>* 
00160       rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
00161 
00162       basic_ios&
00163       copyfmt(const basic_ios& __rhs);
00164 
00165       inline char_type 
00166       fill() const 
00167       { return _M_fill; }
00168 
00169       inline char_type 
00170       fill(char_type __ch)
00171       {
00172     char_type __old = _M_fill;
00173     _M_fill = __ch;
00174     return __old;
00175       }
00176 
00177       // Locales:
00178       locale 
00179       imbue(const locale& __loc);
00180 
00181       char 
00182       narrow(char_type __c, char __dfault) const;
00183 
00184       char_type 
00185       widen(char __c) const;
00186      
00187     protected:
00188       // 27.4.5.1  basic_ios constructors
00189       basic_ios() : ios_base() 
00190       { }
00191 
00192       void 
00193       init(basic_streambuf<_CharT, _Traits>* __sb);
00194 
00195       bool
00196       _M_check_facet(const locale::facet* __f)
00197       {
00198     bool __ret = false;
00199     if (__f)
00200       __ret = true;
00201     else
00202       __throw_bad_cast();
00203     return __ret;
00204       }
00205 
00206       void
00207       _M_cache_facets(const locale& __loc);
00208     };
00209 } // namespace std
00210 
00211 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00212 # define export
00213 #include <bits/basic_ios.tcc>
00214 #endif
00215 
00216 #endif /* _CPP_BITS_BASICIOS_H */
00217 
00218 

Generated on Mon Apr 8 03:11:21 2002 for libstdc++-v3 Source by doxygen1.2.15