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