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