]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/ios.cc
c++config: Add in revised namespace associations.
[thirdparty/gcc.git] / libstdc++-v3 / src / ios.cc
CommitLineData
b2dad0e3
BK
1// Iostreams base classes -*- C++ -*-
2
3cbc7af0 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
17325050 4// Free Software Foundation, Inc.
b2dad0e3
BK
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.
11
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.
16
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
83f51799 19// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
b2dad0e3
BK
20// USA.
21
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.
30
31//
32// ISO C++ 14882: 27.4 Iostreams base classes
33//
34
54c1bf78 35#include <ios>
c755e77d 36#include <limits>
17325050 37#include <bits/atomicity.h>
a7817e1d 38
3cbc7af0
BK
39_GLIBCXX_BEGIN_NAMESPACE(std)
40
bd80bd9b
BK
41 // XXX GLIBCXX_ABI Deprecated
42 // Definitions for static const data members of __ios_flags.
0479a462
BK
43 const __ios_flags::__int_type __ios_flags::_S_boolalpha;
44 const __ios_flags::__int_type __ios_flags::_S_dec;
45 const __ios_flags::__int_type __ios_flags::_S_fixed;
46 const __ios_flags::__int_type __ios_flags::_S_hex;
47 const __ios_flags::__int_type __ios_flags::_S_internal;
48 const __ios_flags::__int_type __ios_flags::_S_left;
49 const __ios_flags::__int_type __ios_flags::_S_oct;
50 const __ios_flags::__int_type __ios_flags::_S_right;
51 const __ios_flags::__int_type __ios_flags::_S_scientific;
52 const __ios_flags::__int_type __ios_flags::_S_showbase;
53 const __ios_flags::__int_type __ios_flags::_S_showpoint;
54 const __ios_flags::__int_type __ios_flags::_S_showpos;
55 const __ios_flags::__int_type __ios_flags::_S_skipws;
56 const __ios_flags::__int_type __ios_flags::_S_unitbuf;
57 const __ios_flags::__int_type __ios_flags::_S_uppercase;
58 const __ios_flags::__int_type __ios_flags::_S_adjustfield;
59 const __ios_flags::__int_type __ios_flags::_S_basefield;
60 const __ios_flags::__int_type __ios_flags::_S_floatfield;
61
62 const __ios_flags::__int_type __ios_flags::_S_badbit;
63 const __ios_flags::__int_type __ios_flags::_S_eofbit;
64 const __ios_flags::__int_type __ios_flags::_S_failbit;
65
66 const __ios_flags::__int_type __ios_flags::_S_app;
67 const __ios_flags::__int_type __ios_flags::_S_ate;
68 const __ios_flags::__int_type __ios_flags::_S_bin;
69 const __ios_flags::__int_type __ios_flags::_S_in;
70 const __ios_flags::__int_type __ios_flags::_S_out;
71 const __ios_flags::__int_type __ios_flags::_S_trunc;
72
73 // Definitions for static const members of ios_base.
b2dad0e3
BK
74 const ios_base::fmtflags ios_base::boolalpha;
75 const ios_base::fmtflags ios_base::dec;
76 const ios_base::fmtflags ios_base::fixed;
77 const ios_base::fmtflags ios_base::hex;
78 const ios_base::fmtflags ios_base::internal;
79 const ios_base::fmtflags ios_base::left;
80 const ios_base::fmtflags ios_base::oct;
81 const ios_base::fmtflags ios_base::right;
82 const ios_base::fmtflags ios_base::scientific;
83 const ios_base::fmtflags ios_base::showbase;
84 const ios_base::fmtflags ios_base::showpoint;
85 const ios_base::fmtflags ios_base::showpos;
86 const ios_base::fmtflags ios_base::skipws;
87 const ios_base::fmtflags ios_base::unitbuf;
88 const ios_base::fmtflags ios_base::uppercase;
89 const ios_base::fmtflags ios_base::adjustfield;
90 const ios_base::fmtflags ios_base::basefield;
91 const ios_base::fmtflags ios_base::floatfield;
92
93 const ios_base::iostate ios_base::badbit;
94 const ios_base::iostate ios_base::eofbit;
95 const ios_base::iostate ios_base::failbit;
96 const ios_base::iostate ios_base::goodbit;
97
98 const ios_base::openmode ios_base::app;
99 const ios_base::openmode ios_base::ate;
100 const ios_base::openmode ios_base::binary;
101 const ios_base::openmode ios_base::in;
102 const ios_base::openmode ios_base::out;
103 const ios_base::openmode ios_base::trunc;
104
105 const ios_base::seekdir ios_base::beg;
106 const ios_base::seekdir ios_base::cur;
107 const ios_base::seekdir ios_base::end;
108
663653eb 109 const int ios_base::_S_local_word_size;
c755e77d 110
fa972243 111 _Atomic_word ios_base::Init::_S_refcount;
c755e77d 112
469550eb 113 bool ios_base::Init::_S_synced_with_stdio = true;
0479a462 114
c755e77d 115 ios_base::ios_base()
26c691a8
BK
116 : _M_precision(), _M_width(), _M_flags(), _M_exception(),
117 _M_streambuf_state(), _M_callbacks(0), _M_word_zero(),
118 _M_word_size(_S_local_word_size), _M_word(_M_local_word), _M_ios_locale()
5de197f2 119 {
c755e77d
BK
120 // Do nothing: basic_ios::init() does it.
121 // NB: _M_callbacks and _M_word must be zero for non-initialized
122 // ios_base to go through ~ios_base gracefully.
5de197f2 123 }
c755e77d
BK
124
125 // 27.4.2.7 ios_base constructors/destructors
126 ios_base::~ios_base()
b2dad0e3 127 {
c755e77d
BK
128 _M_call_callbacks(erase_event);
129 _M_dispose_callbacks();
130 if (_M_word != _M_local_word)
2aacd735 131 {
c755e77d
BK
132 delete [] _M_word;
133 _M_word = 0;
2aacd735 134 }
c755e77d 135 }
b2dad0e3
BK
136
137 // 27.4.2.5 ios_base storage functions
138 int
139 ios_base::xalloc() throw()
140 {
17325050
AP
141 // Implementation note: Initialize top to zero to ensure that
142 // initialization occurs before main() is started.
663653eb 143 static _Atomic_word _S_top = 0;
2c5d0ae8 144 return __gnu_cxx::__exchange_and_add(&_S_top, 1) + 4;
b2dad0e3
BK
145 }
146
c755e77d
BK
147 void
148 ios_base::register_callback(event_callback __fn, int __index)
149 { _M_callbacks = new _Callback_list(__fn, __index, _M_callbacks); }
150
b2dad0e3
BK
151 // 27.4.2.5 iword/pword storage
152 ios_base::_Words&
705debec 153 ios_base::_M_grow_words(int __ix, bool __iword)
b2dad0e3 154 {
705debec
PC
155 // Precondition: _M_word_size <= __ix
156 int __newsize = _S_local_word_size;
157 _Words* __words = _M_local_word;
158 if (__ix > _S_local_word_size - 1)
b2dad0e3 159 {
705debec 160 if (__ix < numeric_limits<int>::max())
d02475fd 161 {
705debec 162 __newsize = __ix + 1;
d02475fd 163 try
705debec 164 { __words = new _Words[__newsize]; }
d02475fd
BK
165 catch (...)
166 {
d02475fd
BK
167 _M_streambuf_state |= badbit;
168 if (_M_streambuf_state & _M_exception)
ba9119ec
PC
169 __throw_ios_failure(__N("ios_base::_M_grow_words "
170 "allocation failed"));
705debec 171 if (__iword)
2a837cf8
JQ
172 _M_word_zero._M_iword = 0;
173 else
174 _M_word_zero._M_pword = 0;
d02475fd
BK
175 return _M_word_zero;
176 }
705debec
PC
177 for (int __i = 0; __i < _M_word_size; __i++)
178 __words[__i] = _M_word[__i];
d02475fd
BK
179 if (_M_word && _M_word != _M_local_word)
180 {
181 delete [] _M_word;
182 _M_word = 0;
183 }
184 }
663653eb 185 else
b2dad0e3 186 {
663653eb 187 _M_streambuf_state |= badbit;
c524ed5d 188 if (_M_streambuf_state & _M_exception)
ba9119ec 189 __throw_ios_failure(__N("ios_base::_M_grow_words is not valid"));
705debec 190 if (__iword)
2a837cf8
JQ
191 _M_word_zero._M_iword = 0;
192 else
193 _M_word_zero._M_pword = 0;
663653eb
BK
194 return _M_word_zero;
195 }
b2dad0e3 196 }
705debec
PC
197 _M_word = __words;
198 _M_word_size = __newsize;
199 return _M_word[__ix];
b2dad0e3 200 }
b2dad0e3
BK
201
202 void
203 ios_base::_M_call_callbacks(event __e) throw()
204 {
1bc59af5
BK
205 _Callback_list* __p = _M_callbacks;
206 while (__p)
b2dad0e3 207 {
1bc59af5
BK
208 try
209 { (*__p->_M_fn) (__e, *this, __p->_M_index); }
210 catch (...)
211 { }
212 __p = __p->_M_next;
b2dad0e3
BK
213 }
214 }
215
216 void
217 ios_base::_M_dispose_callbacks(void)
218 {
219 _Callback_list* __p = _M_callbacks;
220 while (__p && __p->_M_remove_reference() == 0)
221 {
222 _Callback_list* __next = __p->_M_next;
223 delete __p;
224 __p = __next;
225 }
226 _M_callbacks = 0;
227 }
3cbc7af0
BK
228
229_GLIBCXX_END_NAMESPACE