Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / bits / basic_ios.tcc
blob399e93ae7371ae572a8e339798069f5966e9d5cf
1 // basic_ios member functions -*- C++ -*-
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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,
20 // USA.
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.
34  */
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>
44     void
45     basic_ios<_CharT, _Traits>::clear(iostate __state)
46     {
47       if (this->rdbuf())
48         _M_streambuf_state = __state;
49       else
50           _M_streambuf_state = __state | badbit;
51       if (this->exceptions() & this->rdstate())
52         __throw_ios_failure(__N("basic_ios::clear"));
53     }
55   template<typename _CharT, typename _Traits>
56     basic_streambuf<_CharT, _Traits>*
57     basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __sb)
58     {
59       basic_streambuf<_CharT, _Traits>* __old = _M_streambuf;
60       _M_streambuf = __sb;
61       this->clear();
62       return __old;
63     }
65   template<typename _CharT, typename _Traits>
66     basic_ios<_CharT, _Traits>&
67     basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
68     {
69       // _GLIBCXX_RESOLVE_LIB_DEFECTS
70       // 292. effects of a.copyfmt (a)
71       if (this != &__rhs)
72         {
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;
82           if (__cb)
83             __cb->_M_add_reference();
84           _M_call_callbacks(erase_event);
85           if (_M_word != _M_local_word)
86             {
87               delete [] _M_word;
88               _M_word = 0;
89             }
90           _M_dispose_callbacks();
92           // NB: Don't want any added during above.
93           _M_callbacks = __cb;
94           for (int __i = 0; __i < __rhs._M_word_size; ++__i)
95             __words[__i] = __rhs._M_word[__i];
96           _M_word = __words;
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());
111         }
112       return *this;
113     }
115   // Locales:
116   template<typename _CharT, typename _Traits>
117     locale
118     basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
119     {
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);
125       return __old;
126     }
128   template<typename _CharT, typename _Traits>
129     void
130     basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
131     {
132       // NB: This may be called more than once on the same object.
133       ios_base::_M_init();
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.
150       _M_fill = _CharT();
151       _M_fill_init = false;
153       _M_tie = 0;
154       _M_exception = goodbit;
155       _M_streambuf = __sb;
156       _M_streambuf_state = __sb ? goodbit : badbit;
157     }
159   template<typename _CharT, typename _Traits>
160     void
161     basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc)
162     {
163       if (__builtin_expect(has_facet<__ctype_type>(__loc), true))
164         _M_ctype = &use_facet<__ctype_type>(__loc);
165       else
166         _M_ctype = 0;
168       if (__builtin_expect(has_facet<__num_put_type>(__loc), true))
169         _M_num_put = &use_facet<__num_put_type>(__loc);
170       else
171         _M_num_put = 0;
173       if (__builtin_expect(has_facet<__num_get_type>(__loc), true))
174         _M_num_get = &use_facet<__num_get_type>(__loc);
175       else
176         _M_num_get = 0;
177     }
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>;
187 #endif
188 #endif
190 _GLIBCXX_END_NAMESPACE
192 #endif