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 
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 _CPP_BITS_BASICIOS_H
00037 #define _CPP_BITS_BASICIOS_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 ostreambuf_iterator<_CharT, _Traits>   __ostreambuf_iter;
00080       typedef num_put<_CharT, __ostreambuf_iter>     __numput_type;
00081       typedef istreambuf_iterator<_CharT, _Traits>   __istreambuf_iter;
00082       typedef num_get<_CharT, __istreambuf_iter>     __numget_type;
00084 
00085       friend void ios_base::Init::_S_ios_create(bool);
00086       
00087       // Data members:
00088     protected:
00089       basic_ostream<_CharT, _Traits>*                _M_tie;
00090       mutable char_type                              _M_fill;
00091       mutable bool                                   _M_fill_init;
00092       basic_streambuf<_CharT, _Traits>*              _M_streambuf;
00093 
00094       // Cached use_facet<ctype>, which is based on the current locale info.
00095       const __ctype_type*                            _M_fctype;      
00096       // From ostream.
00097       const __numput_type*                           _M_fnumput;
00098       // From istream.
00099       const __numget_type*                           _M_fnumget;
00100 
00101     public:
00103 
00109       operator void*() const 
00110       { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
00111 
00112       bool 
00113       operator!() const 
00114       { return this->fail(); }
00116 
00124       iostate 
00125       rdstate() const 
00126       { return _M_streambuf_state; }
00127 
00135       void 
00136       clear(iostate __state = goodbit);
00137 
00144       void 
00145       setstate(iostate __state) 
00146       { this->clear(this->rdstate() | __state); }
00147 
00154       bool 
00155       good() const 
00156       { return this->rdstate() == 0; }
00157 
00164       bool 
00165       eof() const 
00166       { return (this->rdstate() & eofbit) != 0; }
00167 
00175       bool 
00176       fail() const 
00177       { return (this->rdstate() & (badbit | failbit)) != 0; }
00178 
00185       bool 
00186       bad() const 
00187       { return (this->rdstate() & badbit) != 0; }
00188 
00196       iostate 
00197       exceptions() const 
00198       { return _M_exception; }
00199 
00231       void 
00232       exceptions(iostate __except) 
00233       { 
00234         _M_exception = __except; 
00235         this->clear(_M_streambuf_state); 
00236       }
00237 
00238       // Constructor/destructor:
00244       explicit 
00245       basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base() 
00246       { this->init(__sb); }
00247 
00254       virtual 
00255       ~basic_ios() { }
00256       
00257       // Members:
00267       basic_ostream<_CharT, _Traits>*
00268       tie() const      
00269       { return _M_tie; }
00270 
00279       basic_ostream<_CharT, _Traits>*
00280       tie(basic_ostream<_CharT, _Traits>* __tiestr)
00281       {
00282         basic_ostream<_CharT, _Traits>* __old = _M_tie;
00283         _M_tie = __tiestr;
00284         return __old;
00285       }
00286 
00293       basic_streambuf<_CharT, _Traits>*
00294       rdbuf() const    
00295       { return _M_streambuf; }
00296 
00312       basic_streambuf<_CharT, _Traits>* 
00313       rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
00314 
00318       basic_ios&
00319       copyfmt(const basic_ios& __rhs);
00320 
00327       char_type 
00328       fill() const 
00329       {
00330     if (!_M_fill_init)
00331       {
00332         _M_fill = this->widen(' ');
00333         _M_fill_init = true;
00334       }
00335     return _M_fill; 
00336       }
00337 
00347       char_type 
00348       fill(char_type __ch)
00349       {
00350     char_type __old = this->fill();
00351     _M_fill = __ch;
00352     return __old;
00353       }
00354 
00355       // Locales:
00367       locale 
00368       imbue(const locale& __loc);
00369 
00387       char 
00388       narrow(char_type __c, char __dfault) const;
00389 
00405       char_type 
00406       widen(char __c) const;
00407      
00408     protected:
00409       // 27.4.5.1  basic_ios constructors
00416       basic_ios() : ios_base() 
00417       { }
00418 
00427       void 
00428       init(basic_streambuf<_CharT, _Traits>* __sb,
00429        __locale_cache<_CharT>* __cache=0);
00430 
00431       bool
00432       _M_check_facet(const locale::facet* __f) const
00433       {
00434     if (!__f)
00435       __throw_bad_cast();
00436     return true;
00437       }
00438 
00439       void
00440       _M_cache_locale(const locale& __loc,__locale_cache<_CharT>* __cache = 0);
00441 
00442 #if 1
00443       // XXX GLIBCXX_ABI Deprecated, compatibility only.
00444       void
00445       _M_cache_facets(const locale& __loc);
00446 #endif
00447  
00448        // Internal state setter that won't throw, only set the state bits.
00449        // Used to guarantee we don't throw when setting badbit.
00450        void
00451        _M_setstate(iostate __state) { _M_streambuf_state |= __state; }
00452     };
00453 } // namespace std
00454 
00455 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00456 # define export
00457 #include <bits/basic_ios.tcc>
00458 #endif
00459 
00460 #endif /* _CPP_BITS_BASICIOS_H */

Generated on Tue Apr 29 20:16:20 2003 for libstdc++-v3 Source by doxygen1.3