# basic_ios.h

Go to the documentation of this file.

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