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 _CPP_OSTREAM
00041 #define _CPP_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 ostreambuf_iterator<_CharT, _Traits> __ostreambuf_iter;
00073 typedef num_put<_CharT, __ostreambuf_iter> __numput_type;
00074 typedef ctype<_CharT> __ctype_type;
00075
00076
00084 explicit
00085 basic_ostream(__streambuf_type* __sb)
00086 { this->init(__sb); }
00087
00093 virtual
00094 ~basic_ostream() { }
00095
00096
00097 class sentry;
00098 friend class sentry;
00099
00100
00101
00103
00110 __ostream_type&
00111 operator<<(__ostream_type& (*__pf)(__ostream_type&));
00112
00113 __ostream_type&
00114 operator<<(__ios_type& (*__pf)(__ios_type&));
00115
00116 __ostream_type&
00117 operator<<(ios_base& (*__pf) (ios_base&));
00119
00120
00147 __ostream_type&
00148 operator<<(long __n);
00149
00150 __ostream_type&
00151 operator<<(unsigned long __n);
00152
00153 __ostream_type&
00154 operator<<(bool __n);
00155
00156 __ostream_type&
00157 operator<<(short __n)
00158 {
00159 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00160 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00161 return this->operator<<(static_cast<unsigned long>
00162 (static_cast<unsigned short>(__n)));
00163 else
00164 return this->operator<<(static_cast<long>(__n));
00165 }
00166
00167 __ostream_type&
00168 operator<<(unsigned short __n)
00169 { return this->operator<<(static_cast<unsigned long>(__n)); }
00170
00171 __ostream_type&
00172 operator<<(int __n)
00173 {
00174 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00175 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00176 return this->operator<<(static_cast<unsigned long>
00177 (static_cast<unsigned int>(__n)));
00178 else
00179 return this->operator<<(static_cast<long>(__n));
00180 }
00181
00182 __ostream_type&
00183 operator<<(unsigned int __n)
00184 { return this->operator<<(static_cast<unsigned long>(__n)); }
00185
00186 #ifdef _GLIBCPP_USE_LONG_LONG
00187 __ostream_type&
00188 operator<<(long long __n);
00189
00190 __ostream_type&
00191 operator<<(unsigned long long __n);
00192 #endif
00193
00194 __ostream_type&
00195 operator<<(double __f);
00196
00197 __ostream_type&
00198 operator<<(float __f)
00199 { return this->operator<<(static_cast<double>(__f)); }
00200
00201 __ostream_type&
00202 operator<<(long double __f);
00203
00204 __ostream_type&
00205 operator<<(const void* __p);
00206
00228 __ostream_type&
00229 operator<<(__streambuf_type* __sb);
00231
00232
00261 __ostream_type&
00262 put(char_type __c);
00263
00280 __ostream_type&
00281 write(const char_type* __s, streamsize __n);
00283
00293 __ostream_type&
00294 flush();
00295
00296
00304 pos_type
00305 tellp();
00306
00315 __ostream_type&
00316 seekp(pos_type);
00317
00327 __ostream_type&
00328 seekp(off_type, ios_base::seekdir);
00329 };
00330
00341 template <typename _CharT, typename _Traits>
00342 class basic_ostream<_CharT, _Traits>::sentry
00343 {
00344
00345 bool _M_ok;
00346 basic_ostream<_CharT,_Traits>& _M_os;
00347
00348 public:
00360 explicit
00361 sentry(basic_ostream<_CharT,_Traits>& __os);
00362
00370 ~sentry()
00371 {
00372
00373 if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
00374 {
00375
00376 if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
00377 _M_os.setstate(ios_base::badbit);
00378 }
00379 }
00380
00388 operator bool()
00389 { return _M_ok; }
00390 };
00391
00392
00394
00409 template<typename _CharT, typename _Traits>
00410 basic_ostream<_CharT, _Traits>&
00411 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c);
00412
00413 template<typename _CharT, typename _Traits>
00414 basic_ostream<_CharT, _Traits>&
00415 operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
00416 { return (__out << __out.widen(__c)); }
00417
00418
00419 template <class _Traits>
00420 basic_ostream<char, _Traits>&
00421 operator<<(basic_ostream<char, _Traits>& __out, char __c);
00422
00423
00424 template<class _Traits>
00425 basic_ostream<char, _Traits>&
00426 operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
00427 { return (__out << static_cast<char>(__c)); }
00428
00429 template<class _Traits>
00430 basic_ostream<char, _Traits>&
00431 operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
00432 { return (__out << static_cast<char>(__c)); }
00434
00436
00449 template<typename _CharT, typename _Traits>
00450 basic_ostream<_CharT, _Traits>&
00451 operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s);
00452
00453 template<typename _CharT, typename _Traits>
00454 basic_ostream<_CharT, _Traits> &
00455 operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
00456
00457
00458 template<class _Traits>
00459 basic_ostream<char, _Traits>&
00460 operator<<(basic_ostream<char, _Traits>& __out, const char* __s);
00461
00462
00463 template<class _Traits>
00464 basic_ostream<char, _Traits>&
00465 operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
00466 { return (__out << reinterpret_cast<const char*>(__s)); }
00467
00468 template<class _Traits>
00469 basic_ostream<char, _Traits> &
00470 operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
00471 { return (__out << reinterpret_cast<const char*>(__s)); }
00473
00474
00483 template<typename _CharT, typename _Traits>
00484 basic_ostream<_CharT, _Traits>&
00485 endl(basic_ostream<_CharT, _Traits>& __os)
00486 { return flush(__os.put(__os.widen('\n'))); }
00487
00494 template<typename _CharT, typename _Traits>
00495 basic_ostream<_CharT, _Traits>&
00496 ends(basic_ostream<_CharT, _Traits>& __os)
00497 { return __os.put(_CharT()); }
00498
00504 template<typename _CharT, typename _Traits>
00505 basic_ostream<_CharT, _Traits>&
00506 flush(basic_ostream<_CharT, _Traits>& __os)
00507 { return __os.flush(); }
00508
00509 }
00510
00511 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00512 # define export
00513 #endif
00514 #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
00515 # include <bits/ostream.tcc>
00516 #endif
00517
00518 #endif