Copyright (C) 2000-2012 |
Whole document tree ostream.tccGo to the documentation of this file.00001 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 00002 // 00003 // This file is part of the GNU ISO C++ Library. This library is free 00004 // software; you can redistribute it and/or modify it under the 00005 // terms of the GNU General Public License as published by the 00006 // Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License along 00015 // with this library; see the file COPYING. If not, write to the Free 00016 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00017 // USA. 00018 00019 // As a special exception, you may use this file as part of a free software 00020 // library without restriction. Specifically, if other files instantiate 00021 // templates or use macros or inline functions from this file, or you compile 00022 // this file and link it with other files to produce an executable, this 00023 // file does not by itself cause the resulting executable to be covered by 00024 // the GNU General Public License. This exception does not however 00025 // invalidate any other reasons why the executable file might be covered by 00026 // the GNU General Public License. 00027 00028 // 00029 // ISO C++ 14882: 27.6.2 Output streams 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 // XXX MT 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 catch(exception& __fail) 00057 { 00058 // 27.6.2.5.1 Common requirements. 00059 // Turn this on without causing an ios::failure to be thrown. 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 catch(exception& __fail) 00079 { 00080 // 27.6.2.5.1 Common requirements. 00081 // Turn this on without causing an ios::failure to be thrown. 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 catch(exception& __fail) 00101 { 00102 // 27.6.2.5.1 Common requirements. 00103 // Turn this on without causing an ios::failure to be thrown. 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 { 00121 if (_M_check_facet(_M_fnumput)) 00122 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed()) 00123 this->setstate(ios_base::badbit); 00124 } 00125 catch(exception& __fail) 00126 { 00127 // 27.6.1.2.1 Common requirements. 00128 // Turn this on without causing an ios::failure to be thrown. 00129 this->setstate(ios_base::badbit); 00130 if ((this->exceptions() & ios_base::badbit) != 0) 00131 __throw_exception_again; 00132 } 00133 } 00134 return *this; 00135 } 00136 00137 template<typename _CharT, typename _Traits> 00138 basic_ostream<_CharT, _Traits>& 00139 basic_ostream<_CharT, _Traits>::operator<<(long __n) 00140 { 00141 sentry __cerb(*this); 00142 if (__cerb) 00143 { 00144 try 00145 { 00146 char_type __c = this->fill(); 00147 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; 00148 if (_M_check_facet(_M_fnumput)) 00149 { 00150 bool __b = false; 00151 if (__fmt & ios_base::oct || __fmt & ios_base::hex) 00152 { 00153 unsigned long __l = static_cast<unsigned long>(__n); 00154 __b = _M_fnumput->put(*this, *this, __c, __l).failed(); 00155 } 00156 else 00157 __b = _M_fnumput->put(*this, *this, __c, __n).failed(); 00158 if (__b) 00159 this->setstate(ios_base::badbit); 00160 } 00161 } 00162 catch(exception& __fail) 00163 { 00164 // 27.6.1.2.1 Common requirements. 00165 // Turn this on without causing an ios::failure to be thrown. 00166 this->setstate(ios_base::badbit); 00167 if ((this->exceptions() & ios_base::badbit) != 0) 00168 __throw_exception_again; 00169 } 00170 } 00171 return *this; 00172 } 00173 00174 template<typename _CharT, typename _Traits> 00175 basic_ostream<_CharT, _Traits>& 00176 basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n) 00177 { 00178 sentry __cerb(*this); 00179 if (__cerb) 00180 { 00181 try 00182 { 00183 if (_M_check_facet(_M_fnumput)) 00184 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed()) 00185 this->setstate(ios_base::badbit); 00186 } 00187 catch(exception& __fail) 00188 { 00189 // 27.6.1.2.1 Common requirements. 00190 // Turn this on without causing an ios::failure to be thrown. 00191 this->setstate(ios_base::badbit); 00192 if ((this->exceptions() & ios_base::badbit) != 0) 00193 __throw_exception_again; 00194 } 00195 } 00196 return *this; 00197 } 00198 00199 #ifdef _GLIBCPP_USE_LONG_LONG 00200 template<typename _CharT, typename _Traits> 00201 basic_ostream<_CharT, _Traits>& 00202 basic_ostream<_CharT, _Traits>::operator<<(long long __n) 00203 { 00204 sentry __cerb(*this); 00205 if (__cerb) 00206 { 00207 try 00208 { 00209 char_type __c = this->fill(); 00210 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; 00211 if (_M_check_facet(_M_fnumput)) 00212 { 00213 bool __b = false; 00214 if (__fmt & ios_base::oct || __fmt & ios_base::hex) 00215 { 00216 unsigned long long __l; 00217 __l = static_cast<unsigned long long>(__n); 00218 __b = _M_fnumput->put(*this, *this, __c, __l).failed(); 00219 } 00220 else 00221 __b = _M_fnumput->put(*this, *this, __c, __n).failed(); 00222 if (__b) 00223 this->setstate(ios_base::badbit); 00224 } 00225 } 00226 catch(exception& __fail) 00227 { 00228 // 27.6.1.2.1 Common requirements. 00229 // Turn this on without causing an ios::failure to be thrown. 00230 this->setstate(ios_base::badbit); 00231 if ((this->exceptions() & ios_base::badbit) != 0) 00232 __throw_exception_again; 00233 } 00234 } 00235 return *this; 00236 } 00237 00238 template<typename _CharT, typename _Traits> 00239 basic_ostream<_CharT, _Traits>& 00240 basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n) 00241 { 00242 sentry __cerb(*this); 00243 if (__cerb) 00244 { 00245 try 00246 { 00247 if (_M_check_facet(_M_fnumput)) 00248 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed()) 00249 this->setstate(ios_base::badbit); 00250 } 00251 catch(exception& __fail) 00252 { 00253 // 27.6.1.2.1 Common requirements. 00254 // Turn this on without causing an ios::failure to be thrown. 00255 this->setstate(ios_base::badbit); 00256 if ((this->exceptions() & ios_base::badbit) != 0) 00257 __throw_exception_again; 00258 } 00259 } 00260 return *this; 00261 } 00262 #endif 00263 00264 template<typename _CharT, typename _Traits> 00265 basic_ostream<_CharT, _Traits>& 00266 basic_ostream<_CharT, _Traits>::operator<<(double __n) 00267 { 00268 sentry __cerb(*this); 00269 if (__cerb) 00270 { 00271 try 00272 { 00273 if (_M_check_facet(_M_fnumput)) 00274 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed()) 00275 this->setstate(ios_base::badbit); 00276 } 00277 catch(exception& __fail) 00278 { 00279 // 27.6.1.2.1 Common requirements. 00280 // Turn this on without causing an ios::failure to be thrown. 00281 this->setstate(ios_base::badbit); 00282 if ((this->exceptions() & ios_base::badbit) != 0) 00283 __throw_exception_again; 00284 } 00285 } 00286 return *this; 00287 } 00288 00289 template<typename _CharT, typename _Traits> 00290 basic_ostream<_CharT, _Traits>& 00291 basic_ostream<_CharT, _Traits>::operator<<(long double __n) 00292 { 00293 sentry __cerb(*this); 00294 if (__cerb) 00295 { 00296 try 00297 { 00298 if (_M_check_facet(_M_fnumput)) 00299 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed()) 00300 this->setstate(ios_base::badbit); 00301 } 00302 catch(exception& __fail) 00303 { 00304 // 27.6.1.2.1 Common requirements. 00305 // Turn this on without causing an ios::failure to be thrown. 00306 this->setstate(ios_base::badbit); 00307 if ((this->exceptions() & ios_base::badbit) != 0) 00308 __throw_exception_again; 00309 } 00310 } 00311 return *this; 00312 } 00313 00314 template<typename _CharT, typename _Traits> 00315 basic_ostream<_CharT, _Traits>& 00316 basic_ostream<_CharT, _Traits>::operator<<(const void* __n) 00317 { 00318 sentry __cerb(*this); 00319 if (__cerb) 00320 { 00321 try 00322 { 00323 if (_M_check_facet(_M_fnumput)) 00324 if (_M_fnumput->put(*this, *this, this->fill(), __n).failed()) 00325 this->setstate(ios_base::badbit); 00326 } 00327 catch(exception& __fail) 00328 { 00329 // 27.6.1.2.1 Common requirements. 00330 // Turn this on without causing an ios::failure to be thrown. 00331 this->setstate(ios_base::badbit); 00332 if ((this->exceptions() & ios_base::badbit) != 0) 00333 __throw_exception_again; 00334 } 00335 } 00336 return *this; 00337 } 00338 00339 template<typename _CharT, typename _Traits> 00340 basic_ostream<_CharT, _Traits>& 00341 basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sbin) 00342 { 00343 streamsize __xtrct = 0; 00344 __streambuf_type* __sbout = this->rdbuf(); 00345 sentry __cerb(*this); 00346 if (__sbin && __cerb) 00347 __xtrct = __copy_streambufs(*this, __sbin, __sbout); 00348 if (!__sbin || !__xtrct) 00349 this->setstate(ios_base::failbit); 00350 return *this; 00351 } 00352 00353 template<typename _CharT, typename _Traits> 00354 basic_ostream<_CharT, _Traits>& 00355 basic_ostream<_CharT, _Traits>::put(char_type __c) 00356 { 00357 sentry __cerb(*this); 00358 if (__cerb) 00359 { 00360 int_type __put = rdbuf()->sputc(__c); 00361 if (__put != traits_type::to_int_type(__c)) 00362 this->setstate(ios_base::badbit); 00363 } 00364 return *this; 00365 } 00366 00367 template<typename _CharT, typename _Traits> 00368 basic_ostream<_CharT, _Traits>& 00369 basic_ostream<_CharT, _Traits>::write(const _CharT* __s, streamsize __n) 00370 { 00371 sentry __cerb(*this); 00372 if (__cerb) 00373 { 00374 streamsize __put = this->rdbuf()->sputn(__s, __n); 00375 if ( __put != __n) 00376 this->setstate(ios_base::badbit); 00377 } 00378 return *this; 00379 } 00380 00381 template<typename _CharT, typename _Traits> 00382 basic_ostream<_CharT, _Traits>& 00383 basic_ostream<_CharT, _Traits>::flush() 00384 { 00385 sentry __cerb(*this); 00386 if (__cerb) 00387 { 00388 if (this->rdbuf() && this->rdbuf()->pubsync() == -1) 00389 this->setstate(ios_base::badbit); 00390 } 00391 return *this; 00392 } 00393 00394 template<typename _CharT, typename _Traits> 00395 typename basic_ostream<_CharT, _Traits>::pos_type 00396 basic_ostream<_CharT, _Traits>::tellp() 00397 { 00398 pos_type __ret = pos_type(-1); 00399 bool __testok = this->fail() != true; 00400 00401 if (__testok) 00402 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); 00403 return __ret; 00404 } 00405 00406 00407 template<typename _CharT, typename _Traits> 00408 basic_ostream<_CharT, _Traits>& 00409 basic_ostream<_CharT, _Traits>::seekp(pos_type __pos) 00410 { 00411 bool __testok = this->fail() != true; 00412 00413 if (__testok) 00414 { 00415 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS 00416 // 136. seekp, seekg setting wrong streams? 00417 pos_type __err = this->rdbuf()->pubseekpos(__pos, ios_base::out); 00418 00419 // 129. Need error indication from seekp() and seekg() 00420 if (__err == pos_type(off_type(-1))) 00421 this->setstate(failbit); 00422 #endif 00423 } 00424 return *this; 00425 } 00426 00427 template<typename _CharT, typename _Traits> 00428 basic_ostream<_CharT, _Traits>& 00429 basic_ostream<_CharT, _Traits>:: 00430 seekp(off_type __off, ios_base::seekdir __d) 00431 { 00432 bool __testok = this->fail() != true; 00433 00434 if (__testok) 00435 { 00436 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS 00437 // 136. seekp, seekg setting wrong streams? 00438 pos_type __err = this->rdbuf()->pubseekoff(__off, __d, 00439 ios_base::out); 00440 00441 // 129. Need error indication from seekp() and seekg() 00442 if (__err == pos_type(off_type(-1))) 00443 this->setstate(failbit); 00444 } 00445 #endif 00446 return *this; 00447 } 00448 00449 // 27.6.2.5.4 Character inserters 00450 00451 // Construct correctly padded string, as per 22.2.2.2.2 00452 // Similar in theory to __pad_numeric, from num_put, but it doesn't 00453 // use _S_fill: perhaps it should. 00454 // Assumes 00455 // __newlen > __oldlen 00456 // __news is allocated for __newlen size 00457 template<typename _CharT, typename _Traits> 00458 void 00459 __pad_char(basic_ios<_CharT, _Traits>& __ios, 00460 _CharT* __news, const _CharT* __olds, 00461 const streamsize __newlen, const streamsize __oldlen) 00462 { 00463 typedef _CharT char_type; 00464 typedef _Traits traits_type; 00465 typedef typename traits_type::int_type int_type; 00466 00467 int_type __plen = static_cast<size_t>(__newlen - __oldlen); 00468 char_type* __pads = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __plen)); 00469 traits_type::assign(__pads, __plen, __ios.fill()); 00470 00471 char_type* __beg; 00472 char_type* __end; 00473 size_t __mod = 0; 00474 size_t __beglen; //either __plen or __oldlen 00475 ios_base::fmtflags __fmt = __ios.flags() & ios_base::adjustfield; 00476 00477 if (__fmt == ios_base::left) 00478 { 00479 // Padding last. 00480 __beg = const_cast<char_type*>(__olds); 00481 __beglen = __oldlen; 00482 __end = __pads; 00483 } 00484 else if (__fmt == ios_base::internal) 00485 { 00486 // Pad after the sign, if there is one. 00487 // Pad after 0[xX], if there is one. 00488 // Who came up with these rules, anyway? Jeeze. 00489 typedef _Format_cache<_CharT> __cache_type; 00490 __cache_type const* __lfmt = __cache_type::_S_get(__ios); 00491 const char_type* __minus = traits_type::find(__olds, __oldlen, 00492 __lfmt->_S_minus); 00493 const char_type* __plus = traits_type::find(__olds, __oldlen, 00494 __lfmt->_S_plus); 00495 bool __testsign = __minus || __plus; 00496 bool __testhex = __olds[0] == '0' 00497 && (__olds[1] == 'x' || __olds[1] == 'X'); 00498 00499 if (__testhex) 00500 { 00501 __news[0] = __olds[0]; 00502 __news[1] = __olds[1]; 00503 __mod += 2; 00504 __beg = const_cast<char_type*>(__olds + __mod); 00505 __beglen = __oldlen - __mod; 00506 __end = __pads; 00507 } 00508 else if (__testsign) 00509 { 00510 __mod += __plen; 00511 const char_type* __sign = __minus ? __minus + 1: __plus + 1; 00512 __beg = const_cast<char_type*>(__olds); 00513 __beglen = __sign - __olds; 00514 __end = const_cast<char_type*>(__sign + __plen); 00515 traits_type::copy(__news + __beglen, __pads, __plen); 00516 } 00517 else 00518 { 00519 // Padding first. 00520 __beg = __pads; 00521 __beglen = __plen; 00522 __end = const_cast<char_type*>(__olds); 00523 } 00524 } 00525 else 00526 { 00527 // Padding first. 00528 __beg = __pads; 00529 __beglen = __plen; 00530 __end = const_cast<char_type*>(__olds); 00531 } 00532 00533 traits_type::copy(__news, __beg, __beglen); 00534 traits_type::copy(__news + __beglen, __end, __newlen - __beglen - __mod); 00535 } 00536 00537 template<typename _CharT, typename _Traits> 00538 basic_ostream<_CharT, _Traits>& 00539 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c) 00540 { 00541 typedef basic_ostream<_CharT, _Traits> __ostream_type; 00542 typename __ostream_type::sentry __cerb(__out); 00543 if (__cerb) 00544 { 00545 try 00546 { 00547 streamsize __w = __out.width(); 00548 _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); 00549 __pads[0] = __c; 00550 streamsize __len = 1; 00551 if (__w > __len) 00552 { 00553 __pad_char(__out, __pads, &__c, __w, __len); 00554 __len = __w; 00555 } 00556 __out.write(__pads, __len); 00557 __out.width(0); 00558 } 00559 catch(exception& __fail) 00560 { 00561 // 27.6.1.2.1 Common requirements. 00562 // Turn this on without causing an ios::failure to be thrown. 00563 __out.setstate(ios_base::badbit); 00564 if ((__out.exceptions() & ios_base::badbit) != 0) 00565 __throw_exception_again; 00566 } 00567 } 00568 return __out; 00569 } 00570 00571 // Specialization 00572 template <class _Traits> 00573 basic_ostream<char, _Traits>& 00574 operator<<(basic_ostream<char, _Traits>& __out, char __c) 00575 { 00576 typedef basic_ostream<char, _Traits> __ostream_type; 00577 typename __ostream_type::sentry __cerb(__out); 00578 if (__cerb) 00579 { 00580 try 00581 { 00582 streamsize __w = __out.width(); 00583 char* __pads = static_cast<char*>(__builtin_alloca(__w + 1)); 00584 __pads[0] = __c; 00585 streamsize __len = 1; 00586 if (__w > __len) 00587 { 00588 __pad_char(__out, __pads, &__c, __w, __len); 00589 __len = __w; 00590 } 00591 __out.write(__pads, __len); 00592 __out.width(0); 00593 } 00594 catch(exception& __fail) 00595 { 00596 // 27.6.1.2.1 Common requirements. 00597 // Turn this on without causing an ios::failure to be thrown. 00598 __out.setstate(ios_base::badbit); 00599 if ((__out.exceptions() & ios_base::badbit) != 0) 00600 __throw_exception_again; 00601 } 00602 } 00603 return __out; 00604 } 00605 00606 template<typename _CharT, typename _Traits> 00607 basic_ostream<_CharT, _Traits>& 00608 operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) 00609 { 00610 typedef basic_ostream<_CharT, _Traits> __ostream_type; 00611 typename __ostream_type::sentry __cerb(__out); 00612 if (__cerb) 00613 { 00614 try 00615 { 00616 streamsize __w = __out.width(); 00617 _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); 00618 streamsize __len = static_cast<streamsize>(_Traits::length(__s)); 00619 if (__w > __len) 00620 { 00621 __pad_char(__out, __pads, __s, __w, __len); 00622 __s = __pads; 00623 __len = __w; 00624 } 00625 __out.write(__s, __len); 00626 __out.width(0); 00627 } 00628 catch(exception& __fail) 00629 { 00630 // 27.6.1.2.1 Common requirements. 00631 // Turn this on without causing an ios::failure to be thrown. 00632 __out.setstate(ios_base::badbit); 00633 if ((__out.exceptions() & ios_base::badbit) != 0) 00634 __throw_exception_again; 00635 } 00636 } 00637 return __out; 00638 } 00639 00640 template<typename _CharT, typename _Traits> 00641 basic_ostream<_CharT, _Traits>& 00642 operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) 00643 { 00644 typedef basic_ostream<_CharT, _Traits> __ostream_type; 00645 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS 00646 // 167. Improper use of traits_type::length() 00647 typedef char_traits<char> __ctraits_type; 00648 #endif 00649 typename __ostream_type::sentry __cerb(__out); 00650 if (__cerb) 00651 { 00652 size_t __clen = __ctraits_type::length(__s); 00653 _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__clen + 1))); 00654 for (size_t __i = 0; __i <= __clen; ++__i) 00655 __ws[__i] = __out.widen(__s[__i]); 00656 _CharT* __str = __ws; 00657 00658 try 00659 { 00660 streamsize __len = static_cast<streamsize>(__clen); 00661 streamsize __w = __out.width(); 00662 _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); 00663 00664 if (__w > __len) 00665 { 00666 __pad_char(__out, __pads, __ws, __w, __len); 00667 __str = __pads; 00668 __len = __w; 00669 } 00670 __out.write(__str, __len); 00671 __out.width(0); 00672 } 00673 catch(exception& __fail) 00674 { 00675 // 27.6.1.2.1 Common requirements. 00676 // Turn this on without causing an ios::failure to be thrown. 00677 __out.setstate(ios_base::badbit); 00678 if ((__out.exceptions() & ios_base::badbit) != 0) 00679 __throw_exception_again; 00680 } 00681 } 00682 return __out; 00683 } 00684 00685 // Partial specializationss 00686 template<class _Traits> 00687 basic_ostream<char, _Traits>& 00688 operator<<(basic_ostream<char, _Traits>& __out, const char* __s) 00689 { 00690 typedef basic_ostream<char, _Traits> __ostream_type; 00691 typename __ostream_type::sentry __cerb(__out); 00692 if (__cerb) 00693 { 00694 try 00695 { 00696 streamsize __w = __out.width(); 00697 char* __pads = static_cast<char*>(__builtin_alloca(__w)); 00698 streamsize __len = static_cast<streamsize>(_Traits::length(__s)); 00699 if (__w > __len) 00700 { 00701 __pad_char(__out, __pads, __s, __w, __len); 00702 __s = __pads; 00703 __len = __w; 00704 } 00705 __out.write(__s, __len); 00706 __out.width(0); 00707 } 00708 catch(exception& __fail) 00709 { 00710 // 27.6.1.2.1 Common requirements. 00711 // Turn this on without causing an ios::failure to be thrown. 00712 __out.setstate(ios_base::badbit); 00713 if ((__out.exceptions() & ios_base::badbit) != 0) 00714 __throw_exception_again; 00715 } 00716 } 00717 return __out; 00718 } 00719 00720 // 21.3.7.9 basic_string::operator<< 00721 template<typename _CharT, typename _Traits, typename _Alloc> 00722 basic_ostream<_CharT, _Traits>& 00723 operator<<(basic_ostream<_CharT, _Traits>& __out, 00724 const basic_string<_CharT, _Traits, _Alloc>& __str) 00725 { 00726 typedef basic_ostream<_CharT, _Traits> __ostream_type; 00727 typename __ostream_type::sentry __cerb(__out); 00728 if (__cerb) 00729 { 00730 const _CharT* __s = __str.data(); 00731 streamsize __w = __out.width(); 00732 _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); 00733 streamsize __len = static_cast<streamsize>(__str.size()); 00734 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS 00735 // 25. String operator<< uses width() value wrong 00736 #endif 00737 if (__w > __len) 00738 { 00739 __pad_char(__out, __pads, __s, __w, __len); 00740 __s = __pads; 00741 __len = __w; 00742 } 00743 streamsize __res = __out.rdbuf()->sputn(__s, __len); 00744 __out.width(0); 00745 if (__res != __len) 00746 __out.setstate(ios_base::failbit); 00747 } 00748 return __out; 00749 } 00750 } // namespace std 00751 00752 // Local Variables: 00753 // mode:C++ 00754 // End: 00755 Generated on Mon Apr 8 03:11:30 2002 for libstdc++-v3 Source by 1.2.15 |