00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <ios>
00036 #include <limits>
00037 #include <bits/atomicity.h>
00038
00039 namespace std
00040 {
00041
00042
00043 const __ios_flags::__int_type __ios_flags::_S_boolalpha;
00044 const __ios_flags::__int_type __ios_flags::_S_dec;
00045 const __ios_flags::__int_type __ios_flags::_S_fixed;
00046 const __ios_flags::__int_type __ios_flags::_S_hex;
00047 const __ios_flags::__int_type __ios_flags::_S_internal;
00048 const __ios_flags::__int_type __ios_flags::_S_left;
00049 const __ios_flags::__int_type __ios_flags::_S_oct;
00050 const __ios_flags::__int_type __ios_flags::_S_right;
00051 const __ios_flags::__int_type __ios_flags::_S_scientific;
00052 const __ios_flags::__int_type __ios_flags::_S_showbase;
00053 const __ios_flags::__int_type __ios_flags::_S_showpoint;
00054 const __ios_flags::__int_type __ios_flags::_S_showpos;
00055 const __ios_flags::__int_type __ios_flags::_S_skipws;
00056 const __ios_flags::__int_type __ios_flags::_S_unitbuf;
00057 const __ios_flags::__int_type __ios_flags::_S_uppercase;
00058 const __ios_flags::__int_type __ios_flags::_S_adjustfield;
00059 const __ios_flags::__int_type __ios_flags::_S_basefield;
00060 const __ios_flags::__int_type __ios_flags::_S_floatfield;
00061
00062 const __ios_flags::__int_type __ios_flags::_S_badbit;
00063 const __ios_flags::__int_type __ios_flags::_S_eofbit;
00064 const __ios_flags::__int_type __ios_flags::_S_failbit;
00065
00066 const __ios_flags::__int_type __ios_flags::_S_app;
00067 const __ios_flags::__int_type __ios_flags::_S_ate;
00068 const __ios_flags::__int_type __ios_flags::_S_bin;
00069 const __ios_flags::__int_type __ios_flags::_S_in;
00070 const __ios_flags::__int_type __ios_flags::_S_out;
00071 const __ios_flags::__int_type __ios_flags::_S_trunc;
00072
00073
00074 const ios_base::fmtflags ios_base::boolalpha;
00075 const ios_base::fmtflags ios_base::dec;
00076 const ios_base::fmtflags ios_base::fixed;
00077 const ios_base::fmtflags ios_base::hex;
00078 const ios_base::fmtflags ios_base::internal;
00079 const ios_base::fmtflags ios_base::left;
00080 const ios_base::fmtflags ios_base::oct;
00081 const ios_base::fmtflags ios_base::right;
00082 const ios_base::fmtflags ios_base::scientific;
00083 const ios_base::fmtflags ios_base::showbase;
00084 const ios_base::fmtflags ios_base::showpoint;
00085 const ios_base::fmtflags ios_base::showpos;
00086 const ios_base::fmtflags ios_base::skipws;
00087 const ios_base::fmtflags ios_base::unitbuf;
00088 const ios_base::fmtflags ios_base::uppercase;
00089 const ios_base::fmtflags ios_base::adjustfield;
00090 const ios_base::fmtflags ios_base::basefield;
00091 const ios_base::fmtflags ios_base::floatfield;
00092
00093 const ios_base::iostate ios_base::badbit;
00094 const ios_base::iostate ios_base::eofbit;
00095 const ios_base::iostate ios_base::failbit;
00096 const ios_base::iostate ios_base::goodbit;
00097
00098 const ios_base::openmode ios_base::app;
00099 const ios_base::openmode ios_base::ate;
00100 const ios_base::openmode ios_base::binary;
00101 const ios_base::openmode ios_base::in;
00102 const ios_base::openmode ios_base::out;
00103 const ios_base::openmode ios_base::trunc;
00104
00105 const ios_base::seekdir ios_base::beg;
00106 const ios_base::seekdir ios_base::cur;
00107 const ios_base::seekdir ios_base::end;
00108
00109 const int ios_base::_S_local_word_size;
00110
00111 _Atomic_word ios_base::Init::_S_refcount;
00112
00113 bool ios_base::Init::_S_synced_with_stdio = true;
00114
00115 ios_base::ios_base()
00116 : _M_precision(), _M_width(), _M_flags(), _M_exception(),
00117 _M_streambuf_state(), _M_callbacks(0), _M_word_zero(),
00118 _M_word_size(_S_local_word_size), _M_word(_M_local_word), _M_ios_locale()
00119 {
00120
00121
00122
00123 }
00124
00125
00126 ios_base::~ios_base()
00127 {
00128 _M_call_callbacks(erase_event);
00129 _M_dispose_callbacks();
00130 if (_M_word != _M_local_word)
00131 {
00132 delete [] _M_word;
00133 _M_word = 0;
00134 }
00135 }
00136
00137
00138 int
00139 ios_base::xalloc() throw()
00140 {
00141
00142
00143 static _Atomic_word _S_top = 0;
00144 return __gnu_cxx::__exchange_and_add(&_S_top, 1) + 4;
00145 }
00146
00147 void
00148 ios_base::register_callback(event_callback __fn, int __index)
00149 { _M_callbacks = new _Callback_list(__fn, __index, _M_callbacks); }
00150
00151
00152 ios_base::_Words&
00153 ios_base::_M_grow_words(int ix, bool iword)
00154 {
00155
00156 int newsize = _S_local_word_size;
00157 _Words* words = _M_local_word;
00158 if (ix > _S_local_word_size - 1)
00159 {
00160 if (ix < numeric_limits<int>::max())
00161 {
00162 newsize = ix + 1;
00163 try
00164 { words = new _Words[newsize]; }
00165 catch (...)
00166 {
00167 _M_streambuf_state |= badbit;
00168 if (_M_streambuf_state & _M_exception)
00169 __throw_ios_failure(__N("ios_base::_M_grow_words "
00170 "allocation failed"));
00171 if (iword)
00172 _M_word_zero._M_iword = 0;
00173 else
00174 _M_word_zero._M_pword = 0;
00175 return _M_word_zero;
00176 }
00177 for (int i = 0; i < _M_word_size; i++)
00178 words[i] = _M_word[i];
00179 if (_M_word && _M_word != _M_local_word)
00180 {
00181 delete [] _M_word;
00182 _M_word = 0;
00183 }
00184 }
00185 else
00186 {
00187 _M_streambuf_state |= badbit;
00188 if (_M_streambuf_state & _M_exception)
00189 __throw_ios_failure(__N("ios_base::_M_grow_words is not valid"));
00190 if (iword)
00191 _M_word_zero._M_iword = 0;
00192 else
00193 _M_word_zero._M_pword = 0;
00194 return _M_word_zero;
00195 }
00196 }
00197 _M_word = words;
00198 _M_word_size = newsize;
00199 return _M_word[ix];
00200 }
00201
00202 void
00203 ios_base::_M_call_callbacks(event __e) throw()
00204 {
00205 _Callback_list* __p = _M_callbacks;
00206 while (__p)
00207 {
00208 try
00209 { (*__p->_M_fn) (__e, *this, __p->_M_index); }
00210 catch (...)
00211 { }
00212 __p = __p->_M_next;
00213 }
00214 }
00215
00216 void
00217 ios_base::_M_dispose_callbacks(void)
00218 {
00219 _Callback_list* __p = _M_callbacks;
00220 while (__p && __p->_M_remove_reference() == 0)
00221 {
00222 _Callback_list* __next = __p->_M_next;
00223 delete __p;
00224 __p = __next;
00225 }
00226 _M_callbacks = 0;
00227 }
00228 }