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
00040 #ifndef _GLIBCXX_OSTREAM
00041 #define _GLIBCXX_OSTREAM 1
00042
00043 #pragma GCC system_header
00044
00045 #include <ios>
00046
00047 namespace std
00048 {
00049
00057 template<typename _CharT, typename _Traits>
00058 class basic_ostream : virtual public basic_ios<_CharT, _Traits>
00059 {
00060 public:
00061
00062 typedef _CharT char_type;
00063 typedef typename _Traits::int_type int_type;
00064 typedef typename _Traits::pos_type pos_type;
00065 typedef typename _Traits::off_type off_type;
00066 typedef _Traits traits_type;
00067
00068
00069 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
00070 typedef basic_ios<_CharT, _Traits> __ios_type;
00071 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00072 typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> >
00073 __num_put_type;
00074 typedef ctype<_CharT> __ctype_type;
00075
00076 template<typename _CharT2, typename _Traits2>
00077 friend basic_ostream<_CharT2, _Traits2>&
00078 operator<<(basic_ostream<_CharT2, _Traits2>&, _CharT2);
00079
00080 template<typename _Traits2>
00081 friend basic_ostream<char, _Traits2>&
00082 operator<<(basic_ostream<char, _Traits2>&, char);
00083
00084 template<typename _CharT2, typename _Traits2>
00085 friend basic_ostream<_CharT2, _Traits2>&
00086 operator<<(basic_ostream<_CharT2, _Traits2>&, const _CharT2*);
00087
00088 template<typename _Traits2>
00089 friend basic_ostream<char, _Traits2>&
00090 operator<<(basic_ostream<char, _Traits2>&, const char*);
00091
00092 template<typename _CharT2, typename _Traits2>
00093 friend basic_ostream<_CharT2, _Traits2>&
00094 operator<<(basic_ostream<_CharT2, _Traits2>&, const char*);
00095
00096
00104 explicit
00105 basic_ostream(__streambuf_type* __sb)
00106 { this->init(__sb); }
00107
00113 virtual
00114 ~basic_ostream() { }
00115
00116
00117 class sentry;
00118 friend class sentry;
00119
00120
00121
00123
00130 inline __ostream_type&
00131 operator<<(__ostream_type& (*__pf)(__ostream_type&));
00132
00133 inline __ostream_type&
00134 operator<<(__ios_type& (*__pf)(__ios_type&));
00135
00136 inline __ostream_type&
00137 operator<<(ios_base& (*__pf) (ios_base&));
00139
00140
00167 __ostream_type&
00168 operator<<(long __n);
00169
00170 __ostream_type&
00171 operator<<(unsigned long __n);
00172
00173 __ostream_type&
00174 operator<<(bool __n);
00175
00176 __ostream_type&
00177 operator<<(short __n)
00178 {
00179 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00180 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00181 return this->operator<<(static_cast<unsigned long>
00182 (static_cast<unsigned short>(__n)));
00183 else
00184 return this->operator<<(static_cast<long>(__n));
00185 }
00186
00187 __ostream_type&
00188 operator<<(unsigned short __n)
00189 { return this->operator<<(static_cast<unsigned long>(__n)); }
00190
00191 __ostream_type&
00192 operator<<(int __n)
00193 {
00194 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00195 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00196 return this->operator<<(static_cast<unsigned long>
00197 (static_cast<unsigned int>(__n)));
00198 else
00199 return this->operator<<(static_cast<long>(__n));
00200 }
00201
00202 __ostream_type&
00203 operator<<(unsigned int __n)
00204 { return this->operator<<(static_cast<unsigned long>(__n)); }
00205
00206 #ifdef _GLIBCXX_USE_LONG_LONG
00207 __ostream_type&
00208 operator<<(long long __n);
00209
00210 __ostream_type&
00211 operator<<(unsigned long long __n);
00212 #endif
00213
00214 __ostream_type&
00215 operator<<(double __f);
00216
00217 __ostream_type&
00218 operator<<(float __f)
00219 { return this->operator<<(static_cast<double>(__f)); }
00220
00221 __ostream_type&
00222 operator<<(long double __f);
00223
00224 __ostream_type&
00225 operator<<(const void* __p);
00226
00248 __ostream_type&
00249 operator<<(__streambuf_type* __sb);
00251
00252
00281 __ostream_type&
00282 put(char_type __c);
00283
00284
00285 void
00286 _M_write(const char_type* __s, streamsize __n)
00287 {
00288 streamsize __put = this->rdbuf()->sputn(__s, __n);
00289 if (__put != __n)
00290 this->setstate(ios_base::badbit);
00291 }
00292
00309 __ostream_type&
00310 write(const char_type* __s, streamsize __n);
00312
00322 __ostream_type&
00323 flush();
00324
00325
00333 pos_type
00334 tellp();
00335
00344 __ostream_type&
00345 seekp(pos_type);
00346
00356 __ostream_type&
00357 seekp(off_type, ios_base::seekdir);
00358
00359 protected:
00360 explicit
00361 basic_ostream() { }
00362 };
00363
00374 template <typename _CharT, typename _Traits>
00375 class basic_ostream<_CharT, _Traits>::sentry
00376 {
00377
00378 bool _M_ok;
00379 basic_ostream<_CharT,_Traits>& _M_os;
00380
00381 public:
00393 explicit
00394 sentry(basic_ostream<_CharT,_Traits>& __os);
00395
00403 ~sentry()
00404 {
00405
00406 if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
00407 {
00408
00409 if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
00410 _M_os.setstate(ios_base::badbit);
00411 }
00412 }
00413
00421 operator bool() const
00422 { return _M_ok; }
00423 };
00424
00425
00427
00442 template<typename _CharT, typename _Traits>
00443 basic_ostream<_CharT, _Traits>&
00444 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c);
00445
00446 template<typename _CharT, typename _Traits>
00447 basic_ostream<_CharT, _Traits>&
00448 operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
00449 { return (__out << __out.widen(__c)); }
00450
00451
00452 template <class _Traits>
00453 basic_ostream<char, _Traits>&
00454 operator<<(basic_ostream<char, _Traits>& __out, char __c);
00455
00456
00457 template<class _Traits>
00458 basic_ostream<char, _Traits>&
00459 operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
00460 { return (__out << static_cast<char>(__c)); }
00461
00462 template<class _Traits>
00463 basic_ostream<char, _Traits>&
00464 operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
00465 { return (__out << static_cast<char>(__c)); }
00467
00469
00482 template<typename _CharT, typename _Traits>
00483 basic_ostream<_CharT, _Traits>&
00484 operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s);
00485
00486 template<typename _CharT, typename _Traits>
00487 basic_ostream<_CharT, _Traits> &
00488 operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
00489
00490
00491 template<class _Traits>
00492 basic_ostream<char, _Traits>&
00493 operator<<(basic_ostream<char, _Traits>& __out, const char* __s);
00494
00495
00496 template<class _Traits>
00497 basic_ostream<char, _Traits>&
00498 operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
00499 { return (__out << reinterpret_cast<const char*>(__s)); }
00500
00501 template<class _Traits>
00502 basic_ostream<char, _Traits> &
00503 operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
00504 { return (__out << reinterpret_cast<const char*>(__s)); }
00506
00507
00516 template<typename _CharT, typename _Traits>
00517 basic_ostream<_CharT, _Traits>&
00518 endl(basic_ostream<_CharT, _Traits>& __os)
00519 { return flush(__os.put(__os.widen('\n'))); }
00520
00527 template<typename _CharT, typename _Traits>
00528 basic_ostream<_CharT, _Traits>&
00529 ends(basic_ostream<_CharT, _Traits>& __os)
00530 { return __os.put(_CharT()); }
00531
00537 template<typename _CharT, typename _Traits>
00538 basic_ostream<_CharT, _Traits>&
00539 flush(basic_ostream<_CharT, _Traits>& __os)
00540 { return __os.flush(); }
00541
00542 }
00543
00544 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00545 # include <bits/ostream.tcc>
00546 #endif
00547
00548 #endif