ostream.tcc

Go to the documentation of this file.
00001 // ostream classes -*- C++ -*-
00002 
00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00036 //
00037 // ISO C++ 14882: 27.6.2  Output streams
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       // XXX MT
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       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00070       // DR 60. What is a formatted input function?
00071       // The inserters for manipulators are *not* formatted output functions.
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       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00081       // DR 60. What is a formatted input function?
00082       // The inserters for manipulators are *not* formatted output functions.
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       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00093       // DR 60. What is a formatted input function?
00094       // The inserters for manipulators are *not* formatted output functions.
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<<(short __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           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00134           // 117. basic_ostream uses nonexistent num_put member functions.
00135           long __l;
00136           const ios_base::fmtflags __fmt = (this->flags()
00137                         & ios_base::basefield);
00138           if (__fmt == ios_base::oct || __fmt == ios_base::hex)
00139         __l = static_cast<long>(static_cast<unsigned short>(__n));
00140           else
00141         __l = static_cast<long>(__n);
00142           const __num_put_type& __np = __check_facet(this->_M_num_put);
00143           if (__np.put(*this, *this, this->fill(), __l).failed())
00144         __err |= ios_base::badbit;
00145         }
00146       catch(...)
00147         { this->_M_setstate(ios_base::badbit); }
00148       if (__err)
00149         this->setstate(__err);
00150     }
00151       return *this;
00152     }
00153 
00154   template<typename _CharT, typename _Traits>
00155     basic_ostream<_CharT, _Traits>&
00156     basic_ostream<_CharT, _Traits>::
00157     operator<<(unsigned short __n)
00158     {
00159       sentry __cerb(*this);
00160       if (__cerb)
00161     {
00162       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00163       try
00164         {
00165           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00166           // 117. basic_ostream uses nonexistent num_put member functions.
00167           const __num_put_type& __np = __check_facet(this->_M_num_put);
00168           if (__np.put(*this, *this, this->fill(),
00169                static_cast<unsigned long>(__n)).failed())
00170         __err |= ios_base::badbit;
00171         }
00172       catch(...)
00173         { this->_M_setstate(ios_base::badbit); }
00174       if (__err)
00175         this->setstate(__err);
00176     }
00177       return *this;
00178     }
00179 
00180   template<typename _CharT, typename _Traits>
00181     basic_ostream<_CharT, _Traits>&
00182     basic_ostream<_CharT, _Traits>::
00183     operator<<(int __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           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00192           // 117. basic_ostream uses nonexistent num_put member functions.
00193           long __l;
00194           const ios_base::fmtflags __fmt = (this->flags()
00195                         & ios_base::basefield);
00196           if (__fmt == ios_base::oct || __fmt == ios_base::hex)
00197         __l = static_cast<long>(static_cast<unsigned int>(__n));
00198           else
00199         __l = static_cast<long>(__n);
00200           const __num_put_type& __np = __check_facet(this->_M_num_put);
00201           if (__np.put(*this, *this, this->fill(), __l).failed())
00202         __err |= ios_base::badbit;
00203         }
00204       catch(...)
00205         { this->_M_setstate(ios_base::badbit); }
00206       if (__err)
00207         this->setstate(__err);
00208     }
00209       return *this;
00210     }
00211 
00212   template<typename _CharT, typename _Traits>
00213     basic_ostream<_CharT, _Traits>&
00214     basic_ostream<_CharT, _Traits>::
00215     operator<<(unsigned int __n)
00216     {
00217       sentry __cerb(*this);
00218       if (__cerb)
00219     {
00220       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00221       try
00222         {
00223           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00224           // 117. basic_ostream uses nonexistent num_put member functions.
00225           const __num_put_type& __np = __check_facet(this->_M_num_put);
00226           if (__np.put(*this, *this, this->fill(),
00227                static_cast<unsigned long>(__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 
00238   template<typename _CharT, typename _Traits>
00239     basic_ostream<_CharT, _Traits>&
00240     basic_ostream<_CharT, _Traits>::
00241     operator<<(long __n)
00242     {
00243       sentry __cerb(*this);
00244       if (__cerb)
00245     {
00246       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00247       try
00248         {
00249           const __num_put_type& __np = __check_facet(this->_M_num_put);
00250           if (__np.put(*this, *this, this->fill(), __n).failed())
00251         __err |= ios_base::badbit;
00252         }
00253       catch(...)
00254         { this->_M_setstate(ios_base::badbit); }
00255       if (__err)
00256         this->setstate(__err);
00257     }
00258       return *this;
00259     }
00260 
00261   template<typename _CharT, typename _Traits>
00262     basic_ostream<_CharT, _Traits>&
00263     basic_ostream<_CharT, _Traits>::
00264     operator<<(unsigned long __n)
00265     {
00266       sentry __cerb(*this);
00267       if (__cerb)
00268     {
00269       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00270       try
00271         {
00272           const __num_put_type& __np = __check_facet(this->_M_num_put);
00273           if (__np.put(*this, *this, this->fill(), __n).failed())
00274         __err |= ios_base::badbit;
00275         }
00276       catch(...)
00277         { this->_M_setstate(ios_base::badbit); }
00278       if (__err)
00279         this->setstate(__err);
00280     }
00281       return *this;
00282     }
00283 
00284 #ifdef _GLIBCXX_USE_LONG_LONG
00285   template<typename _CharT, typename _Traits>
00286     basic_ostream<_CharT, _Traits>&
00287     basic_ostream<_CharT, _Traits>::
00288     operator<<(long long __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<<(unsigned long long __n)
00312     {
00313       sentry __cerb(*this);
00314       if (__cerb)
00315     {
00316       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00317       try
00318         {
00319           const __num_put_type& __np = __check_facet(this->_M_num_put);
00320           if (__np.put(*this, *this, this->fill(), __n).failed())
00321         __err |= ios_base::badbit;
00322         }
00323       catch(...)
00324         { this->_M_setstate(ios_base::badbit); }
00325       if (__err)
00326         this->setstate(__err);
00327     }
00328       return *this;
00329     }
00330 #endif
00331 
00332   template<typename _CharT, typename _Traits>
00333     basic_ostream<_CharT, _Traits>&
00334     basic_ostream<_CharT, _Traits>::
00335     operator<<(float __n)
00336     {
00337       sentry __cerb(*this);
00338       if (__cerb)
00339     {
00340       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00341       try
00342         {
00343           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00344           // 117. basic_ostream uses nonexistent num_put member functions.
00345           const __num_put_type& __np = __check_facet(this->_M_num_put);
00346           if (__np.put(*this, *this, this->fill(),
00347                static_cast<double>(__n)).failed())
00348         __err |= ios_base::badbit;
00349         }
00350       catch(...)
00351         { this->_M_setstate(ios_base::badbit); }
00352       if (__err)
00353         this->setstate(__err);
00354     }
00355       return *this;
00356     }
00357 
00358   template<typename _CharT, typename _Traits>
00359     basic_ostream<_CharT, _Traits>&
00360     basic_ostream<_CharT, _Traits>::
00361     operator<<(double __n)
00362     {
00363       sentry __cerb(*this);
00364       if (__cerb)
00365     {
00366       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00367       try
00368         {
00369           const __num_put_type& __np = __check_facet(this->_M_num_put);
00370           if (__np.put(*this, *this, this->fill(), __n).failed())
00371         __err |= ios_base::badbit;
00372         }
00373       catch(...)
00374         { this->_M_setstate(ios_base::badbit); }
00375       if (__err)
00376         this->setstate(__err);
00377     }
00378       return *this;
00379     }
00380 
00381   template<typename _CharT, typename _Traits>
00382     basic_ostream<_CharT, _Traits>&
00383     basic_ostream<_CharT, _Traits>::
00384     operator<<(long double __n)
00385     {
00386       sentry __cerb(*this);
00387       if (__cerb)
00388     {
00389       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00390       try
00391         {
00392           const __num_put_type& __np = __check_facet(this->_M_num_put);
00393           if (__np.put(*this, *this, this->fill(), __n).failed())
00394         __err |= ios_base::badbit;
00395         }
00396       catch(...)
00397         { this->_M_setstate(ios_base::badbit); }
00398       if (__err)
00399         this->setstate(__err);
00400     }
00401       return *this;
00402     }
00403 
00404   template<typename _CharT, typename _Traits>
00405     basic_ostream<_CharT, _Traits>&
00406     basic_ostream<_CharT, _Traits>::
00407     operator<<(const void* __n)
00408     {
00409       sentry __cerb(*this);
00410       if (__cerb)
00411     {
00412       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00413       try
00414         {
00415           const __num_put_type& __np = __check_facet(this->_M_num_put);
00416           if (__np.put(*this, *this, this->fill(), __n).failed())
00417         __err |= ios_base::badbit;
00418         }
00419       catch(...)
00420         { this->_M_setstate(ios_base::badbit); }
00421       if (__err)
00422         this->setstate(__err);
00423     }
00424       return *this;
00425     }
00426 
00427   template<typename _CharT, typename _Traits>
00428     basic_ostream<_CharT, _Traits>&
00429     basic_ostream<_CharT, _Traits>::
00430     operator<<(__streambuf_type* __sbin)
00431     {
00432       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00433       sentry __cerb(*this);
00434       if (__cerb && __sbin)
00435     {
00436       try
00437         {
00438           if (!__copy_streambufs(__sbin, this->rdbuf()))
00439         __err |= ios_base::failbit;
00440         }
00441       catch(...)
00442         { this->_M_setstate(ios_base::failbit); }
00443     }
00444       else if (!__sbin)
00445     __err |= ios_base::badbit;
00446       if (__err)
00447     this->setstate(__err);
00448       return *this;
00449     }
00450 
00451   template<typename _CharT, typename _Traits>
00452     basic_ostream<_CharT, _Traits>&
00453     basic_ostream<_CharT, _Traits>::
00454     put(char_type __c)
00455     {
00456       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00457       // DR 60. What is a formatted input function?
00458       // basic_ostream::put(char_type) is an unformatted output function.
00459       // DR 63. Exception-handling policy for unformatted output.
00460       // Unformatted output functions should catch exceptions thrown
00461       // from streambuf members.
00462       sentry __cerb(*this);
00463       if (__cerb)
00464     {
00465       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00466       try
00467         {
00468           const int_type __put = this->rdbuf()->sputc(__c);
00469           if (traits_type::eq_int_type(__put, traits_type::eof()))
00470         __err |= ios_base::badbit;
00471         }
00472       catch (...)
00473         { this->_M_setstate(ios_base::badbit); }
00474       if (__err)
00475         this->setstate(__err);
00476     }
00477       return *this;
00478     }
00479 
00480   template<typename _CharT, typename _Traits>
00481     basic_ostream<_CharT, _Traits>&
00482     basic_ostream<_CharT, _Traits>::
00483     write(const _CharT* __s, streamsize __n)
00484     {
00485       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00486       // DR 60. What is a formatted input function?
00487       // basic_ostream::write(const char_type*, streamsize) is an
00488       // unformatted output function.
00489       // DR 63. Exception-handling policy for unformatted output.
00490       // Unformatted output functions should catch exceptions thrown
00491       // from streambuf members.
00492       sentry __cerb(*this);
00493       if (__cerb)
00494     {
00495       try
00496         { _M_write(__s, __n); }
00497       catch (...)
00498         { this->_M_setstate(ios_base::badbit); }
00499     }
00500       return *this;
00501     }
00502 
00503   template<typename _CharT, typename _Traits>
00504     basic_ostream<_CharT, _Traits>&
00505     basic_ostream<_CharT, _Traits>::
00506     flush()
00507     {
00508       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00509       // DR 60. What is a formatted input function?
00510       // basic_ostream::flush() is *not* an unformatted output function.
00511       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00512       try
00513     {
00514       if (this->rdbuf() && this->rdbuf()->pubsync() == -1)
00515         __err |= ios_base::badbit;
00516     }
00517       catch(...)
00518     { this->_M_setstate(ios_base::badbit); }
00519       if (__err)
00520     this->setstate(__err);
00521       return *this;
00522     }
00523 
00524   template<typename _CharT, typename _Traits>
00525     typename basic_ostream<_CharT, _Traits>::pos_type
00526     basic_ostream<_CharT, _Traits>::
00527     tellp()
00528     {
00529       pos_type __ret = pos_type(-1);
00530       try
00531     {
00532       if (!this->fail())
00533         __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
00534     }
00535       catch(...)
00536     { this->_M_setstate(ios_base::badbit); }
00537       return __ret;
00538     }
00539 
00540   template<typename _CharT, typename _Traits>
00541     basic_ostream<_CharT, _Traits>&
00542     basic_ostream<_CharT, _Traits>::
00543     seekp(pos_type __pos)
00544     {
00545       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00546       try
00547     {
00548       if (!this->fail())
00549         {
00550           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00551           // 136.  seekp, seekg setting wrong streams?
00552           const pos_type __p = this->rdbuf()->pubseekpos(__pos,
00553                                  ios_base::out);
00554 
00555           // 129. Need error indication from seekp() and seekg()
00556           if (__p == pos_type(off_type(-1)))
00557         __err |= ios_base::failbit;
00558         }
00559     }
00560       catch(...)
00561     { this->_M_setstate(ios_base::badbit); }
00562       if (__err)
00563     this->setstate(__err);
00564       return *this;
00565     }
00566 
00567   template<typename _CharT, typename _Traits>
00568     basic_ostream<_CharT, _Traits>&
00569     basic_ostream<_CharT, _Traits>::
00570     seekp(off_type __off, ios_base::seekdir __dir)
00571     {
00572       ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00573       try
00574     {
00575       if (!this->fail())
00576         {
00577           // _GLIBCXX_RESOLVE_LIB_DEFECTS
00578           // 136.  seekp, seekg setting wrong streams?
00579           const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
00580                                  ios_base::out);
00581 
00582           // 129. Need error indication from seekp() and seekg()
00583           if (__p == pos_type(off_type(-1)))
00584         __err |= ios_base::failbit;
00585         }
00586     }
00587       catch(...)
00588     { this->_M_setstate(ios_base::badbit); }
00589       if (__err)
00590     this->setstate(__err);
00591       return *this;
00592     }
00593 
00594   // 27.6.2.5.4 Character inserters.
00595   template<typename _CharT, typename _Traits>
00596     basic_ostream<_CharT, _Traits>&
00597     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
00598     {
00599       typedef basic_ostream<_CharT, _Traits> __ostream_type;
00600       typename __ostream_type::sentry __cerb(__out);
00601       if (__cerb)
00602     {
00603       try
00604         {
00605           const streamsize __w = __out.width();
00606           streamsize __len = 1;
00607           _CharT* __cs = &__c;
00608           if (__w > __len)
00609         {
00610           __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00611                                    * __w));
00612           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
00613                          &__c, __w, __len, false);
00614           __len = __w;
00615         }
00616           __out._M_write(__cs, __len);
00617           __out.width(0);
00618         }
00619       catch(...)
00620         { __out._M_setstate(ios_base::badbit); }
00621     }
00622       return __out;
00623     }
00624 
00625   // Specializations.
00626   template <class _Traits>
00627     basic_ostream<char, _Traits>&
00628     operator<<(basic_ostream<char, _Traits>& __out, char __c)
00629     {
00630       typedef basic_ostream<char, _Traits> __ostream_type;
00631       typename __ostream_type::sentry __cerb(__out);
00632       if (__cerb)
00633     {
00634       try
00635         {
00636           const streamsize __w = __out.width();
00637           streamsize __len = 1;
00638           char* __cs = &__c;
00639           if (__w > __len)
00640         {
00641           __cs = static_cast<char*>(__builtin_alloca(__w));
00642           __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs,
00643                            &__c, __w, __len, false);
00644           __len = __w;
00645         }
00646           __out._M_write(__cs, __len);
00647           __out.width(0);
00648         }
00649       catch(...)
00650         { __out._M_setstate(ios_base::badbit); }
00651     }
00652       return __out;
00653      }
00654 
00655   template<typename _CharT, typename _Traits>
00656     basic_ostream<_CharT, _Traits>&
00657     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
00658     {
00659       typedef basic_ostream<_CharT, _Traits> __ostream_type;
00660       typename __ostream_type::sentry __cerb(__out);
00661       if (__cerb && __s)
00662     {
00663       try
00664         {
00665           const streamsize __w = __out.width();
00666           streamsize __len = static_cast<streamsize>(_Traits::length(__s));
00667           if (__w > __len)
00668         {
00669           _CharT* __cs = (static_cast<
00670                   _CharT*>(__builtin_alloca(sizeof(_CharT)
00671                                 * __w)));
00672           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
00673                          __s, __w, __len, false);
00674           __s = __cs;
00675           __len = __w;
00676         }
00677           __out._M_write(__s, __len);
00678           __out.width(0);
00679         }
00680       catch(...)
00681         { __out._M_setstate(ios_base::badbit); }
00682     }
00683       else if (!__s)
00684     __out.setstate(ios_base::badbit);
00685       return __out;
00686     }
00687 
00688   template<typename _CharT, typename _Traits>
00689     basic_ostream<_CharT, _Traits>&
00690     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
00691     {
00692       typedef basic_ostream<_CharT, _Traits> __ostream_type;
00693       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00694       // 167.  Improper use of traits_type::length()
00695       // Note that this is only in 'Review' status.
00696       typedef char_traits<char>          __traits_type;
00697       typename __ostream_type::sentry __cerb(__out);
00698       if (__cerb && __s)
00699     {
00700       size_t __clen = __traits_type::length(__s);
00701       _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
00702                                    * __clen));
00703       for (size_t  __i = 0; __i < __clen; ++__i)
00704         __ws[__i] = __out.widen(__s[__i]);
00705       _CharT* __str = __ws;
00706 
00707       try
00708         {
00709           const streamsize __w = __out.width();
00710           streamsize __len = static_cast<streamsize>(__clen);
00711           if (__w > __len)
00712         {
00713           _CharT* __cs = (static_cast<
00714                   _CharT*>(__builtin_alloca(sizeof(_CharT)
00715                                 * __w)));
00716           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs,
00717                          __ws, __w, __len, false);
00718           __str = __cs;
00719           __len = __w;
00720         }
00721           __out._M_write(__str, __len);
00722           __out.width(0);
00723         }
00724       catch(...)
00725         { __out._M_setstate(ios_base::badbit); }
00726     }
00727       else if (!__s)
00728     __out.setstate(ios_base::badbit);
00729       return __out;
00730     }
00731 
00732   // Partial specializations.
00733   template<class _Traits>
00734     basic_ostream<char, _Traits>&
00735     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
00736     {
00737       typedef basic_ostream<char, _Traits> __ostream_type;
00738       typename __ostream_type::sentry __cerb(__out);
00739       if (__cerb && __s)
00740     {
00741       try
00742         {
00743           const streamsize __w = __out.width();
00744           streamsize __len = static_cast<streamsize>(_Traits::length(__s));
00745           if (__w > __len)
00746         {
00747           char* __cs = static_cast<char*>(__builtin_alloca(__w));
00748           __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs,
00749                          __s, __w, __len, false);
00750           __s = __cs;
00751           __len = __w;
00752         }
00753           __out._M_write(__s, __len);
00754           __out.width(0);
00755         }
00756       catch(...)
00757         { __out._M_setstate(ios_base::badbit); }
00758     }
00759       else if (!__s)
00760     __out.setstate(ios_base::badbit);
00761       return __out;
00762     }
00763 
00764   // 21.3.7.9 basic_string::operator<<
00765   template<typename _CharT, typename _Traits, typename _Alloc>
00766     basic_ostream<_CharT, _Traits>&
00767     operator<<(basic_ostream<_CharT, _Traits>& __out,
00768            const basic_string<_CharT, _Traits, _Alloc>& __str)
00769     {
00770       typedef basic_ostream<_CharT, _Traits> __ostream_type;
00771       typename __ostream_type::sentry __cerb(__out);
00772       if (__cerb)
00773     {
00774       const streamsize __w = __out.width();
00775       streamsize __len = static_cast<streamsize>(__str.size());
00776       const _CharT* __s = __str.data();
00777 
00778       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00779       // 25. String operator<< uses width() value wrong
00780       if (__w > __len)
00781         {
00782           _CharT* __cs = (static_cast<
00783                   _CharT*>(__builtin_alloca(sizeof(_CharT) * __w)));
00784           __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s,
00785                          __w, __len, false);
00786           __s = __cs;
00787           __len = __w;
00788         }
00789       __out._M_write(__s, __len);
00790       __out.width(0);
00791     }
00792       return __out;
00793     }
00794 
00795   // Inhibit implicit instantiations for required instantiations,
00796   // which are defined via explicit instantiations elsewhere.
00797   // NB:  This syntax is a GNU extension.
00798 #if _GLIBCXX_EXTERN_TEMPLATE
00799   extern template class basic_ostream<char>;
00800   extern template ostream& endl(ostream&);
00801   extern template ostream& ends(ostream&);
00802   extern template ostream& flush(ostream&);
00803   extern template ostream& operator<<(ostream&, char);
00804   extern template ostream& operator<<(ostream&, unsigned char);
00805   extern template ostream& operator<<(ostream&, signed char);
00806   extern template ostream& operator<<(ostream&, const char*);
00807   extern template ostream& operator<<(ostream&, const unsigned char*);
00808   extern template ostream& operator<<(ostream&, const signed char*);
00809 
00810 #ifdef _GLIBCXX_USE_WCHAR_T
00811   extern template class basic_ostream<wchar_t>;
00812   extern template wostream& endl(wostream&);
00813   extern template wostream& ends(wostream&);
00814   extern template wostream& flush(wostream&);
00815   extern template wostream& operator<<(wostream&, wchar_t);
00816   extern template wostream& operator<<(wostream&, char);
00817   extern template wostream& operator<<(wostream&, const wchar_t*);
00818   extern template wostream& operator<<(wostream&, const char*);
00819 #endif
00820 #endif
00821 } // namespace std
00822 
00823 #endif

Generated on Tue Feb 2 16:56:20 2010 for GNU C++ STL by  doxygen 1.4.7