1 // basic_ios locale and locale-related member functions -*- C++ -*-
3 // Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
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)
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.
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,
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.
30 #ifndef _CPP_BITS_BASICIOS_TCC
31 #define _CPP_BITS_BASICIOS_TCC 1
35 template<typename _CharT, typename _Traits>
36 basic_streambuf<_CharT, _Traits>*
37 basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb)
39 basic_streambuf<_CharT, _Traits>* __old = _M_streambuf;
45 template<typename _CharT, typename _Traits>
46 basic_ios<_CharT, _Traits>&
47 basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
49 // Per 27.1.1.1, do not call imbue, yet must trash all caches
50 // associated with imbue()
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];
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.
62 // Bump refs before doing callbacks, for safety.
63 _Callback_list* __cb = __rhs._M_callbacks;
65 __cb->_M_add_reference();
66 _M_call_callbacks(erase_event);
67 if (_M_words != _M_word_array)
69 _M_dispose_callbacks();
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)
77 _M_word_limit = __rhs._M_word_limit;
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());
87 _M_call_callbacks(copyfmt_event);
91 template<typename _CharT, typename _Traits>
93 basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
95 char __ret = __dfault;
96 if (_M_check_facet(_M_ios_fctype))
97 __ret = _M_ios_fctype->narrow(__c, __dfault);
101 template<typename _CharT, typename _Traits>
103 basic_ios<_CharT, _Traits>::widen(char __c) const
105 char_type __ret = char_type();
106 if (_M_check_facet(_M_ios_fctype))
107 __ret = _M_ios_fctype->widen(__c);
112 template<typename _CharT, typename _Traits>
114 basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
116 locale __old(this->getloc());
117 ios_base::imbue(__loc);
118 _M_cache_facets(__loc);
119 if (this->rdbuf() != 0)
120 this->rdbuf()->pubimbue(__loc);
124 template<typename _CharT, typename _Traits>
126 basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
128 // NB: This may be called more than once on the same object.
130 _M_cache_facets(_M_ios_locale);
133 // NB: The 27.4.4.1 Postconditions Table only specifies
134 // requirements after basic_ios::init() has been called. As part
135 // of this, fill() must return widen(' '), which needs an imbued
136 // ctype facet of char_type to return without throwing an
137 // exception. This is not a required facet, so streams with
138 // char_type != [char, wchar_t] will not have it by
139 // default. However, because fill()'s signature is const, this
140 // data member cannot be lazily initialized. Thus, thoughts of
141 // using a non-const helper function in ostream inserters is
142 // really besides the point.
143 _M_fill = this->widen(' ');
145 _M_exception = goodbit;
147 _M_streambuf_state = __sb ? goodbit : badbit;
150 template<typename _CharT, typename _Traits>
152 basic_ios<_CharT, _Traits>::_M_cache_facets(const locale& __loc)
154 if (has_facet<__ctype_type>(__loc))
155 _M_ios_fctype = &use_facet<__ctype_type>(__loc);
158 // Should be filled in by ostream and istream, respectively.
159 if (has_facet<__numput_type>(__loc))
160 _M_fnumput = &use_facet<__numput_type>(__loc);
163 if (has_facet<__numget_type>(__loc))
164 _M_fnumget = &use_facet<__numget_type>(__loc);