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 #include <bits/std_locale.h>
00033
00034 namespace std {
00035
00036 template<typename _CharT, typename _Traits>
00037 basic_ostream<_CharT, _Traits>::sentry::
00038 sentry(basic_ostream<_CharT,_Traits>& __os)
00039 : _M_ok(__os.good()), _M_os(__os)
00040 {
00041
00042 if (_M_ok && __os.tie())
00043 __os.tie()->flush();
00044 }
00045
00046 template<typename _CharT, typename _Traits>
00047 basic_ostream<_CharT, _Traits>&
00048 basic_ostream<_CharT, _Traits>::
00049 operator<<(__ostream_type& (*__pf)(__ostream_type&))
00050 {
00051 sentry __cerb(*this);
00052 if (__cerb)
00053 {
00054 try {
00055 __pf(*this);
00056 }
00057 catch(exception& __fail){
00058
00059
00060 this->setstate(ios_base::badbit);
00061 if ((this->exceptions() & ios_base::badbit) != 0)
00062 __throw_exception_again;
00063 }
00064 }
00065 return *this;
00066 }
00067
00068 template<typename _CharT, typename _Traits>
00069 basic_ostream<_CharT, _Traits>&
00070 basic_ostream<_CharT, _Traits>::
00071 operator<<(__ios_type& (*__pf)(__ios_type&))
00072 {
00073 sentry __cerb(*this);
00074 if (__cerb)
00075 {
00076 try {
00077 __pf(*this);
00078 }
00079 catch(exception& __fail){
00080
00081
00082 this->setstate(ios_base::badbit);
00083 if ((this->exceptions() & ios_base::badbit) != 0)
00084 __throw_exception_again;
00085 }
00086 }
00087 return *this;
00088 }
00089
00090 template<typename _CharT, typename _Traits>
00091 basic_ostream<_CharT, _Traits>&
00092 basic_ostream<_CharT, _Traits>::
00093 operator<<(ios_base& (*__pf)(ios_base&))
00094 {
00095 sentry __cerb(*this);
00096 if (__cerb)
00097 {
00098 try {
00099 __pf(*this);
00100 }
00101 catch(exception& __fail){
00102
00103
00104 this->setstate(ios_base::badbit);
00105 if ((this->exceptions() & ios_base::badbit) != 0)
00106 __throw_exception_again;
00107 }
00108 }
00109 return *this;
00110 }
00111
00112 template<typename _CharT, typename _Traits>
00113 basic_ostream<_CharT, _Traits>&
00114 basic_ostream<_CharT, _Traits>::operator<<(bool __n)
00115 {
00116 sentry __cerb(*this);
00117 if (__cerb)
00118 {
00119 try {
00120 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
00121 this->setstate(ios_base::badbit);
00122 }
00123 catch(exception& __fail){
00124
00125
00126 this->setstate(ios_base::badbit);
00127 if ((this->exceptions() & ios_base::badbit) != 0)
00128 __throw_exception_again;
00129 }
00130 }
00131 return *this;
00132 }
00133
00134 template<typename _CharT, typename _Traits>
00135 basic_ostream<_CharT, _Traits>&
00136 basic_ostream<_CharT, _Traits>::operator<<(long __n)
00137 {
00138 sentry __cerb(*this);
00139 if (__cerb)
00140 {
00141 try {
00142 bool __f;
00143 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00144 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00145 __f = _M_fnumput->put(*this, *this, this->fill(),
00146 static_cast<unsigned long>(__n)).failed();
00147 else
00148 __f = _M_fnumput->put(*this, *this, this->fill(), __n).failed();
00149
00150 if (__f)
00151 this->setstate(ios_base::badbit);
00152 }
00153 catch(exception& __fail){
00154
00155
00156 this->setstate(ios_base::badbit);
00157 if ((this->exceptions() & ios_base::badbit) != 0)
00158 __throw_exception_again;
00159 }
00160 }
00161 return *this;
00162 }
00163
00164 template<typename _CharT, typename _Traits>
00165 basic_ostream<_CharT, _Traits>&
00166 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
00167 {
00168 sentry __cerb(*this);
00169 if (__cerb)
00170 {
00171 try {
00172 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
00173 this->setstate(ios_base::badbit);
00174 }
00175 catch(exception& __fail){
00176
00177
00178 this->setstate(ios_base::badbit);
00179 if ((this->exceptions() & ios_base::badbit) != 0)
00180 __throw_exception_again;
00181 }
00182 }
00183 return *this;
00184 }
00185
00186 #ifdef _GLIBCPP_USE_LONG_LONG
00187 template<typename _CharT, typename _Traits>
00188 basic_ostream<_CharT, _Traits>&
00189 basic_ostream<_CharT, _Traits>::operator<<(long long __n)
00190 {
00191 sentry __cerb(*this);
00192 if (__cerb)
00193 {
00194 try {
00195 bool __f;
00196 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00197 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00198 __f = _M_fnumput->put(*this, *this, this->fill(),
00199 static_cast<unsigned long long>(__n)).failed();
00200 else
00201 __f = _M_fnumput->put(*this, *this, this->fill(), __n).failed();
00202
00203 }
00204 catch(exception& __fail){
00205
00206
00207 this->setstate(ios_base::badbit);
00208 if ((this->exceptions() & ios_base::badbit) != 0)
00209 __throw_exception_again;
00210 }
00211 }
00212 return *this;
00213 }
00214
00215 template<typename _CharT, typename _Traits>
00216 basic_ostream<_CharT, _Traits>&
00217 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
00218 {
00219 sentry __cerb(*this);
00220 if (__cerb)
00221 {
00222 try {
00223 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
00224 this->setstate(ios_base::badbit);
00225 }
00226 catch(exception& __fail){
00227
00228
00229 this->setstate(ios_base::badbit);
00230 if ((this->exceptions() & ios_base::badbit) != 0)
00231 __throw_exception_again;
00232 }
00233 }
00234 return *this;
00235 }
00236 #endif
00237
00238 template<typename _CharT, typename _Traits>
00239 basic_ostream<_CharT, _Traits>&
00240 basic_ostream<_CharT, _Traits>::operator<<(double __n)
00241 {
00242 sentry __cerb(*this);
00243 if (__cerb)
00244 {
00245 try {
00246 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
00247 this->setstate(ios_base::badbit);
00248 }
00249 catch(exception& __fail){
00250
00251
00252 this->setstate(ios_base::badbit);
00253 if ((this->exceptions() & ios_base::badbit) != 0)
00254 __throw_exception_again;
00255 }
00256 }
00257 return *this;
00258 }
00259
00260 template<typename _CharT, typename _Traits>
00261 basic_ostream<_CharT, _Traits>&
00262 basic_ostream<_CharT, _Traits>::operator<<(long double __n)
00263 {
00264 sentry __cerb(*this);
00265 if (__cerb)
00266 {
00267 try {
00268 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
00269 this->setstate(ios_base::badbit);
00270 }
00271 catch(exception& __fail){
00272
00273
00274 this->setstate(ios_base::badbit);
00275 if ((this->exceptions() & ios_base::badbit) != 0)
00276 __throw_exception_again;
00277 }
00278 }
00279 return *this;
00280 }
00281
00282 template<typename _CharT, typename _Traits>
00283 basic_ostream<_CharT, _Traits>&
00284 basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
00285 {
00286 sentry __cerb(*this);
00287 if (__cerb)
00288 {
00289 try {
00290 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed())
00291 this->setstate(ios_base::badbit);
00292 }
00293 catch(exception& __fail){
00294
00295
00296 this->setstate(ios_base::badbit);
00297 if ((this->exceptions() & ios_base::badbit) != 0)
00298 __throw_exception_again;
00299 }
00300 }
00301 return *this;
00302 }
00303
00304 template<typename _CharT, typename _Traits>
00305 basic_ostream<_CharT, _Traits>&
00306 basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin)
00307 {
00308 streamsize __xtrct = 0;
00309 __streambuf_type* __sbout = this->rdbuf();
00310 sentry __cerb(*this);
00311 if (__sbin && __cerb)
00312 __xtrct = __copy_streambufs(*this, __sbin, __sbout);
00313 if (!__sbin || !__xtrct)
00314 this->setstate(ios_base::failbit);
00315 return *this;
00316 }
00317
00318 template<typename _CharT, typename _Traits>
00319 basic_ostream<_CharT, _Traits>&
00320 basic_ostream<_CharT, _Traits>::put(char_type __c)
00321 {
00322 sentry __cerb(*this);
00323 if (__cerb)
00324 {
00325 int_type __put = rdbuf()->sputc(__c);
00326 if (__put != traits_type::to_int_type(__c))
00327 this->setstate(ios_base::badbit);
00328 }
00329 return *this;
00330 }
00331
00332 template<typename _CharT, typename _Traits>
00333 basic_ostream<_CharT, _Traits>&
00334 basic_ostream<_CharT, _Traits>::write(const _CharT* __s, streamsize __n)
00335 {
00336 sentry __cerb(*this);
00337 if (__cerb)
00338 {
00339 streamsize __put = this->rdbuf()->sputn(__s, __n);
00340 if ( __put != __n)
00341 this->setstate(ios_base::badbit);
00342 }
00343 return *this;
00344 }
00345
00346 template<typename _CharT, typename _Traits>
00347 basic_ostream<_CharT, _Traits>&
00348 basic_ostream<_CharT, _Traits>::flush()
00349 {
00350 sentry __cerb(*this);
00351 if (__cerb)
00352 {
00353 if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
00354 this->setstate(ios_base::badbit);
00355 }
00356 return *this;
00357 }
00358
00359 template<typename _CharT, typename _Traits>
00360 typename basic_ostream<_CharT, _Traits>::pos_type
00361 basic_ostream<_CharT, _Traits>::tellp()
00362 {
00363 pos_type __ret = pos_type(-1);
00364 bool __testok = this->fail() != true;
00365
00366 if (__testok)
00367 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
00368 return __ret;
00369 }
00370
00371
00372 template<typename _CharT, typename _Traits>
00373 basic_ostream<_CharT, _Traits>&
00374 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
00375 {
00376 bool __testok = this->fail() != true;
00377
00378 if (__testok)
00379 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00380
00381 this->rdbuf()->pubseekpos(__pos, ios_base::out);
00382 #endif
00383 return *this;
00384 }
00385
00386 template<typename _CharT, typename _Traits>
00387 basic_ostream<_CharT, _Traits>&
00388 basic_ostream<_CharT, _Traits>::
00389 seekp(off_type __off, ios_base::seekdir __d)
00390 {
00391 bool __testok = this->fail() != true;
00392
00393 if (__testok)
00394 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00395
00396 rdbuf()->pubseekoff(__off, __d, ios_base::out);
00397 #endif
00398 return *this;
00399 }
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 template<typename _CharT, typename _Traits>
00410 void
00411 __pad_char(basic_ios<_CharT, _Traits>& __ios,
00412 _CharT* __news, const _CharT* __olds,
00413 const streamsize __newlen, const streamsize __oldlen)
00414 {
00415 typedef _CharT char_type;
00416 typedef _Traits traits_type;
00417 typedef typename traits_type::int_type int_type;
00418
00419 int_type __plen = static_cast<size_t>(__newlen - __oldlen);
00420 char_type* __pads = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __plen));
00421 traits_type::assign(__pads, __plen, __ios.fill());
00422
00423 char_type* __beg;
00424 char_type* __end;
00425 size_t __mod = 0;
00426 size_t __beglen;
00427 ios_base::fmtflags __fmt = __ios.flags() & ios_base::adjustfield;
00428
00429 if (__fmt == ios_base::left)
00430 {
00431
00432 __beg = const_cast<char_type*>(__olds);
00433 __beglen = __oldlen;
00434 __end = __pads;
00435 }
00436 else if (__fmt == ios_base::internal)
00437 {
00438
00439
00440
00441 typedef _Format_cache<_CharT> __cache_type;
00442 __cache_type const* __fmt = __cache_type::_S_get(__ios);
00443 const char_type* __minus = traits_type::find(__olds, __oldlen,
00444 __fmt->_S_minus);
00445 const char_type* __plus = traits_type::find(__olds, __oldlen,
00446 __fmt->_S_plus);
00447 bool __testsign = __minus || __plus;
00448 bool __testhex = __olds[0] == '0'
00449 && (__olds[1] == 'x' || __olds[1] == 'X');
00450
00451 if (__testhex)
00452 {
00453 __news[0] = __olds[0];
00454 __news[1] = __olds[1];
00455 __mod += 2;
00456 __beg = const_cast<char_type*>(__olds + __mod);
00457 __beglen = __oldlen - __mod;
00458 __end = __pads;
00459 }
00460 else if (__testsign)
00461 {
00462 __mod += __plen;
00463 const char_type* __sign = __minus ? __minus + 1: __plus + 1;
00464 __beg = const_cast<char_type*>(__olds);
00465 __beglen = __sign - __olds;
00466 __end = const_cast<char_type*>(__sign + __plen);
00467 traits_type::copy(__news + __beglen, __pads, __plen);
00468 }
00469 else
00470 {
00471
00472 __beg = __pads;
00473 __beglen = __plen;
00474 __end = const_cast<char_type*>(__olds);
00475 }
00476 }
00477 else
00478 {
00479
00480 __beg = __pads;
00481 __beglen = __plen;
00482 __end = const_cast<char_type*>(__olds);
00483 }
00484
00485 traits_type::copy(__news, __beg, __beglen);
00486 traits_type::copy(__news + __beglen, __end, __newlen - __beglen - __mod);
00487 }
00488
00489 template<typename _CharT, typename _Traits>
00490 basic_ostream<_CharT, _Traits>&
00491 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
00492 {
00493 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00494 typename __ostream_type::sentry __cerb(__out);
00495 if (__cerb)
00496 {
00497 try {
00498 streamsize __w = __out.width();
00499 _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
00500 __pads[0] = __c;
00501 streamsize __len = 1;
00502 if (__w > __len)
00503 {
00504 __pad_char(__out, __pads, &__c, __w, __len);
00505 __len = __w;
00506 }
00507 __out.write(__pads, __len);
00508 __out.width(0);
00509 }
00510 catch(exception& __fail){
00511
00512
00513 __out.setstate(ios_base::badbit);
00514 if ((__out.exceptions() & ios_base::badbit) != 0)
00515 __throw_exception_again;
00516 }
00517 }
00518 return __out;
00519 }
00520
00521
00522 template <class _Traits>
00523 basic_ostream<char, _Traits>&
00524 operator<<(basic_ostream<char, _Traits>& __out, char __c)
00525 {
00526 typedef basic_ostream<char, _Traits> __ostream_type;
00527 typename __ostream_type::sentry __cerb(__out);
00528 if (__cerb)
00529 {
00530 try {
00531 streamsize __w = __out.width();
00532 char* __pads = static_cast<char*>(__builtin_alloca(__w + 1));
00533 __pads[0] = __c;
00534 streamsize __len = 1;
00535 if (__w > __len)
00536 {
00537 __pad_char(__out, __pads, &__c, __w, __len);
00538 __len = __w;
00539 }
00540 __out.write(__pads, __len);
00541 __out.width(0);
00542 }
00543 catch(exception& __fail){
00544
00545
00546 __out.setstate(ios_base::badbit);
00547 if ((__out.exceptions() & ios_base::badbit) != 0)
00548 __throw_exception_again;
00549 }
00550 }
00551 return __out;
00552 }
00553
00554 template<typename _CharT, typename _Traits>
00555 basic_ostream<_CharT, _Traits>&
00556 operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
00557 {
00558 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00559 typename __ostream_type::sentry __cerb(__out);
00560 if (__cerb)
00561 {
00562 try {
00563 streamsize __w = __out.width();
00564 _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
00565 streamsize __len = static_cast<streamsize>(_Traits::length(__s));
00566 if (__w > __len)
00567 {
00568 __pad_char(__out, __pads, __s, __w, __len);
00569 __s = __pads;
00570 __len = __w;
00571 }
00572 __out.write(__s, __len);
00573 __out.width(0);
00574 }
00575 catch(exception& __fail){
00576
00577
00578 __out.setstate(ios_base::badbit);
00579 if ((__out.exceptions() & ios_base::badbit) != 0)
00580 __throw_exception_again;
00581 }
00582 }
00583 return __out;
00584 }
00585
00586 template<typename _CharT, typename _Traits>
00587 basic_ostream<_CharT, _Traits>&
00588 operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
00589 {
00590 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00591 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00592
00593 typedef char_traits<char> __ctraits_type;
00594 #endif
00595 typename __ostream_type::sentry __cerb(__out);
00596 if (__cerb)
00597 {
00598 size_t __clen = __ctraits_type::length(__s);
00599 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1)));
00600 for (size_t __i = 0; __i <= __clen; ++__i)
00601 __ws[__i] = __out.widen(__s[__i]);
00602 _CharT* __str = __ws;
00603
00604 try {
00605 streamsize __len = static_cast<streamsize>(__clen);
00606 streamsize __w = __out.width();
00607 _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
00608
00609 if (__w > __len)
00610 {
00611 __pad_char(__out, __pads, __ws, __w, __len);
00612 __str = __pads;
00613 __len = __w;
00614 }
00615 __out.write(__str, __len);
00616 __out.width(0);
00617 }
00618 catch(exception& __fail){
00619
00620
00621 __out.setstate(ios_base::badbit);
00622 if ((__out.exceptions() & ios_base::badbit) != 0)
00623 __throw_exception_again;
00624 }
00625 }
00626 return __out;
00627 }
00628
00629
00630 template<class _Traits>
00631 basic_ostream<char, _Traits>&
00632 operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
00633 {
00634 typedef basic_ostream<char, _Traits> __ostream_type;
00635 typename __ostream_type::sentry __cerb(__out);
00636 if (__cerb)
00637 {
00638 try {
00639 streamsize __w = __out.width();
00640 char* __pads = static_cast<char*>(__builtin_alloca(__w));
00641 streamsize __len = static_cast<streamsize>(_Traits::length(__s));
00642 if (__w > __len)
00643 {
00644 __pad_char(__out, __pads, __s, __w, __len);
00645 __s = __pads;
00646 __len = __w;
00647 }
00648 __out.write(__s, __len);
00649 __out.width(0);
00650 }
00651 catch(exception& __fail){
00652
00653
00654 __out.setstate(ios_base::badbit);
00655 if ((__out.exceptions() & ios_base::badbit) != 0)
00656 __throw_exception_again;
00657 }
00658 }
00659 return __out;
00660 }
00661
00662
00663 template<typename _CharT, typename _Traits, typename _Alloc>
00664 basic_ostream<_CharT, _Traits>&
00665 operator<<(basic_ostream<_CharT, _Traits>& __out,
00666 const basic_string<_CharT, _Traits, _Alloc>& __s)
00667 { return (__out << __s.c_str()); }
00668
00669 }
00670
00671
00672
00673
00674