]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/basic_ios.tcc
std_ostream.h: Replaced usage of _Traits::_S_eos() with _CharT() as per section 17...
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / basic_ios.tcc
1 // basic_ios locale and locale-related member functions -*- C++ -*-
2
3 // Copyright (C) 1999, 2001 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 2, or (at your option)
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
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 #ifndef _CPP_BITS_BASICIOS_TCC
31 #define _CPP_BITS_BASICIOS_TCC 1
32
33 namespace std {
34
35 template<typename _CharT, typename _Traits>
36 basic_streambuf<_CharT, _Traits>*
37 basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb)
38 {
39 basic_streambuf<_CharT, _Traits>* __old = _M_streambuf;
40 _M_streambuf = __sb;
41 this->clear();
42 return __old;
43 }
44
45 template<typename _CharT, typename _Traits>
46 basic_ios<_CharT, _Traits>&
47 basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
48 {
49 // Per 27.1.1.1, do not call imbue, yet must trash all caches
50 // associated with imbue()
51
52 // Alloc any new word array first, so if it fails we have "rollback".
53 _Words* __words = (__rhs._M_word_limit <= _S_local_words) ?
54 _M_word_array : new _Words[__rhs._M_word_limit];
55
56 // XXX This is the only reason _Callback_list was defined
57 // inline. The suspicion is that this increased compilation
58 // times dramatically for functions that use this member
59 // function (inserters_extractors, ios_manip_fmtflags). FIX ME,
60 // clean this stuff up. Callbacks are broken right now, anyway.
61
62 // Bump refs before doing callbacks, for safety.
63 _Callback_list* __cb = __rhs._M_callbacks;
64 if (__cb)
65 __cb->_M_add_reference();
66 _M_call_callbacks(erase_event);
67 if (_M_words != _M_word_array)
68 delete [] _M_words;
69 _M_dispose_callbacks();
70
71 _M_callbacks = __cb; // NB: Don't want any added during above.
72 for (int __i = 0; __i < __rhs._M_word_limit; ++__i)
73 __words[__i] = __rhs._M_words[__i];
74 if (_M_words != _M_word_array)
75 delete [] _M_words;
76 _M_words = __words;
77 _M_word_limit = __rhs._M_word_limit;
78
79 this->flags(__rhs.flags());
80 this->width(__rhs.width());
81 this->precision(__rhs.precision());
82 this->tie(__rhs.tie());
83 this->fill(__rhs.fill());
84 // The next is required to be the last assignment.
85 this->exceptions(__rhs.exceptions());
86
87 _M_call_callbacks(copyfmt_event);
88 return *this;
89 }
90
91 template<typename _CharT, typename _Traits>
92 char
93 basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
94 { return _M_ios_fctype->narrow(__c, __dfault); }
95
96 template<typename _CharT, typename _Traits>
97 _CharT
98 basic_ios<_CharT, _Traits>::widen(char __c) const
99 { return _M_ios_fctype->widen(__c); }
100
101 // Locales:
102 template<typename _CharT, typename _Traits>
103 locale
104 basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
105 {
106 locale __old(this->getloc());
107 ios_base::imbue(__loc);
108 _M_ios_fctype = &use_facet<__ctype_type>(__loc);
109 _M_fnumput = &use_facet<__numput_type>(__loc);
110 _M_fnumget = &use_facet<__numget_type>(__loc);
111 if (this->rdbuf() != 0)
112 this->rdbuf()->pubimbue(__loc);
113 return __old;
114 }
115
116 template<typename _CharT, typename _Traits>
117 void
118 basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
119 {
120 // NB: This may be called more than once on the same object.
121 ios_base::_M_init();
122 _M_ios_fctype = &use_facet<__ctype_type>(_M_ios_locale);
123 // Should be filled in by ostream and istream, respectively.
124 _M_fnumput = &use_facet<__numput_type>(_M_ios_locale);
125 _M_fnumget = &use_facet<__numget_type>(_M_ios_locale);
126 _M_tie = 0;
127 _M_fill = this->widen(' ');
128 _M_exception = goodbit;
129 _M_streambuf = __sb;
130 _M_streambuf_state = __sb ? goodbit : badbit;
131 }
132
133 } // namespace std
134
135 #endif /* _CPP_BITS_BASICIOS_TCC */
136
137
138
139
140