Whole document tree
    

Whole document tree

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

basic_ios.tcc

Go to the documentation of this file.
00001 // basic_ios locale and locale-related member functions -*- C++ -*-
00002 
00003 // Copyright (C) 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_TCC
00031 #define _CPP_BITS_BASICIOS_TCC 1
00032 
00033 namespace std
00034 {
00035   template<typename _CharT, typename _Traits>
00036     basic_streambuf<_CharT, _Traits>* 
00037     basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb)
00038     {
00039       basic_streambuf<_CharT, _Traits>* __old = _M_streambuf;
00040       _M_streambuf = __sb;
00041       this->clear();
00042       return __old;
00043     }
00044 
00045   template<typename _CharT, typename _Traits>
00046     basic_ios<_CharT, _Traits>&
00047     basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
00048     {
00049       // Per 27.1.1.1, do not call imbue, yet must trash all caches
00050       // associated with imbue()
00051 
00052       // Alloc any new word array first, so if it fails we have "rollback".
00053       _Words* __words = (__rhs._M_word_limit <= _S_local_words) ?
00054     _M_word_array : new _Words[__rhs._M_word_limit];
00055 
00056       // XXX This is the only reason _Callback_list was defined
00057       // inline. The suspicion is that this increased compilation
00058       // times dramatically for functions that use this member
00059       // function (inserters_extractors, ios_manip_fmtflags). FIX ME,
00060       // clean this stuff up. Callbacks are broken right now, anyway.
00061 
00062       // Bump refs before doing callbacks, for safety.
00063       _Callback_list* __cb = __rhs._M_callbacks;
00064       if (__cb) 
00065     __cb->_M_add_reference();
00066       _M_call_callbacks(erase_event);
00067       if (_M_words != _M_word_array) 
00068     delete [] _M_words;
00069       _M_dispose_callbacks();
00070 
00071       _M_callbacks = __cb;  // NB: Don't want any added during above.
00072       for (int __i = 0; __i < __rhs._M_word_limit; ++__i)
00073     __words[__i] = __rhs._M_words[__i];
00074       if (_M_words != _M_word_array) 
00075     delete [] _M_words;
00076       _M_words = __words;
00077       _M_word_limit = __rhs._M_word_limit;
00078 
00079       this->flags(__rhs.flags());
00080       this->width(__rhs.width());
00081       this->precision(__rhs.precision());
00082       this->tie(__rhs.tie());
00083       this->fill(__rhs.fill());
00084       // The next is required to be the last assignment.
00085       this->exceptions(__rhs.exceptions());
00086       
00087       _M_call_callbacks(copyfmt_event);
00088       return *this;
00089     }
00090 
00091   template<typename _CharT, typename _Traits>
00092     char
00093     basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
00094     { return _M_ios_fctype->narrow(__c, __dfault); }
00095 
00096   template<typename _CharT, typename _Traits>
00097     _CharT
00098     basic_ios<_CharT, _Traits>::widen(char __c) const
00099     { return _M_ios_fctype->widen(__c); }
00100 
00101   // Locales:
00102   template<typename _CharT, typename _Traits>
00103     locale
00104     basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
00105     {
00106       locale __old(this->getloc());
00107       ios_base::imbue(__loc);
00108       _M_cache_facets(__loc);
00109       if (this->rdbuf() != 0)
00110     this->rdbuf()->pubimbue(__loc);
00111       return __old;
00112     }
00113 
00114   template<typename _CharT, typename _Traits>
00115     void
00116     basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
00117     {
00118       // NB: This may be called more than once on the same object.
00119       ios_base::_M_init();
00120       _M_cache_facets(_M_ios_locale);
00121       _M_tie = 0;
00122       _M_fill = this->widen(' ');
00123       _M_exception = goodbit;
00124       _M_streambuf = __sb;
00125       _M_streambuf_state = __sb ? goodbit : badbit;
00126     }
00127 
00128   template<typename _CharT, typename _Traits>
00129     void
00130     basic_ios<_CharT, _Traits>::_M_cache_facets(const locale& __loc)
00131     {
00132       if (has_facet<__ctype_type>(__loc))
00133     _M_ios_fctype = &use_facet<__ctype_type>(__loc);
00134       // Should be filled in by ostream and istream, respectively.
00135       if (has_facet<__numput_type>(__loc))
00136     _M_fnumput = &use_facet<__numput_type>(__loc); 
00137       if (has_facet<__numget_type>(__loc))
00138     _M_fnumget = &use_facet<__numget_type>(__loc); 
00139     }
00140 } // namespace std
00141 
00142 #endif // _CPP_BITS_BASICIOS_TCC
00143 
00144 
00145 

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