1*e4b17023SJohn Marino // basic_ios member functions -*- C++ -*- 2*e4b17023SJohn Marino 3*e4b17023SJohn Marino // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 4*e4b17023SJohn Marino // 2009, 2010, 2011 Free Software Foundation, Inc. 5*e4b17023SJohn Marino // 6*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 7*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 8*e4b17023SJohn Marino // terms of the GNU General Public License as published by the 9*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 10*e4b17023SJohn Marino // any later version. 11*e4b17023SJohn Marino 12*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 13*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 14*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*e4b17023SJohn Marino // GNU General Public License for more details. 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 18*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 19*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 20*e4b17023SJohn Marino 21*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 22*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 23*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 25*e4b17023SJohn Marino 26*e4b17023SJohn Marino /** @file bits/basic_ios.tcc 27*e4b17023SJohn Marino * This is an internal header file, included by other library headers. 28*e4b17023SJohn Marino * Do not attempt to use it directly. @headername{ios} 29*e4b17023SJohn Marino */ 30*e4b17023SJohn Marino 31*e4b17023SJohn Marino #ifndef _BASIC_IOS_TCC 32*e4b17023SJohn Marino #define _BASIC_IOS_TCC 1 33*e4b17023SJohn Marino 34*e4b17023SJohn Marino #pragma GCC system_header 35*e4b17023SJohn Marino 36*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 37*e4b17023SJohn Marino { 38*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 39*e4b17023SJohn Marino 40*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 41*e4b17023SJohn Marino void clear(iostate __state)42*e4b17023SJohn Marino basic_ios<_CharT, _Traits>::clear(iostate __state) 43*e4b17023SJohn Marino { 44*e4b17023SJohn Marino if (this->rdbuf()) 45*e4b17023SJohn Marino _M_streambuf_state = __state; 46*e4b17023SJohn Marino else 47*e4b17023SJohn Marino _M_streambuf_state = __state | badbit; 48*e4b17023SJohn Marino if (this->exceptions() & this->rdstate()) 49*e4b17023SJohn Marino __throw_ios_failure(__N("basic_ios::clear")); 50*e4b17023SJohn Marino } 51*e4b17023SJohn Marino 52*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 53*e4b17023SJohn Marino basic_streambuf<_CharT, _Traits>* rdbuf(basic_streambuf<_CharT,_Traits> * __sb)54*e4b17023SJohn Marino basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb) 55*e4b17023SJohn Marino { 56*e4b17023SJohn Marino basic_streambuf<_CharT, _Traits>* __old = _M_streambuf; 57*e4b17023SJohn Marino _M_streambuf = __sb; 58*e4b17023SJohn Marino this->clear(); 59*e4b17023SJohn Marino return __old; 60*e4b17023SJohn Marino } 61*e4b17023SJohn Marino 62*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 63*e4b17023SJohn Marino basic_ios<_CharT, _Traits>& copyfmt(const basic_ios & __rhs)64*e4b17023SJohn Marino basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) 65*e4b17023SJohn Marino { 66*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 67*e4b17023SJohn Marino // 292. effects of a.copyfmt (a) 68*e4b17023SJohn Marino if (this != &__rhs) 69*e4b17023SJohn Marino { 70*e4b17023SJohn Marino // Per 27.1.1, do not call imbue, yet must trash all caches 71*e4b17023SJohn Marino // associated with imbue() 72*e4b17023SJohn Marino 73*e4b17023SJohn Marino // Alloc any new word array first, so if it fails we have "rollback". 74*e4b17023SJohn Marino _Words* __words = (__rhs._M_word_size <= _S_local_word_size) ? 75*e4b17023SJohn Marino _M_local_word : new _Words[__rhs._M_word_size]; 76*e4b17023SJohn Marino 77*e4b17023SJohn Marino // Bump refs before doing callbacks, for safety. 78*e4b17023SJohn Marino _Callback_list* __cb = __rhs._M_callbacks; 79*e4b17023SJohn Marino if (__cb) 80*e4b17023SJohn Marino __cb->_M_add_reference(); 81*e4b17023SJohn Marino _M_call_callbacks(erase_event); 82*e4b17023SJohn Marino if (_M_word != _M_local_word) 83*e4b17023SJohn Marino { 84*e4b17023SJohn Marino delete [] _M_word; 85*e4b17023SJohn Marino _M_word = 0; 86*e4b17023SJohn Marino } 87*e4b17023SJohn Marino _M_dispose_callbacks(); 88*e4b17023SJohn Marino 89*e4b17023SJohn Marino // NB: Don't want any added during above. 90*e4b17023SJohn Marino _M_callbacks = __cb; 91*e4b17023SJohn Marino for (int __i = 0; __i < __rhs._M_word_size; ++__i) 92*e4b17023SJohn Marino __words[__i] = __rhs._M_word[__i]; 93*e4b17023SJohn Marino _M_word = __words; 94*e4b17023SJohn Marino _M_word_size = __rhs._M_word_size; 95*e4b17023SJohn Marino 96*e4b17023SJohn Marino this->flags(__rhs.flags()); 97*e4b17023SJohn Marino this->width(__rhs.width()); 98*e4b17023SJohn Marino this->precision(__rhs.precision()); 99*e4b17023SJohn Marino this->tie(__rhs.tie()); 100*e4b17023SJohn Marino this->fill(__rhs.fill()); 101*e4b17023SJohn Marino _M_ios_locale = __rhs.getloc(); 102*e4b17023SJohn Marino _M_cache_locale(_M_ios_locale); 103*e4b17023SJohn Marino 104*e4b17023SJohn Marino _M_call_callbacks(copyfmt_event); 105*e4b17023SJohn Marino 106*e4b17023SJohn Marino // The next is required to be the last assignment. 107*e4b17023SJohn Marino this->exceptions(__rhs.exceptions()); 108*e4b17023SJohn Marino } 109*e4b17023SJohn Marino return *this; 110*e4b17023SJohn Marino } 111*e4b17023SJohn Marino 112*e4b17023SJohn Marino // Locales: 113*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 114*e4b17023SJohn Marino locale imbue(const locale & __loc)115*e4b17023SJohn Marino basic_ios<_CharT, _Traits>::imbue(const locale& __loc) 116*e4b17023SJohn Marino { 117*e4b17023SJohn Marino locale __old(this->getloc()); 118*e4b17023SJohn Marino ios_base::imbue(__loc); 119*e4b17023SJohn Marino _M_cache_locale(__loc); 120*e4b17023SJohn Marino if (this->rdbuf() != 0) 121*e4b17023SJohn Marino this->rdbuf()->pubimbue(__loc); 122*e4b17023SJohn Marino return __old; 123*e4b17023SJohn Marino } 124*e4b17023SJohn Marino 125*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 126*e4b17023SJohn Marino void init(basic_streambuf<_CharT,_Traits> * __sb)127*e4b17023SJohn Marino basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb) 128*e4b17023SJohn Marino { 129*e4b17023SJohn Marino // NB: This may be called more than once on the same object. 130*e4b17023SJohn Marino ios_base::_M_init(); 131*e4b17023SJohn Marino 132*e4b17023SJohn Marino // Cache locale data and specific facets used by iostreams. 133*e4b17023SJohn Marino _M_cache_locale(_M_ios_locale); 134*e4b17023SJohn Marino 135*e4b17023SJohn Marino // NB: The 27.4.4.1 Postconditions Table specifies requirements 136*e4b17023SJohn Marino // after basic_ios::init() has been called. As part of this, 137*e4b17023SJohn Marino // fill() must return widen(' ') any time after init() has been 138*e4b17023SJohn Marino // called, which needs an imbued ctype facet of char_type to 139*e4b17023SJohn Marino // return without throwing an exception. Unfortunately, 140*e4b17023SJohn Marino // ctype<char_type> is not necessarily a required facet, so 141*e4b17023SJohn Marino // streams with char_type != [char, wchar_t] will not have it by 142*e4b17023SJohn Marino // default. Because of this, the correct value for _M_fill is 143*e4b17023SJohn Marino // constructed on the first call of fill(). That way, 144*e4b17023SJohn Marino // unformatted input and output with non-required basic_ios 145*e4b17023SJohn Marino // instantiations is possible even without imbuing the expected 146*e4b17023SJohn Marino // ctype<char_type> facet. 147*e4b17023SJohn Marino _M_fill = _CharT(); 148*e4b17023SJohn Marino _M_fill_init = false; 149*e4b17023SJohn Marino 150*e4b17023SJohn Marino _M_tie = 0; 151*e4b17023SJohn Marino _M_exception = goodbit; 152*e4b17023SJohn Marino _M_streambuf = __sb; 153*e4b17023SJohn Marino _M_streambuf_state = __sb ? goodbit : badbit; 154*e4b17023SJohn Marino } 155*e4b17023SJohn Marino 156*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 157*e4b17023SJohn Marino void _M_cache_locale(const locale & __loc)158*e4b17023SJohn Marino basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc) 159*e4b17023SJohn Marino { 160*e4b17023SJohn Marino if (__builtin_expect(has_facet<__ctype_type>(__loc), true)) 161*e4b17023SJohn Marino _M_ctype = &use_facet<__ctype_type>(__loc); 162*e4b17023SJohn Marino else 163*e4b17023SJohn Marino _M_ctype = 0; 164*e4b17023SJohn Marino 165*e4b17023SJohn Marino if (__builtin_expect(has_facet<__num_put_type>(__loc), true)) 166*e4b17023SJohn Marino _M_num_put = &use_facet<__num_put_type>(__loc); 167*e4b17023SJohn Marino else 168*e4b17023SJohn Marino _M_num_put = 0; 169*e4b17023SJohn Marino 170*e4b17023SJohn Marino if (__builtin_expect(has_facet<__num_get_type>(__loc), true)) 171*e4b17023SJohn Marino _M_num_get = &use_facet<__num_get_type>(__loc); 172*e4b17023SJohn Marino else 173*e4b17023SJohn Marino _M_num_get = 0; 174*e4b17023SJohn Marino } 175*e4b17023SJohn Marino 176*e4b17023SJohn Marino // Inhibit implicit instantiations for required instantiations, 177*e4b17023SJohn Marino // which are defined via explicit instantiations elsewhere. 178*e4b17023SJohn Marino #if _GLIBCXX_EXTERN_TEMPLATE 179*e4b17023SJohn Marino extern template class basic_ios<char>; 180*e4b17023SJohn Marino 181*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 182*e4b17023SJohn Marino extern template class basic_ios<wchar_t>; 183*e4b17023SJohn Marino #endif 184*e4b17023SJohn Marino #endif 185*e4b17023SJohn Marino 186*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 187*e4b17023SJohn Marino } // namespace std 188*e4b17023SJohn Marino 189*e4b17023SJohn Marino #endif 190