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 #include <bits/std_ios.h>
00035 #include <bits/std_ostream.h>
00036 #include <bits/std_istream.h>
00037 #include <bits/std_fstream.h>
00038
00039 namespace std
00040 {
00041
00042 const __ios_flags::__int_type __ios_flags::_S_boolalpha;
00043 const __ios_flags::__int_type __ios_flags::_S_dec;
00044 const __ios_flags::__int_type __ios_flags::_S_fixed;
00045 const __ios_flags::__int_type __ios_flags::_S_hex;
00046 const __ios_flags::__int_type __ios_flags::_S_internal;
00047 const __ios_flags::__int_type __ios_flags::_S_left;
00048 const __ios_flags::__int_type __ios_flags::_S_oct;
00049 const __ios_flags::__int_type __ios_flags::_S_right;
00050 const __ios_flags::__int_type __ios_flags::_S_scientific;
00051 const __ios_flags::__int_type __ios_flags::_S_showbase;
00052 const __ios_flags::__int_type __ios_flags::_S_showpoint;
00053 const __ios_flags::__int_type __ios_flags::_S_showpos;
00054 const __ios_flags::__int_type __ios_flags::_S_skipws;
00055 const __ios_flags::__int_type __ios_flags::_S_unitbuf;
00056 const __ios_flags::__int_type __ios_flags::_S_uppercase;
00057 const __ios_flags::__int_type __ios_flags::_S_adjustfield;
00058 const __ios_flags::__int_type __ios_flags::_S_basefield;
00059 const __ios_flags::__int_type __ios_flags::_S_floatfield;
00060
00061 const __ios_flags::__int_type __ios_flags::_S_badbit;
00062 const __ios_flags::__int_type __ios_flags::_S_eofbit;
00063 const __ios_flags::__int_type __ios_flags::_S_failbit;
00064
00065 const __ios_flags::__int_type __ios_flags::_S_app;
00066 const __ios_flags::__int_type __ios_flags::_S_ate;
00067 const __ios_flags::__int_type __ios_flags::_S_bin;
00068 const __ios_flags::__int_type __ios_flags::_S_in;
00069 const __ios_flags::__int_type __ios_flags::_S_out;
00070 const __ios_flags::__int_type __ios_flags::_S_trunc;
00071
00072
00073 const ios_base::fmtflags ios_base::boolalpha;
00074 const ios_base::fmtflags ios_base::dec;
00075 const ios_base::fmtflags ios_base::fixed;
00076 const ios_base::fmtflags ios_base::hex;
00077 const ios_base::fmtflags ios_base::internal;
00078 const ios_base::fmtflags ios_base::left;
00079 const ios_base::fmtflags ios_base::oct;
00080 const ios_base::fmtflags ios_base::right;
00081 const ios_base::fmtflags ios_base::scientific;
00082 const ios_base::fmtflags ios_base::showbase;
00083 const ios_base::fmtflags ios_base::showpoint;
00084 const ios_base::fmtflags ios_base::showpos;
00085 const ios_base::fmtflags ios_base::skipws;
00086 const ios_base::fmtflags ios_base::unitbuf;
00087 const ios_base::fmtflags ios_base::uppercase;
00088 const ios_base::fmtflags ios_base::adjustfield;
00089 const ios_base::fmtflags ios_base::basefield;
00090 const ios_base::fmtflags ios_base::floatfield;
00091
00092 const ios_base::iostate ios_base::badbit;
00093 const ios_base::iostate ios_base::eofbit;
00094 const ios_base::iostate ios_base::failbit;
00095 const ios_base::iostate ios_base::goodbit;
00096
00097 const ios_base::openmode ios_base::app;
00098 const ios_base::openmode ios_base::ate;
00099 const ios_base::openmode ios_base::binary;
00100 const ios_base::openmode ios_base::in;
00101 const ios_base::openmode ios_base::out;
00102 const ios_base::openmode ios_base::trunc;
00103
00104 const ios_base::seekdir ios_base::beg;
00105 const ios_base::seekdir ios_base::cur;
00106 const ios_base::seekdir ios_base::end;
00107
00108 const int ios_base::_S_local_words;
00109 int ios_base::Init::_S_ios_base_init = 0;
00110 bool ios_base::Init::_S_synced_with_stdio = true;
00111
00112 extern istream cin;
00113 extern ostream cout;
00114 extern ostream cerr;
00115 extern ostream clog;
00116 #ifdef _GLIBCPP_USE_WCHAR_T
00117 extern wistream wcin;
00118 extern wostream wcout;
00119 extern wostream wcerr;
00120 extern wostream wclog;
00121 #endif
00122
00123 ios_base::failure::failure(const string& __str) throw()
00124 {
00125 strncpy(_M_name, __str.c_str(), _M_bufsize);
00126 _M_name[_M_bufsize - 1] = '\0';
00127 }
00128
00129 ios_base::failure::~failure() throw()
00130 { }
00131
00132 const char*
00133 ios_base::failure::what() const throw()
00134 { return _M_name; }
00135
00136 void
00137 ios_base::Init::_S_ios_create(bool __sync)
00138 {
00139
00140
00141 new (&cout) ostream(new filebuf(stdout, __sync, ios_base::out));
00142 new (&cin) istream(new filebuf(stdin, __sync, ios_base::in));
00143 new (&cerr) ostream(new filebuf(stderr, __sync, ios_base::out));
00144 new (&clog) ostream(cerr.rdbuf());
00145 cin.tie(&cout);
00146 cerr.flags(ios_base::unitbuf);
00147
00148 #ifdef _GLIBCPP_USE_WCHAR_T
00149 new (&wcout) wostream( new wfilebuf(stdout, __sync, ios_base::out));
00150 new (&wcin) wistream(new wfilebuf(stdin, __sync, ios_base::in));
00151 new (&wcerr) wostream(new wfilebuf(stderr, __sync, ios_base::out));
00152 new (&wclog) wostream(wcerr.rdbuf());
00153 wcin.tie(&wcout);
00154 wcerr.flags(ios_base::unitbuf);
00155 #endif
00156 }
00157
00158 ios_base::Init::Init()
00159 {
00160 if (++_S_ios_base_init == 1)
00161 {
00162
00163 ios_base::Init::_S_synced_with_stdio = true;
00164 _S_ios_create(ios_base::Init::_S_synced_with_stdio);
00165 }
00166 }
00167
00168 void
00169 ios_base::Init::_S_ios_destroy()
00170 {
00171 cout.flush();
00172 cerr.flush();
00173 clog.flush();
00174 delete cout.rdbuf();
00175 delete cin.rdbuf();
00176 delete cerr.rdbuf();
00177 #ifdef _GLIBCPP_USE_WCHAR_T
00178 wcout.flush();
00179 wcerr.flush();
00180 wclog.flush();
00181 delete wcout.rdbuf();
00182 delete wcin.rdbuf();
00183 delete wcerr.rdbuf();
00184 #endif
00185 }
00186
00187 ios_base::Init::~Init()
00188 {
00189 if (--_S_ios_base_init == 0)
00190 _S_ios_destroy();
00191 }
00192
00193
00194 int
00195 ios_base::xalloc() throw()
00196 {
00197
00198
00199 static int top = 4;
00200 return top++;
00201 }
00202
00203
00204 ios_base::_Words&
00205 ios_base::_M_grow_words(int ix)
00206 {
00207
00208 _Words zero = { 0, 0 };
00209 int newlimit = _S_local_words;
00210 _Words* words = _M_word_array;
00211 int i = 0;
00212 if (_S_local_words <= ix)
00213 {
00214 newlimit = ix+1;
00215 try
00216 { words = new _Words[ix+1]; }
00217 catch (...)
00218 {
00219 _M_dummy = zero;
00220
00221
00222 return _M_dummy;
00223 }
00224 for (; i < _M_word_limit; i++)
00225 words[i] = _M_words[i];
00226 if (_M_words != _M_word_array)
00227 delete [] _M_words;
00228 }
00229
00230 do { words[i] = zero; } while (++i < newlimit);
00231 _M_words = words;
00232 _M_word_limit = newlimit;
00233 return words[ix];
00234 }
00235
00236
00237 void
00238 ios_base::_M_init()
00239 {
00240
00241 _M_precision = 6;
00242 _M_width = 0;
00243 _M_flags = skipws | dec;
00244 _M_callbacks = 0;
00245 _M_words = 0;
00246 _M_word_limit = 0;
00247 _M_ios_locale = locale();
00248
00249 }
00250
00251
00252 locale
00253 ios_base::imbue(const locale& __loc)
00254 {
00255 locale __old = _M_ios_locale;
00256 _M_ios_locale = __loc;
00257
00258
00259 _Format_cache<char>::_S_get(*this);
00260 #ifdef _GLIBCPP_USE_WCHAR_T
00261 _Format_cache<wchar_t>::_S_get(*this);
00262 #endif
00263 _M_call_callbacks(imbue_event);
00264 return __old;
00265 }
00266
00267 ios_base::ios_base()
00268 {
00269
00270 }
00271
00272
00273 ios_base::~ios_base()
00274 {
00275 _M_call_callbacks(erase_event);
00276 _M_dispose_callbacks();
00277 if (_M_words != _M_word_array)
00278 delete [] _M_words;
00279
00280 }
00281
00282 void
00283 ios_base::register_callback(event_callback __fn, int __index)
00284 { _M_callbacks = new _Callback_list(__fn, __index, _M_callbacks); }
00285
00286 void
00287 ios_base::_M_call_callbacks(event __e) throw()
00288 {
00289 for (_Callback_list* __p = _M_callbacks; __p; __p = __p->_M_next)
00290 {
00291 try {
00292 (*__p->_M_fn) (__e, *this, __p->_M_index);
00293 }
00294 catch (...) {
00295 }
00296 }
00297 }
00298
00299 void
00300 ios_base::_M_dispose_callbacks(void)
00301 {
00302 _Callback_list* __p = _M_callbacks;
00303 while (__p && __p->_M_remove_reference() == 0)
00304 {
00305 _Callback_list* __next = __p->_M_next;
00306 delete __p;
00307 __p = __next;
00308 }
00309 _M_callbacks = 0;
00310 }
00311
00312 bool
00313 ios_base::sync_with_stdio(bool __sync)
00314 {
00315 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00316
00317 bool __ret = ios_base::Init::_S_synced_with_stdio;
00318 #endif
00319
00320
00321
00322 if (!__sync && __ret)
00323 {
00324 ios_base::Init::_S_synced_with_stdio = false;
00325 ios_base::Init::_S_ios_destroy();
00326 ios_base::Init::_S_ios_create(ios_base::Init::_S_synced_with_stdio);
00327 }
00328 return __ret;
00329 }
00330 }
00331