1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_ostream.c Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_ostream.c Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,75 +1,52 @@
1.4 /*
1.5 - * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.6 - *
1.7 * Copyright (c) 1999
1.8 * Silicon Graphics Computer Systems, Inc.
1.9 *
1.10 - * Copyright (c) 1999
1.11 + * Copyright (c) 1999
1.12 * Boris Fomitchev
1.13 *
1.14 * This material is provided "as is", with absolutely no warranty expressed
1.15 * or implied. Any use is at your own risk.
1.16 *
1.17 - * Permission to use or copy this software for any purpose is hereby granted
1.18 + * Permission to use or copy this software for any purpose is hereby granted
1.19 * without fee, provided the above notices are retained on all copies.
1.20 * Permission to modify the code and to distribute modified code is granted,
1.21 * provided the above notices are retained, and a notice that the code was
1.22 * modified is included with the above copyright notice.
1.23 *
1.24 - */
1.25 + */
1.26 #ifndef _STLP_OSTREAM_C
1.27 #define _STLP_OSTREAM_C
1.28
1.29 -
1.30 #ifndef _STLP_INTERNAL_OSTREAM_H
1.31 -# include <stl/_ostream.h>
1.32 +# include <stl/_ostream.h>
1.33 #endif
1.34
1.35 -#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
1.36 -
1.37 #if !defined (_STLP_INTERNAL_NUM_PUT_H)
1.38 -# include <stl/_num_put.h> // For basic_streambuf and iterators
1.39 +# include <stl/_num_put.h> // For basic_streambuf and iterators
1.40 #endif
1.41
1.42 _STLP_BEGIN_NAMESPACE
1.43
1.44 -// Helper functions for istream<>::sentry constructor.
1.45 -template <class _CharT, class _Traits>
1.46 -bool
1.47 -_M_init(basic_ostream<_CharT, _Traits>& __str) {
1.48 - if (__str.good()) {
1.49 - // boris : check if this is needed !
1.50 - if (!__str.rdbuf())
1.51 - __str.setstate(ios_base::badbit);
1.52 - if (__str.tie())
1.53 - __str.tie()->flush();
1.54 - return __str.good();
1.55 - } else
1.56 - return false;
1.57 -}
1.58 -
1.59 //----------------------------------------------------------------------
1.60 // Definitions of non-inline member functions.
1.61
1.62 // Constructor, destructor
1.63
1.64 template <class _CharT, class _Traits>
1.65 -_STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>
1.66 - ::basic_ostream(basic_streambuf<_CharT, _Traits>* __buf)
1.67 - : basic_ios<_CharT, _Traits>()
1.68 -{
1.69 +basic_ostream<_CharT, _Traits>::basic_ostream(basic_streambuf<_CharT, _Traits>* __buf)
1.70 + : basic_ios<_CharT, _Traits>() {
1.71 this->init(__buf);
1.72 }
1.73
1.74 template <class _CharT, class _Traits>
1.75 -_STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>::~basic_ostream()
1.76 +basic_ostream<_CharT, _Traits>::~basic_ostream()
1.77 {}
1.78
1.79 // Output directly from a streambuf.
1.80 template <class _CharT, class _Traits>
1.81 -_STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>&
1.82 -basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<_CharT, _Traits>* __from)
1.83 -{
1.84 +basic_ostream<_CharT, _Traits>&
1.85 +basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<_CharT, _Traits>* __from) {
1.86 sentry __sentry(*this);
1.87 if (__sentry) {
1.88 if (__from) {
1.89 @@ -94,8 +71,7 @@
1.90 template <class _CharT, class _Traits>
1.91 bool basic_ostream<_CharT, _Traits>
1.92 ::_M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
1.93 - basic_streambuf<_CharT, _Traits>* __to)
1.94 -{
1.95 + basic_streambuf<_CharT, _Traits>* __to) {
1.96 bool __any_inserted = false;
1.97
1.98 while (__from->egptr() != __from->gptr()) {
1.99 @@ -123,10 +99,8 @@
1.100 return false;
1.101 }
1.102 }
1.103 -
1.104 else if (__nwritten != 0)
1.105 return true;
1.106 -
1.107 else
1.108 return __any_inserted;
1.109 }
1.110 @@ -136,107 +110,87 @@
1.111 return __any_inserted || this->_M_copy_unbuffered(__from, __to);
1.112 }
1.113
1.114 +/*
1.115 + * Helper struct (guard) to put back a character in a streambuf
1.116 + * whenever an exception or an eof occur.
1.117 + */
1.118 +template <class _CharT, class _Traits>
1.119 +struct _SPutBackC {
1.120 + typedef basic_streambuf<_CharT, _Traits> _StreamBuf;
1.121 + typedef typename _StreamBuf::int_type int_type;
1.122 + _SPutBackC(_StreamBuf *pfrom)
1.123 + : __pfrom(pfrom), __c(0), __do_guard(false) {}
1.124 + ~_SPutBackC() {
1.125 + if (__do_guard) {
1.126 + __pfrom->sputbackc(_Traits::to_char_type(__c));
1.127 + }
1.128 + }
1.129 +
1.130 + void guard(int_type c) {
1.131 + __c = c;
1.132 + __do_guard = true;
1.133 + }
1.134 + void release() {
1.135 + __do_guard = false;
1.136 + }
1.137 +
1.138 +private:
1.139 + _StreamBuf *__pfrom;
1.140 + int_type __c;
1.141 + bool __do_guard;
1.142 +};
1.143 +
1.144 template <class _CharT, class _Traits>
1.145 bool basic_ostream<_CharT, _Traits>
1.146 ::_M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
1.147 - basic_streambuf<_CharT, _Traits>* __to)
1.148 -{
1.149 + basic_streambuf<_CharT, _Traits>* __to) {
1.150 + typedef _SPutBackC<_CharT, _Traits> _SPutBackCGuard;
1.151 bool __any_inserted = false;
1.152 + int_type __c;
1.153
1.154 -#ifdef __SYMBIAN32__
1.155 - int_type __c;
1.156 - _STLP_TRY {
1.157 - __c = __from->sgetc();;
1.158 - }
1.159 - _STLP_CATCH_ALL {
1.160 - this->_M_handle_exception(ios_base::failbit);
1.161 - return __any_inserted;
1.162 - }
1.163 - for(;;){
1.164 -
1.165 - if (this->_S_eof(__c))
1.166 - return __any_inserted;
1.167 -
1.168 - else {
1.169 - int_type __tmp;
1.170 + _STLP_TRY {
1.171 + _SPutBackCGuard __cguard(__from);
1.172 + for (;;) {
1.173 _STLP_TRY {
1.174 - __tmp = __to->sputc(__c);
1.175 + __c = __from->sbumpc();
1.176 }
1.177 _STLP_CATCH_ALL {
1.178 - this->_M_handle_exception(ios_base::badbit);
1.179 + this->_M_handle_exception(ios_base::failbit);
1.180 return __any_inserted;
1.181 }
1.182
1.183 - if (this->_S_eof(__tmp)) {
1.184 - break;
1.185 - }
1.186 - else
1.187 - __any_inserted = true;
1.188 - }
1.189 - _STLP_TRY {
1.190 - __c = __from->snextc();
1.191 - }
1.192 - _STLP_CATCH_ALL {
1.193 - this->_M_handle_exception(ios_base::failbit);
1.194 - return __any_inserted;
1.195 - }
1.196 - }
1.197 -#else
1.198 - while (true) {
1.199 - int_type __c;
1.200 - _STLP_TRY {
1.201 - __c = __from->sbumpc();
1.202 - }
1.203 - _STLP_CATCH_ALL {
1.204 - this->_M_handle_exception(ios_base::failbit);
1.205 - return __any_inserted;
1.206 - }
1.207 + if ( this->_S_eof(__c) )
1.208 + return __any_inserted;
1.209
1.210 - if (this->_S_eof(__c))
1.211 - return __any_inserted;
1.212 -
1.213 - else {
1.214 - int_type __tmp;
1.215 - _STLP_TRY {
1.216 - __tmp = __to->sputc(__c);
1.217 - }
1.218 - _STLP_CATCH_ALL {
1.219 - this->_M_handle_exception(ios_base::badbit);
1.220 + __cguard.guard(__c);
1.221 + if ( this->_S_eof( __to->sputc(_Traits::to_char_type(__c)) ) ) {
1.222 return __any_inserted;
1.223 }
1.224
1.225 - if (this->_S_eof(__tmp)) {
1.226 - _STLP_TRY {
1.227 - /* __tmp = */ __from->sputbackc(__c);
1.228 - }
1.229 - _STLP_CATCH_ALL {
1.230 - this->_M_handle_exception(ios_base::badbit);
1.231 - return __any_inserted;
1.232 - }
1.233 - }
1.234 - else
1.235 - __any_inserted = true;
1.236 + __cguard.release();
1.237 + __any_inserted = true;
1.238 }
1.239 }
1.240 -#endif
1.241 - return __any_inserted;
1.242 + _STLP_CATCH_ALL {
1.243 + this->_M_handle_exception(ios_base::badbit);
1.244 + return __any_inserted;
1.245 + }
1.246 }
1.247
1.248 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.249 +
1.250 // Helper function for numeric output.
1.251 -
1.252 template <class _CharT, class _Traits, class _Number>
1.253 basic_ostream<_CharT, _Traits>& _STLP_CALL
1.254 -_M_put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x)
1.255 -{
1.256 +__put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x) {
1.257 typedef typename basic_ostream<_CharT, _Traits>::sentry _Sentry;
1.258 _Sentry __sentry(__os);
1.259 bool __failed = true;
1.260
1.261 if (__sentry) {
1.262 _STLP_TRY {
1.263 - typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> > _NumPut;
1.264 - __failed = (use_facet<_NumPut>(__os.getloc())).put(
1.265 - ostreambuf_iterator<_CharT, _Traits>(__os.rdbuf()),
1.266 + typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> > _NumPut;
1.267 + __failed = (use_facet<_NumPut>(__os.getloc())).put(ostreambuf_iterator<_CharT, _Traits>(__os.rdbuf()),
1.268 __os, __os.fill(),
1.269 __x).failed();
1.270 }
1.271 @@ -245,26 +199,96 @@
1.272 }
1.273 }
1.274 if (__failed)
1.275 - __os.setstate(ios_base::badbit);
1.276 + __os.setstate(ios_base::badbit);
1.277 return __os;
1.278 }
1.279
1.280 -# if defined (_STLP_USE_TEMPLATE_EXPORT) && defined (__BUILDING_STLPORT)
1.281 -_STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
1.282 -_M_put_num(basic_ostream<char, char_traits<char> >&, unsigned long);
1.283 -_STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
1.284 -_M_put_num(basic_ostream<char, char_traits<char> >&, long);
1.285 -# if defined (_STLP_LONG_LONG)
1.286 -_STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
1.287 -_M_put_num(basic_ostream<char, char_traits<char> >&, unsigned _STLP_LONG_LONG);
1.288 -_STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
1.289 -_M_put_num(basic_ostream<char, char_traits<char> >&, _STLP_LONG_LONG );
1.290 -# endif
1.291 -# endif
1.292 +_STLP_MOVE_TO_STD_NAMESPACE
1.293 +
1.294 +/*
1.295 + * In the following operators we try to limit code bloat by limiting the
1.296 + * number of __put_num instanciations.
1.297 + */
1.298 +template <class _CharT, class _Traits>
1.299 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(short __x) {
1.300 + _STLP_STATIC_ASSERT( sizeof(short) <= sizeof(long) )
1.301 + long __tmp = ((this->flags() & _Basic_ios::basefield) != ios_base::dec) ?
1.302 + __STATIC_CAST(long, __STATIC_CAST(unsigned short, __x)): __x;
1.303 + return _STLP_PRIV __put_num(*this, __tmp);
1.304 +}
1.305
1.306 template <class _CharT, class _Traits>
1.307 -void basic_ostream<_CharT, _Traits>::_M_put_char(_CharT __c)
1.308 -{
1.309 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned short __x) {
1.310 + _STLP_STATIC_ASSERT( sizeof(unsigned short) <= sizeof(unsigned long) )
1.311 + return _STLP_PRIV __put_num(*this, __STATIC_CAST(unsigned long,__x));
1.312 +}
1.313 +
1.314 +template <class _CharT, class _Traits>
1.315 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(int __x) {
1.316 + _STLP_STATIC_ASSERT( sizeof(int) <= sizeof(long) )
1.317 + long __tmp = ((this->flags() & _Basic_ios::basefield) != ios_base::dec) ?
1.318 + __STATIC_CAST(long, __STATIC_CAST(unsigned int, __x)): __x;
1.319 + return _STLP_PRIV __put_num(*this, __tmp);
1.320 +}
1.321 +
1.322 +template <class _CharT, class _Traits>
1.323 +#if defined (_WIN64) || !defined (_STLP_MSVC) || (_STLP_MSVC < 1300)
1.324 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned int __x) {
1.325 + _STLP_STATIC_ASSERT( sizeof(unsigned int) <= sizeof(unsigned long) )
1.326 +#else
1.327 +/* We define this operator with size_t rather than unsigned int to avoid
1.328 + * 64 bits warning.
1.329 + */
1.330 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(size_t __x) {
1.331 + _STLP_STATIC_ASSERT( sizeof(size_t) <= sizeof(unsigned long) )
1.332 +#endif
1.333 + return _STLP_PRIV __put_num(*this, __STATIC_CAST(unsigned long,__x));
1.334 +}
1.335 +
1.336 +template <class _CharT, class _Traits>
1.337 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __x)
1.338 +{ return _STLP_PRIV __put_num(*this, __x); }
1.339 +
1.340 +template <class _CharT, class _Traits>
1.341 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(unsigned long __x)
1.342 +{ return _STLP_PRIV __put_num(*this, __x); }
1.343 +
1.344 +#ifdef _STLP_LONG_LONG
1.345 +template <class _CharT, class _Traits>
1.346 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<< (_STLP_LONG_LONG __x)
1.347 +{ return _STLP_PRIV __put_num(*this, __x); }
1.348 +
1.349 +template <class _CharT, class _Traits>
1.350 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<< (unsigned _STLP_LONG_LONG __x)
1.351 +{ return _STLP_PRIV __put_num(*this, __x); }
1.352 +#endif
1.353 +
1.354 +template <class _CharT, class _Traits>
1.355 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(float __x)
1.356 +{ return _STLP_PRIV __put_num(*this, __STATIC_CAST(double,__x)); }
1.357 +
1.358 +template <class _CharT, class _Traits>
1.359 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(double __x)
1.360 +{ return _STLP_PRIV __put_num(*this, __x); }
1.361 +
1.362 +#ifndef _STLP_NO_LONG_DOUBLE
1.363 +template <class _CharT, class _Traits>
1.364 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long double __x)
1.365 +{ return _STLP_PRIV __put_num(*this, __x); }
1.366 +#endif
1.367 +
1.368 +template <class _CharT, class _Traits>
1.369 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(const void* __x)
1.370 +{ return _STLP_PRIV __put_num(*this, __x); }
1.371 +
1.372 +#ifndef _STLP_NO_BOOL
1.373 +template <class _CharT, class _Traits>
1.374 +basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(bool __x)
1.375 +{ return _STLP_PRIV __put_num(*this, __x); }
1.376 +#endif
1.377 +
1.378 +template <class _CharT, class _Traits>
1.379 +void basic_ostream<_CharT, _Traits>::_M_put_char(_CharT __c) {
1.380 sentry __sentry(*this);
1.381 if (__sentry) {
1.382 bool __failed = true;
1.383 @@ -275,7 +299,7 @@
1.384 __failed = this->_S_eof(this->rdbuf()->sputc(__c));
1.385 else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
1.386 __failed = this->_S_eof(this->rdbuf()->sputc(__c));
1.387 - __failed = __failed ||
1.388 + __failed = __failed ||
1.389 this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
1.390 }
1.391 else {
1.392 @@ -295,8 +319,7 @@
1.393 }
1.394
1.395 template <class _CharT, class _Traits>
1.396 -void basic_ostream<_CharT, _Traits>::_M_put_nowiden(const _CharT* __s)
1.397 -{
1.398 +void basic_ostream<_CharT, _Traits>::_M_put_nowiden(const _CharT* __s) {
1.399 sentry __sentry(*this);
1.400 if (__sentry) {
1.401 bool __failed = true;
1.402 @@ -308,7 +331,7 @@
1.403 __failed = this->rdbuf()->sputn(__s, __n) != __n;
1.404 else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
1.405 __failed = this->rdbuf()->sputn(__s, __n) != __n;
1.406 - __failed = __failed ||
1.407 + __failed = __failed ||
1.408 this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
1.409 }
1.410 else {
1.411 @@ -328,8 +351,7 @@
1.412 }
1.413
1.414 template <class _CharT, class _Traits>
1.415 -void basic_ostream<_CharT, _Traits>::_M_put_widen(const char* __s)
1.416 -{
1.417 +void basic_ostream<_CharT, _Traits>::_M_put_widen(const char* __s) {
1.418 sentry __sentry(*this);
1.419 if (__sentry) {
1.420 bool __failed = true;
1.421 @@ -341,7 +363,7 @@
1.422 __failed = !this->_M_put_widen_aux(__s, __n);
1.423 else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
1.424 __failed = !this->_M_put_widen_aux(__s, __n);
1.425 - __failed = __failed ||
1.426 + __failed = __failed ||
1.427 this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
1.428 }
1.429 else {
1.430 @@ -362,8 +384,7 @@
1.431
1.432 template <class _CharT, class _Traits>
1.433 bool basic_ostream<_CharT, _Traits>::_M_put_widen_aux(const char* __s,
1.434 - streamsize __n)
1.435 -{
1.436 + streamsize __n) {
1.437 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.438
1.439 for ( ; __n > 0 ; --__n)
1.440 @@ -374,9 +395,8 @@
1.441
1.442 // Unformatted output of a single character.
1.443 template <class _CharT, class _Traits>
1.444 -_STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>&
1.445 -basic_ostream<_CharT, _Traits>::put(char_type __c)
1.446 -{
1.447 +basic_ostream<_CharT, _Traits>&
1.448 +basic_ostream<_CharT, _Traits>::put(char_type __c) {
1.449 sentry __sentry(*this);
1.450 bool __failed = true;
1.451
1.452 @@ -397,9 +417,8 @@
1.453
1.454 // Unformatted output of a single character.
1.455 template <class _CharT, class _Traits>
1.456 -_STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>&
1.457 -basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
1.458 -{
1.459 +basic_ostream<_CharT, _Traits>&
1.460 +basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n) {
1.461 sentry __sentry(*this);
1.462 bool __failed = true;
1.463
1.464 @@ -420,6 +439,8 @@
1.465
1.466 _STLP_END_NAMESPACE
1.467
1.468 -#endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
1.469 +#endif /* _STLP_OSTREAM_C */
1.470
1.471 -#endif /* _STLP_OSTREAM_C */
1.472 +// Local Variables:
1.473 +// mode:C++
1.474 +// End: