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 #ifndef _CPP_OSTREAM
00035 #define _CPP_OSTREAM 1
00036
00037 #pragma GCC system_header
00038
00039 #include <bits/std_ios.h>
00040
00041 namespace std
00042 {
00043
00044 template<typename _CharT, typename _Traits>
00045 class basic_ostream : virtual public basic_ios<_CharT, _Traits>
00046 {
00047 public:
00048
00049
00050 typedef _CharT char_type;
00051 typedef typename _Traits::int_type int_type;
00052 typedef typename _Traits::pos_type pos_type;
00053 typedef typename _Traits::off_type off_type;
00054 typedef _Traits traits_type;
00055
00056
00057 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
00058 typedef basic_ios<_CharT, _Traits> __ios_type;
00059 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00060 typedef ostreambuf_iterator<_CharT, _Traits> __ostreambuf_iter;
00061 typedef num_put<_CharT, __ostreambuf_iter> __numput_type;
00062 typedef ctype<_CharT> __ctype_type;
00063
00064
00065 explicit
00066 basic_ostream(__streambuf_type* __sb)
00067 { this->init(__sb); }
00068
00069 virtual
00070 ~basic_ostream() { }
00071
00072
00073 class sentry;
00074 friend class sentry;
00075
00076
00077
00078 __ostream_type&
00079 operator<<(__ostream_type& (*__pf)(__ostream_type&));
00080
00081 __ostream_type&
00082 operator<<(__ios_type& (*__pf)(__ios_type&));
00083
00084 __ostream_type&
00085 operator<<(ios_base& (*__pf) (ios_base&));
00086
00087
00088 __ostream_type&
00089 operator<<(long __n);
00090
00091 __ostream_type&
00092 operator<<(unsigned long __n);
00093
00094 __ostream_type&
00095 operator<<(bool __n);
00096
00097 __ostream_type&
00098 operator<<(short __n)
00099 {
00100 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00101 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00102 return this->operator<<(static_cast<unsigned long>
00103 (static_cast<unsigned short>(__n)));
00104 else
00105 return this->operator<<(static_cast<long>(__n));
00106 }
00107
00108 __ostream_type&
00109 operator<<(unsigned short __n)
00110 { return this->operator<<(static_cast<unsigned long>(__n)); }
00111
00112 __ostream_type&
00113 operator<<(int __n)
00114 {
00115 ios_base::fmtflags __fmt = this->flags() & ios_base::basefield;
00116 if (__fmt & ios_base::oct || __fmt & ios_base::hex)
00117 return this->operator<<(static_cast<unsigned long>
00118 (static_cast<unsigned int>(__n)));
00119 else
00120 return this->operator<<(static_cast<long>(__n));
00121 }
00122
00123 __ostream_type&
00124 operator<<(unsigned int __n)
00125 { return this->operator<<(static_cast<unsigned long>(__n)); }
00126
00127 #ifdef _GLIBCPP_USE_LONG_LONG
00128 __ostream_type&
00129 operator<<(long long __n);
00130
00131 __ostream_type&
00132 operator<<(unsigned long long __n);
00133 #endif
00134
00135 __ostream_type&
00136 operator<<(double __f);
00137
00138 __ostream_type&
00139 operator<<(float __f)
00140 { return this->operator<<(static_cast<double>(__f)); }
00141
00142 __ostream_type&
00143 operator<<(long double __f);
00144
00145 __ostream_type&
00146 operator<<(const void* __p);
00147
00148 __ostream_type&
00149 operator<<(__streambuf_type* __sb);
00150
00151
00152 __ostream_type&
00153 put(char_type __c);
00154
00155 __ostream_type&
00156 write(const char_type* __s, streamsize __n);
00157
00158 __ostream_type&
00159 flush();
00160
00161
00162 pos_type
00163 tellp();
00164
00165 __ostream_type&
00166 seekp(pos_type);
00167
00168 __ostream_type&
00169 seekp(off_type, ios_base::seekdir);
00170
00171 private:
00172 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00173
00174 __ostream_type&
00175 operator=(const __ostream_type&);
00176
00177 basic_ostream(const __ostream_type&);
00178 #endif
00179 };
00180
00181
00182 template <typename _CharT, typename _Traits>
00183 class basic_ostream<_CharT, _Traits>::sentry
00184 {
00185
00186 bool _M_ok;
00187 basic_ostream<_CharT,_Traits>& _M_os;
00188
00189 public:
00190 explicit
00191 sentry(basic_ostream<_CharT,_Traits>& __os);
00192
00193 ~sentry()
00194 {
00195
00196 if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception())
00197 {
00198
00199 if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1)
00200 _M_os.setstate(ios_base::badbit);
00201 }
00202 }
00203
00204 operator bool()
00205 { return _M_ok; }
00206 };
00207
00208 template<typename _CharT, typename _Traits>
00209 basic_ostream<_CharT, _Traits>&
00210 operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c);
00211
00212 template<typename _CharT, typename _Traits>
00213 basic_ostream<_CharT, _Traits>&
00214 operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
00215 { return (__out << __out.widen(__c)); }
00216
00217
00218 template <class _Traits>
00219 basic_ostream<char, _Traits>&
00220 operator<<(basic_ostream<char, _Traits>& __out, char __c);
00221
00222
00223 template<class _Traits>
00224 basic_ostream<char, _Traits>&
00225 operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
00226 { return (__out << static_cast<char>(__c)); }
00227
00228 template<class _Traits>
00229 basic_ostream<char, _Traits>&
00230 operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
00231 { return (__out << static_cast<char>(__c)); }
00232
00233 template<typename _CharT, typename _Traits>
00234 basic_ostream<_CharT, _Traits>&
00235 operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s);
00236
00237 template<typename _CharT, typename _Traits>
00238 basic_ostream<_CharT, _Traits> &
00239 operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s);
00240
00241
00242 template<class _Traits>
00243 basic_ostream<char, _Traits>&
00244 operator<<(basic_ostream<char, _Traits>& __out, const char* __s);
00245
00246
00247 template<class _Traits>
00248 basic_ostream<char, _Traits>&
00249 operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
00250 { return (__out << reinterpret_cast<const char*>(__s)); }
00251
00252 template<class _Traits>
00253 basic_ostream<char, _Traits> &
00254 operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
00255 { return (__out << reinterpret_cast<const char*>(__s)); }
00256
00257
00258 template<typename _CharT, typename _Traits>
00259 basic_ostream<_CharT, _Traits>&
00260 endl(basic_ostream<_CharT, _Traits>& __os)
00261 { return flush(__os.put(__os.widen('\n'))); }
00262
00263 template<typename _CharT, typename _Traits>
00264 basic_ostream<_CharT, _Traits>&
00265 ends(basic_ostream<_CharT, _Traits>& __os)
00266 { return __os.put(_CharT()); }
00267
00268 template<typename _CharT, typename _Traits>
00269 basic_ostream<_CharT, _Traits>&
00270 flush(basic_ostream<_CharT, _Traits>& __os)
00271 { return __os.flush(); }
00272
00273 }
00274
00275 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00276 # define export
00277 #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
00278 # include <bits/ostream.tcc>
00279 #endif
00280 #endif
00281
00282 #endif
00283