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