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