1 // basic_ios member functions -*- C++ -*-
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file basic_ios.tcc
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
36 #ifndef _BASIC_IOS_TCC
37 #define _BASIC_IOS_TCC 1
39 #pragma GCC system_header
41 _GLIBCXX_BEGIN_NAMESPACE(std)
43 template<typename _CharT, typename _Traits>
45 basic_ios<_CharT, _Traits>::clear(iostate __state)
48 _M_streambuf_state = __state;
50 _M_streambuf_state = __state | badbit;
51 if (this->exceptions() & this->rdstate())
52 __throw_ios_failure(__N("basic_ios::clear"));
55 template<typename _CharT, typename _Traits>
56 basic_streambuf<_CharT, _Traits>*
57 basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb)
59 basic_streambuf<_CharT, _Traits>* __old = _M_streambuf;
65 template<typename _CharT, typename _Traits>
66 basic_ios<_CharT, _Traits>&
67 basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
69 // _GLIBCXX_RESOLVE_LIB_DEFECTS
70 // 292. effects of a.copyfmt (a)
73 // Per 27.1.1, do not call imbue, yet must trash all caches
74 // associated with imbue()
76 // Alloc any new word array first, so if it fails we have "rollback".
77 _Words* __words = (__rhs._M_word_size <= _S_local_word_size) ?
78 _M_local_word : new _Words[__rhs._M_word_size];
80 // Bump refs before doing callbacks, for safety.
81 _Callback_list* __cb = __rhs._M_callbacks;
83 __cb->_M_add_reference();
84 _M_call_callbacks(erase_event);
85 if (_M_word != _M_local_word)
90 _M_dispose_callbacks();
92 // NB: Don't want any added during above.
94 for (int __i = 0; __i < __rhs._M_word_size; ++__i)
95 __words[__i] = __rhs._M_word[__i];
97 _M_word_size = __rhs._M_word_size;
99 this->flags(__rhs.flags());
100 this->width(__rhs.width());
101 this->precision(__rhs.precision());
102 this->tie(__rhs.tie());
103 this->fill(__rhs.fill());
104 _M_ios_locale = __rhs.getloc();
105 _M_cache_locale(_M_ios_locale);
107 _M_call_callbacks(copyfmt_event);
109 // The next is required to be the last assignment.
110 this->exceptions(__rhs.exceptions());
116 template<typename _CharT, typename _Traits>
118 basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
120 locale __old(this->getloc());
121 ios_base::imbue(__loc);
122 _M_cache_locale(__loc);
123 if (this->rdbuf() != 0)
124 this->rdbuf()->pubimbue(__loc);
128 template<typename _CharT, typename _Traits>
130 basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
132 // NB: This may be called more than once on the same object.
135 // Cache locale data and specific facets used by iostreams.
136 _M_cache_locale(_M_ios_locale);
138 // NB: The 27.4.4.1 Postconditions Table specifies requirements
139 // after basic_ios::init() has been called. As part of this,
140 // fill() must return widen(' ') any time after init() has been
141 // called, which needs an imbued ctype facet of char_type to
142 // return without throwing an exception. Unfortunately,
143 // ctype<char_type> is not necessarily a required facet, so
144 // streams with char_type != [char, wchar_t] will not have it by
145 // default. Because of this, the correct value for _M_fill is
146 // constructed on the first call of fill(). That way,
147 // unformatted input and output with non-required basic_ios
148 // instantiations is possible even without imbuing the expected
149 // ctype<char_type> facet.
151 _M_fill_init = false;
154 _M_exception = goodbit;
156 _M_streambuf_state = __sb ? goodbit : badbit;
159 template<typename _CharT, typename _Traits>
161 basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc)
163 if (__builtin_expect(has_facet<__ctype_type>(__loc), true))
164 _M_ctype = &use_facet<__ctype_type>(__loc);
168 if (__builtin_expect(has_facet<__num_put_type>(__loc), true))
169 _M_num_put = &use_facet<__num_put_type>(__loc);
173 if (__builtin_expect(has_facet<__num_get_type>(__loc), true))
174 _M_num_get = &use_facet<__num_get_type>(__loc);
179 // Inhibit implicit instantiations for required instantiations,
180 // which are defined via explicit instantiations elsewhere.
181 // NB: This syntax is a GNU extension.
182 #if _GLIBCXX_EXTERN_TEMPLATE
183 extern template class basic_ios<char>;
185 #ifdef _GLIBCXX_USE_WCHAR_T
186 extern template class basic_ios<wchar_t>;
190 _GLIBCXX_END_NAMESPACE