basic_ios.tcc revision 132720
150476Speter// basic_ios member functions -*- C++ -*- 215903Swosch 315903Swosch// Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. 415903Swosch// 515903Swosch// This file is part of the GNU ISO C++ Library. This library is free 615903Swosch// software; you can redistribute it and/or modify it under the 715903Swosch// terms of the GNU General Public License as published by the 815903Swosch// Free Software Foundation; either version 2, or (at your option) 915903Swosch// any later version. 1015903Swosch 1115903Swosch// This library is distributed in the hope that it will be useful, 1215903Swosch// but WITHOUT ANY WARRANTY; without even the implied warranty of 1315903Swosch// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14139761Skrion// GNU General Public License for more details. 1534678Sbde 1623546Swosch// You should have received a copy of the GNU General Public License along 1723546Swosch// with this library; see the file COPYING. If not, write to the Free 1823546Swosch// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 1939161Sobrien// USA. 2015903Swosch 2139161Sobrien// As a special exception, you may use this file as part of a free software 2215903Swosch// library without restriction. Specifically, if other files instantiate 2315903Swosch// templates or use macros or inline functions from this file, or you compile 2415903Swosch// this file and link it with other files to produce an executable, this 2515903Swosch// file does not by itself cause the resulting executable to be covered by 2615903Swosch// the GNU General Public License. This exception does not however 2715903Swosch// invalidate any other reasons why the executable file might be covered by 2815903Swosch// the GNU General Public License. 2932216Swosch 3032216Swosch#ifndef _BASIC_IOS_TCC 3132216Swosch#define _BASIC_IOS_TCC 1 3232216Swosch 3315903Swosch#pragma GCC system_header 3415903Swosch 3515903Swoschnamespace std 3615903Swosch{ 37119057Sobrien template<typename _CharT, typename _Traits> 3815903Swosch void 3915903Swosch basic_ios<_CharT, _Traits>::clear(iostate __state) 4015903Swosch { 4115903Swosch if (this->rdbuf()) 4215903Swosch _M_streambuf_state = __state; 4315903Swosch else 4415903Swosch _M_streambuf_state = __state | badbit; 4565501Sobrien if (this->exceptions() & this->rdstate()) 4615903Swosch __throw_ios_failure(__N("basic_ios::clear")); 47186894Sbz } 4815903Swosch 49186894Sbz template<typename _CharT, typename _Traits> 5015903Swosch basic_streambuf<_CharT, _Traits>* 5153033Sphantom basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb) 5215903Swosch { 5315903Swosch basic_streambuf<_CharT, _Traits>* __old = _M_streambuf; 5415903Swosch _M_streambuf = __sb; 5515903Swosch this->clear(); 5615903Swosch return __old; 5739161Sobrien } 5815903Swosch 5939161Sobrien template<typename _CharT, typename _Traits> 6015903Swosch basic_ios<_CharT, _Traits>& 6115903Swosch basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) 6215903Swosch { 6315903Swosch // _GLIBCXX_RESOLVE_LIB_DEFECTS 6415903Swosch // 292. effects of a.copyfmt (a) 6515903Swosch if (this != &__rhs) 6615903Swosch { 6715903Swosch // Per 27.1.1, do not call imbue, yet must trash all caches 6815903Swosch // associated with imbue() 6915903Swosch 7015903Swosch // Alloc any new word array first, so if it fails we have "rollback". 7115903Swosch _Words* __words = (__rhs._M_word_size <= _S_local_word_size) ? 7215903Swosch _M_local_word : new _Words[__rhs._M_word_size]; 7315903Swosch 7415903Swosch // Bump refs before doing callbacks, for safety. 7515903Swosch _Callback_list* __cb = __rhs._M_callbacks; 7615903Swosch if (__cb) 7715903Swosch __cb->_M_add_reference(); 7815903Swosch _M_call_callbacks(erase_event); 7915903Swosch if (_M_word != _M_local_word) 8015903Swosch { 8115903Swosch delete [] _M_word; 8215903Swosch _M_word = 0; 8315903Swosch } 8415903Swosch _M_dispose_callbacks(); 8515903Swosch 8615903Swosch // NB: Don't want any added during above. 8715903Swosch _M_callbacks = __cb; 8815903Swosch for (int __i = 0; __i < __rhs._M_word_size; ++__i) 8915903Swosch __words[__i] = __rhs._M_word[__i]; 9015903Swosch if (_M_word != _M_local_word) 9115903Swosch { 9215903Swosch delete [] _M_word; 9315903Swosch _M_word = 0; 9490627Sphantom } 9515903Swosch _M_word = __words; 9690626Sphantom _M_word_size = __rhs._M_word_size; 9715903Swosch 9890626Sphantom this->flags(__rhs.flags()); 9915903Swosch this->width(__rhs.width()); 10061462Sghelmer this->precision(__rhs.precision()); 10115903Swosch this->tie(__rhs.tie()); 10232216Swosch this->fill(__rhs.fill()); 10315903Swosch _M_ios_locale = __rhs.getloc(); 10494982Sru _M_cache_locale(_M_ios_locale); 10594982Sru 10694982Sru _M_call_callbacks(copyfmt_event); 107164411Sru 108156813Sru // The next is required to be the last assignment. 109156836Sru this->exceptions(__rhs.exceptions()); 110156836Sru } 111156836Sru return *this; 112164411Sru } 113156813Sru 11414968Swosch template<typename _CharT, typename _Traits> 11539161Sobrien char 11639161Sobrien basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const 11714573Swosch { return __check_facet(_M_ctype).narrow(__c, __dfault); } 11814968Swosch 11914573Swosch template<typename _CharT, typename _Traits> 120111853Sru _CharT 121111853Sru basic_ios<_CharT, _Traits>::widen(char __c) const 122111853Sru { return __check_facet(_M_ctype).widen(__c); } 12365501Sobrien 124111853Sru // Locales: 12548204Sjmg template<typename _CharT, typename _Traits> 12648204Sjmg locale 12748204Sjmg basic_ios<_CharT, _Traits>::imbue(const locale& __loc) 12848204Sjmg { 12914573Swosch locale __old(this->getloc()); 13032226Ssteve ios_base::imbue(__loc); 13132226Ssteve _M_cache_locale(__loc); 13214573Swosch if (this->rdbuf() != 0) 13314573Swosch this->rdbuf()->pubimbue(__loc); 13414968Swosch return __old; 13514968Swosch } 13614968Swosch 13714573Swosch template<typename _CharT, typename _Traits> 13814968Swosch void 13914968Swosch basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb) 14014968Swosch { 14139161Sobrien // NB: This may be called more than once on the same object. 14239161Sobrien ios_base::_M_init(); 14314968Swosch 14414968Swosch // Cache locale data and specific facets used by iostreams. 14514968Swosch _M_cache_locale(_M_ios_locale); 14614968Swosch 14714968Swosch // NB: The 27.4.4.1 Postconditions Table specifies requirements 14814968Swosch // after basic_ios::init() has been called. As part of this, 14914968Swosch // fill() must return widen(' ') any time after init() has been 15014968Swosch // called, which needs an imbued ctype facet of char_type to 15114968Swosch // return without throwing an exception. Unfortunately, 15214968Swosch // ctype<char_type> is not necessarily a required facet, so 15314968Swosch // streams with char_type != [char, wchar_t] will not have it by 15414968Swosch // default. Because of this, the correct value for _M_fill is 15514968Swosch // constructed on the first call of fill(). That way, 15614968Swosch // unformatted input and output with non-required basic_ios 15714968Swosch // instantiations is possible even without imbuing the expected 15814968Swosch // ctype<char_type> facet. 15914968Swosch _M_fill = _CharT(); 16014968Swosch _M_fill_init = false; 16190626Sphantom 16290626Sphantom _M_tie = 0; 16361462Sghelmer _M_exception = goodbit; 16414968Swosch _M_streambuf = __sb; 16532216Swosch _M_streambuf_state = __sb ? goodbit : badbit; 16632216Swosch } 16714968Swosch 168125494Sru template<typename _CharT, typename _Traits> 169125494Sru void 170125494Sru basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc) 171125494Sru { 17234678Sbde if (__builtin_expect(has_facet<__ctype_type>(__loc), true)) 17323546Swosch _M_ctype = &use_facet<__ctype_type>(__loc); 17494982Sru else 175164411Sru _M_ctype = 0; 176156813Sru 177156813Sru if (__builtin_expect(has_facet<__num_put_type>(__loc), true)) 178156813Sru _M_num_put = &use_facet<__num_put_type>(__loc); 179156813Sru else 180156813Sru _M_num_put = 0; 181156813Sru 182156813Sru if (__builtin_expect(has_facet<__num_get_type>(__loc), true)) 183156813Sru _M_num_get = &use_facet<__num_get_type>(__loc); 184156813Sru else 185156813Sru _M_num_get = 0; 186156813Sru } 187156813Sru 188156813Sru // Inhibit implicit instantiations for required instantiations, 189172832Sru // which are defined via explicit instantiations elsewhere. 190156869Sru // NB: This syntax is a GNU extension. 191156869Sru#if _GLIBCXX_EXTERN_TEMPLATE 192156813Sru extern template class basic_ios<char>; 193156813Sru 194156813Sru#ifdef _GLIBCXX_USE_WCHAR_T 195156813Sru extern template class basic_ios<wchar_t>; 196156813Sru#endif 197156813Sru#endif 198156813Sru} // namespace std 199156813Sru 200156813Sru#endif 201156813Sru