# 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
    00052   template<typename _CharT, typename _Traits>
    00053     class basic_ios : public ios_base
    00054     {
    00055     public:
    00057
    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;
    00068
    00070
    00075       typedef ctype<_CharT>                          __ctype_type;
    00076       typedef ostreambuf_iterator<_CharT, _Traits>   __ostreambuf_iter;
    00077       typedef num_put<_CharT, __ostreambuf_iter>     __numput_type;
    00078       typedef istreambuf_iterator<_CharT, _Traits>   __istreambuf_iter;
    00079       typedef num_get<_CharT, __istreambuf_iter>     __numget_type;
    00081
    00082       // Data members:
    00083     protected:
    00084       basic_ostream<_CharT, _Traits>*                _M_tie;
    00085       mutable char_type                              _M_fill;
    00086       mutable bool                                   _M_fill_init;
    00087       basic_streambuf<_CharT, _Traits>*              _M_streambuf;
    00088
    00089       // Cached use_facet<ctype>, which is based on the current locale info.
    00090       const __ctype_type*                            _M_fctype;
    00091       // From ostream.
    00092       const __numput_type*                           _M_fnumput;
    00093       // From istream.
    00094       const __numget_type*                           _M_fnumget;
    00095
    00096     public:
    00098
    00104       operator void*() const
    00105       { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
    00106
    00107       bool
    00108       operator!() const
    00109       { return this->fail(); }
    00111
    00119       iostate
    00120       rdstate() const
    00121       { return _M_streambuf_state; }
    00122
    00130       void
    00131       clear(iostate __state = goodbit);
    00132
    00139       void
    00140       setstate(iostate __state)
    00141       { this->clear(this->rdstate() | __state); }
    00142
    00149       bool
    00150       good() const
    00151       { return this->rdstate() == 0; }
    00152
    00159       bool
    00160       eof() const
    00161       { return (this->rdstate() & eofbit) != 0; }
    00162
    00170       bool
    00171       fail() const
    00172       { return (this->rdstate() & (badbit | failbit)) != 0; }
    00173
    00180       bool
    00181       bad() const
    00182       { return (this->rdstate() & badbit) != 0; }
    00183
    00191       iostate
    00192       exceptions() const
    00193       { return _M_exception; }
    00194
    00226       void
    00227       exceptions(iostate __except)
    00228       {
    00229         _M_exception = __except;
    00230         this->clear(_M_streambuf_state);
    00231       }
    00232
    00233       // Constructor/destructor:
    00239       explicit
    00240       basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base()
    00241       { this->init(__sb); }
    00242
    00249       virtual
    00250       ~basic_ios() { }
    00251
    00252       // Members:
    00262       basic_ostream<_CharT, _Traits>*
    00263       tie() const
    00264       { return _M_tie; }
    00265
    00274       basic_ostream<_CharT, _Traits>*
    00275       tie(basic_ostream<_CharT, _Traits>* __tiestr)
    00276       {
    00277         basic_ostream<_CharT, _Traits>* __old = _M_tie;
    00278         _M_tie = __tiestr;
    00279         return __old;
    00280       }
    00281
    00288       basic_streambuf<_CharT, _Traits>*
    00289       rdbuf() const
    00290       { return _M_streambuf; }
    00291
    00307       basic_streambuf<_CharT, _Traits>*
    00308       rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
    00309
    00313       basic_ios&
    00314       copyfmt(const basic_ios& __rhs);
    00315
    00322       char_type
    00323       fill() const
    00324       {
    00325     if (!_M_fill_init)
    00326       {
    00327         _M_fill = this->widen(' ');
    00328         _M_fill_init = true;
    00329       }
    00330     return _M_fill;
    00331       }
    00332
    00342       char_type
    00343       fill(char_type __ch)
    00344       {
    00345     char_type __old = this->fill();
    00346     _M_fill = __ch;
    00347     return __old;
    00348       }
    00349
    00350       // Locales:
    00362       locale
    00363       imbue(const locale& __loc);
    00364
    00382       char
    00383       narrow(char_type __c, char __dfault) const;
    00384
    00400       char_type
    00401       widen(char __c) const;
    00402
    00403     protected:
    00404       // 27.4.5.1  basic_ios constructors
    00411       basic_ios() : ios_base()
    00412       { }
    00413
    00420       void
    00421       init(basic_streambuf<_CharT, _Traits>* __sb);
    00422
    00423       bool
    00424       _M_check_facet(const locale::facet* __f) const
    00425       {
    00426     if (!__f)
    00427       __throw_bad_cast();
    00428     return true;
    00429       }
    00430
    00431       void
    00432       _M_cache_facets(const locale& __loc);
    00433     };
    00434 } // namespace std
    00435
    00436 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
    00437 # define export
    00438 #include <bits/basic_ios.tcc>
    00439 #endif
    00440
    00441 #endif /* _CPP_BITS_BASICIOS_H */