basic_ios.h

Go to the documentation of this file.
00001 // Iostreams base classes -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2004
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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 
00036 #ifndef _BASIC_IOS_H
00037 #define _BASIC_IOS_H 1
00038 
00039 #pragma GCC system_header
00040 
00041 #include <bits/streambuf_iterator.h>
00042 #include <bits/localefwd.h>
00043 #include <bits/locale_classes.h>
00044 #include <bits/locale_facets.h>
00045 
00046 namespace std
00047 {
00048   // 27.4.5  Template class basic_ios
00055   template<typename _CharT, typename _Traits>
00056     class basic_ios : public ios_base
00057     {
00058     public:
00060 
00065       typedef _CharT                                 char_type;
00066       typedef typename _Traits::int_type             int_type;
00067       typedef typename _Traits::pos_type             pos_type;
00068       typedef typename _Traits::off_type             off_type;
00069       typedef _Traits                                traits_type;
00071 
00073 
00078       typedef ctype<_CharT>                          __ctype_type;
00079       typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> >
00080                              __num_put_type;
00081       typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> >
00082                              __num_get_type;
00084 
00085       // Data members:
00086     protected:
00087       basic_ostream<_CharT, _Traits>*                _M_tie;
00088       mutable char_type                              _M_fill;
00089       mutable bool                                   _M_fill_init;
00090       basic_streambuf<_CharT, _Traits>*              _M_streambuf;
00091 
00092       // Cached use_facet<ctype>, which is based on the current locale info.
00093       const __ctype_type*                            _M_ctype;
00094       // For ostream.
00095       const __num_put_type*                          _M_num_put;
00096       // For istream.
00097       const __num_get_type*                          _M_num_get;
00098 
00099     public:
00101 
00107       operator void*() const
00108       { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
00109 
00110       bool
00111       operator!() const
00112       { return this->fail(); }
00114 
00122       iostate
00123       rdstate() const
00124       { return _M_streambuf_state; }
00125 
00133       void
00134       clear(iostate __state = goodbit);
00135 
00142       void
00143       setstate(iostate __state)
00144       { this->clear(this->rdstate() | __state); }
00145 
00146       // Flip the internal state on for the proper state bits, then re
00147       // throws the propagated exception if bit also set in
00148       // exceptions().
00149       void
00150       _M_setstate(iostate __state)
00151       {
00152     // 27.6.1.2.1 Common requirements.
00153     // Turn this on without causing an ios::failure to be thrown.
00154     _M_streambuf_state |= __state;
00155     if (this->exceptions() & __state)
00156       __throw_exception_again;
00157       }
00158 
00165       bool
00166       good() const
00167       { return this->rdstate() == 0; }
00168 
00175       bool
00176       eof() const
00177       { return (this->rdstate() & eofbit) != 0; }
00178 
00186       bool
00187       fail() const
00188       { return (this->rdstate() & (badbit | failbit)) != 0; }
00189 
00196       bool
00197       bad() const
00198       { return (this->rdstate() & badbit) != 0; }
00199 
00207       iostate
00208       exceptions() const
00209       { return _M_exception; }
00210 
00242       void
00243       exceptions(iostate __except)
00244       {
00245         _M_exception = __except;
00246         this->clear(_M_streambuf_state);
00247       }
00248 
00249       // Constructor/destructor:
00255       explicit
00256       basic_ios(basic_streambuf<_CharT, _Traits>* __sb)
00257       : ios_base(), _M_tie(0), _M_fill(), _M_fill_init(false), _M_streambuf(0),
00258       _M_ctype(0), _M_num_put(0), _M_num_get(0)
00259       { this->init(__sb); }
00260 
00267       virtual
00268       ~basic_ios() { }
00269 
00270       // Members:
00280       basic_ostream<_CharT, _Traits>*
00281       tie() const
00282       { return _M_tie; }
00283 
00292       basic_ostream<_CharT, _Traits>*
00293       tie(basic_ostream<_CharT, _Traits>* __tiestr)
00294       {
00295         basic_ostream<_CharT, _Traits>* __old = _M_tie;
00296         _M_tie = __tiestr;
00297         return __old;
00298       }
00299 
00306       basic_streambuf<_CharT, _Traits>*
00307       rdbuf() const
00308       { return _M_streambuf; }
00309 
00332       basic_streambuf<_CharT, _Traits>*
00333       rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
00334 
00346       basic_ios&
00347       copyfmt(const basic_ios& __rhs);
00348 
00355       char_type
00356       fill() const
00357       {
00358     if (!_M_fill_init)
00359       {
00360         _M_fill = this->widen(' ');
00361         _M_fill_init = true;
00362       }
00363     return _M_fill;
00364       }
00365 
00375       char_type
00376       fill(char_type __ch)
00377       {
00378     char_type __old = this->fill();
00379     _M_fill = __ch;
00380     return __old;
00381       }
00382 
00383       // Locales:
00395       locale
00396       imbue(const locale& __loc);
00397 
00415       char
00416       narrow(char_type __c, char __dfault) const;
00417 
00433       char_type
00434       widen(char __c) const;
00435 
00436     protected:
00437       // 27.4.5.1  basic_ios constructors
00444       basic_ios()
00445       : ios_base(), _M_tie(0), _M_fill(char_type()), _M_fill_init(false), 
00446       _M_streambuf(0), _M_ctype(0), _M_num_put(0), _M_num_get(0)
00447       { }
00448 
00455       void
00456       init(basic_streambuf<_CharT, _Traits>* __sb);
00457 
00458       void
00459       _M_cache_locale(const locale& __loc);
00460     };
00461 } // namespace std
00462 
00463 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00464 #include <bits/basic_ios.tcc>
00465 #endif
00466 
00467 #endif /* _BASIC_IOS_H */

Generated on Tue Jan 30 17:31:46 2007 for GNU C++ STL by doxygen 1.3.6