00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _STLP_INTERNAL_OSTREAM_H
00021 #define _STLP_INTERNAL_OSTREAM_H
00022
00023 #ifndef _STLP_INTERNAL_IOS_H
00024 # include <stl/_ios.h>
00025 #endif
00026
00027 #ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
00028 # include <stl/_ostreambuf_iterator.h>
00029 #endif
00030
00031 _STLP_BEGIN_NAMESPACE
00032
00033 template <class _CharT, class _Traits, class _Number>
00034 basic_ostream<_CharT, _Traits>& _STLP_CALL
00035 _M_put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x);
00036
00037 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00038 template <class _CharT, class _Traits>
00039 class _Osentry;
00040 # endif
00041
00042 template <class _CharT, class _Traits>
00043 bool
00044 _M_init(basic_ostream<_CharT, _Traits>& __str);
00045
00046
00047
00048
00049 template <class _CharT, class _Traits>
00050 class basic_ostream : virtual public basic_ios<_CharT, _Traits>
00051 {
00052 typedef basic_ostream<_CharT, _Traits> _Self;
00053
00054 public:
00055 typedef _CharT char_type;
00056 typedef typename _Traits::int_type int_type;
00057 typedef typename _Traits::pos_type pos_type;
00058 typedef typename _Traits::off_type off_type;
00059 typedef _Traits traits_type;
00060 typedef basic_ios<_CharT, _Traits> _Basic_ios;
00061
00062 public:
00063 explicit basic_ostream(basic_streambuf<_CharT, _Traits>* __buf);
00064 ~basic_ostream();
00065
00066 public:
00067 typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
00068 typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
00069 typedef _Self& (_STLP_CALL *__ostream_fn)(_Self&);
00070 _Self& operator<< (__ostream_fn __f) { return __f(*this); }
00071 _Self & operator<< (__ios_base_fn __f) { __f(*this); return *this; }
00072 _Self& operator<< (__ios_fn __ff) { __ff(*this); return *this; }
00073
00074 private:
00075 bool _M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
00076 basic_streambuf<_CharT, _Traits>* __to);
00077 bool _M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
00078 basic_streambuf<_CharT, _Traits>* __to);
00079
00080 public:
00081 void _M_put_char(_CharT __c);
00082
00083 void _M_put_nowiden(const _CharT* __s);
00084 void _M_put_widen(const char* __s);
00085 bool _M_put_widen_aux(const char* __s, streamsize __n);
00086
00087 public:
00088 _Self& put(char_type __c);
00089 _Self& write(const char_type* __s, streamsize __n);
00090
00091 public:
00092
00093 _Self& operator<<(basic_streambuf<_CharT, _Traits>* __buf);
00094 # ifndef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
00095
00096 _Self& operator<<(unsigned char __x) { _M_put_char(__x); return *this; }
00097 # endif
00098 _Self& operator<<(short __x) { return _M_put_num(*this, __STATIC_CAST(long,__x)); }
00099 _Self& operator<<(unsigned short __x) { return _M_put_num(*this, __STATIC_CAST(unsigned long,__x)); }
00100 _Self& operator<<(int __x) { return _M_put_num(*this, __STATIC_CAST(long,__x)); }
00101 _Self& operator<<(unsigned int __x) { return _M_put_num(*this, __STATIC_CAST(unsigned long,__x)); }
00102 _Self& operator<<(long __x) { return _M_put_num(*this, __x); }
00103 _Self& operator<<(unsigned long __x) { return _M_put_num(*this, __x); }
00104 #ifdef _STLP_LONG_LONG
00105 _Self& operator<< (_STLP_LONG_LONG __x) { return _M_put_num(*this, __x); }
00106 _Self& operator<< (unsigned _STLP_LONG_LONG __x) { return _M_put_num(*this, __x); }
00107 #endif
00108 _Self& operator<<(float __x)
00109 { return _M_put_num(*this, __STATIC_CAST(double,__x)); }
00110 _Self& operator<<(double __x) { return _M_put_num(*this, __x); }
00111 # ifndef _STLP_NO_LONG_DOUBLE
00112 _Self& operator<<(long double __x) { return _M_put_num(*this, __x); }
00113 # endif
00114 _Self& operator<<(const void* __x) { return _M_put_num(*this, __x); }
00115 # ifndef _STLP_NO_BOOL
00116 _Self& operator<<(bool __x) { return _M_put_num(*this, __x); }
00117 # endif
00118
00119 public:
00120 _Self& flush() {
00121 if (this->rdbuf())
00122 if (this->rdbuf()->pubsync() == -1)
00123 this->setstate(ios_base::badbit);
00124 return *this;
00125 }
00126
00127 pos_type tellp() {
00128 return this->rdbuf() && !this->fail()
00129 ? this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out)
00130 : pos_type(-1);
00131 }
00132
00133 _Self& seekp(pos_type __pos) {
00134 if (this->rdbuf() && !this->fail())
00135 this->rdbuf()->pubseekpos(__pos, ios_base::out);
00136 return *this;
00137 }
00138
00139 _Self& seekp(off_type __off, ios_base::seekdir __dir) {
00140 if (this->rdbuf() && !this->fail())
00141 this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
00142 return *this;
00143 }
00144
00145 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00146
00147
00148 typedef _Osentry<_CharT, _Traits> sentry;
00149 };
00150 # define sentry _Osentry
00151 template <class _CharT, class _Traits>
00152 class _Osentry {
00153 typedef _Osentry<_CharT, _Traits> _Self;
00154 # else
00155 class sentry {
00156 typedef sentry _Self;
00157 # endif
00158 private:
00159 basic_ostream<_CharT, _Traits>& _M_str;
00160
00161 bool _M_ok;
00162 public:
00163 explicit sentry(basic_ostream<_CharT, _Traits>& __str)
00164 : _M_str(__str), _M_ok(_M_init(__str))
00165 {
00166 }
00167
00168 ~sentry() {
00169 if (_M_str.flags() & ios_base::unitbuf)
00170 # ifndef _STLP_INCOMPLETE_EXCEPTION_HEADER
00171 if (!_STLP_VENDOR_EXCEPT_STD::uncaught_exception())
00172 # endif
00173 _M_str.flush();
00174 }
00175
00176 operator bool() const { return _M_ok; }
00177 private:
00178 sentry(const _Self& __s) : _M_str (__s._M_str) {};
00179 void operator=(const _Self&) {};
00180 };
00181 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00182 # undef sentry
00183 # else
00184
00185 };
00186 # endif
00187
00188 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00189 _STLP_EXPORT_TEMPLATE_CLASS basic_ostream<char, char_traits<char> >;
00190 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<char, char_traits<char> >;
00191 # if !defined (_STLP_NO_WCHAR_T)
00192 _STLP_EXPORT_TEMPLATE_CLASS basic_ostream<wchar_t, char_traits<wchar_t> >;
00193 _STLP_EXPORT_TEMPLATE_CLASS _Osentry<wchar_t, char_traits<wchar_t> >;
00194 # endif
00195 # endif
00196
00197 template <class _CharT, class _Traits>
00198 inline basic_streambuf<_CharT, _Traits>* _STLP_CALL
00199 _M_get_ostreambuf(basic_ostream<_CharT, _Traits>& __St)
00200 {
00201 return __St.rdbuf();
00202 }
00203
00204
00205
00206 template <class _CharT, class _Traits>
00207 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00208 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
00209 __os._M_put_char(__c);
00210 return __os;
00211 }
00212
00213 template <class _CharT, class _Traits>
00214 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00215 operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __s) {
00216 __os._M_put_nowiden(__s);
00217 return __os;
00218 }
00219
00220 # ifdef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
00221
00222
00223 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00224 operator<<(basic_ostream<char, char_traits<char> >& __os, char __c) {
00225 __os._M_put_char(__c);
00226 return __os;
00227 }
00228
00229 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00230 operator<<(basic_ostream<char, char_traits<char> >& __os, signed char __c) {
00231 __os._M_put_char(__c);
00232 return __os;
00233 }
00234
00235 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00236 operator<<(basic_ostream<char, char_traits<char> >& __os, unsigned char __c) {
00237 __os._M_put_char(__c);
00238 return __os;
00239 }
00240
00241 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00242 operator<<(basic_ostream<char, char_traits<char> >& __os, const char* __s) {
00243 __os._M_put_nowiden(__s);
00244 return __os;
00245 }
00246
00247 inline basic_ostream<char, char_traits<char> >& _STLP_CALL
00248 operator<<(basic_ostream<char, char_traits<char> >& __os, const signed char* __s) {
00249 __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00250 return __os;
00251 }
00252
00253 inline basic_ostream<char, char_traits<char> >&
00254 operator<<(basic_ostream<char, char_traits<char> >& __os, const unsigned char* __s) {
00255 __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00256 return __os;
00257 }
00258
00259 # else
00260
00261
00262 template <class _CharT, class _Traits>
00263 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00264 operator<<(basic_ostream<_CharT, _Traits>& __os, char __c) {
00265 __os._M_put_char(__os.widen(__c));
00266 return __os;
00267 }
00268
00269 template <class _Traits>
00270 inline basic_ostream<char, _Traits>& _STLP_CALL
00271 operator<<(basic_ostream<char, _Traits>& __os, char __c) {
00272 __os._M_put_char(__c);
00273 return __os;
00274 }
00275
00276 template <class _Traits>
00277 inline basic_ostream<char, _Traits>& _STLP_CALL
00278 operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
00279 __os._M_put_char(__c);
00280 return __os;
00281 }
00282
00283 template <class _Traits>
00284 inline basic_ostream<char, _Traits>& _STLP_CALL
00285 operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
00286 __os._M_put_char(__c);
00287 return __os;
00288 }
00289
00290 template <class _CharT, class _Traits>
00291 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00292 operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __s) {
00293 __os._M_put_widen(__s);
00294 return __os;
00295 }
00296
00297 template <class _Traits>
00298 inline basic_ostream<char, _Traits>& _STLP_CALL
00299 operator<<(basic_ostream<char, _Traits>& __os, const char* __s) {
00300 __os._M_put_nowiden(__s);
00301 return __os;
00302 }
00303
00304 template <class _Traits>
00305 inline basic_ostream<char, _Traits>& _STLP_CALL
00306 operator<<(basic_ostream<char, _Traits>& __os, const signed char* __s) {
00307 __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00308 return __os;
00309 }
00310
00311 template <class _Traits>
00312 inline basic_ostream<char, _Traits>&
00313 operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __s) {
00314 __os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
00315 return __os;
00316 }
00317 # endif
00318
00319
00320
00321
00322 template <class _CharT, class _Traits>
00323 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00324 endl(basic_ostream<_CharT, _Traits>& __os) {
00325 __os.put(__os.widen('\n'));
00326 __os.flush();
00327 return __os;
00328 }
00329
00330 template <class _CharT, class _Traits>
00331 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00332 ends(basic_ostream<_CharT, _Traits>& __os) {
00333 __os.put(_STLP_DEFAULT_CONSTRUCTED(_CharT));
00334 return __os;
00335 }
00336
00337 template <class _CharT, class _Traits>
00338 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00339 flush(basic_ostream<_CharT, _Traits>& __os) {
00340 __os.flush();
00341 return __os;
00342 }
00343
00344 _STLP_END_NAMESPACE
00345
00346 # undef _STLP_MANIP_INLINE
00347
00348 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
00349 # include <stl/_ostream.c>
00350 # endif
00351
00352 #endif
00353
00354
00355
00356