diff -r e1b950c65cb4 -r 837f303aceeb epoc32/include/stdapis/stlportv5/stl/_istream.c --- a/epoc32/include/stdapis/stlportv5/stl/_istream.c Wed Mar 31 12:27:01 2010 +0100 +++ b/epoc32/include/stdapis/stlportv5/stl/_istream.c Wed Mar 31 12:33:34 2010 +0100 @@ -1,5 +1,4 @@ /* - * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. * Copyright (c) 1999 * Silicon Graphics Computer Systems, Inc. * @@ -19,36 +18,36 @@ #ifndef _STLP_ISTREAM_C #define _STLP_ISTREAM_C -#ifndef _STLP_INTERNAL_ISTREAM_H -# include +#ifndef _STLP_INTERNAL_ISTREAM +# include #endif -# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) - -#ifndef _STLP_LIMITS_H -# include +#ifndef _STLP_INTERNAL_LIMITS +# include #endif #ifndef _STLP_INTERNAL_NUM_GET_H -# include +# include #endif -# if defined ( _STLP_NESTED_TYPE_PARAM_BUG ) +#if defined ( _STLP_NESTED_TYPE_PARAM_BUG ) // no wchar_t is supported for this mode -# define __BIS_int_type__ int -# define __BIS_pos_type__ streampos -# define __BIS_off_type__ streamoff -# else -# define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type -# define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type -# define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type -# endif +# define __BIS_int_type__ int +# define __BIS_pos_type__ streampos +# define __BIS_off_type__ streamoff +#else +# define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type +# define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type +# define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type +#endif _STLP_BEGIN_NAMESPACE //---------------------------------------------------------------------- // Function object structs used by some member functions. +_STLP_MOVE_TO_PRIV_NAMESPACE + template struct _Is_not_wspace { typedef typename _Traits::char_type argument_type; @@ -126,8 +125,7 @@ }; template -struct _Scan_for_char_val -{ +struct _Scan_for_char_val { typedef typename _Traits::char_type char_type; typedef char_type* first_argument_type; typedef char_type* second_argument_type; @@ -144,8 +142,7 @@ }; template -struct _Scan_for_int_val -{ +struct _Scan_for_int_val { typedef typename _Traits::char_type char_type; typedef typename _Traits::int_type int_type; typedef char_type* first_argument_type; @@ -168,8 +165,7 @@ template bool _STLP_CALL -__pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c) -{ +__pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c) { bool ret; _STLP_TRY { const typename _Traits::int_type __eof = _Traits::eof(); @@ -181,58 +177,13 @@ return ret; } -template -basic_istream<_CharT, _Traits>& _STLP_CALL -ws(basic_istream<_CharT, _Traits>& __is) -{ - typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry; - _Sentry __sentry(__is, _No_Skip_WS()); // Don't skip whitespace. - if (__sentry) - __is._M_skip_whitespace(false); - return __is; -} - -// Helper functions for istream<>::sentry constructor. -template -bool -_M_init_skip(basic_istream<_CharT, _Traits>& __is) { - if (__is.good()) { - if (__is.tie()) - __is.tie()->flush(); - - __is._M_skip_whitespace(true); - } - - if (!__is.good()) { - __is.setstate(ios_base::failbit); - return false; - } else - return true; -} - -template -bool -_M_init_noskip(basic_istream<_CharT, _Traits>& __is){ - if (__is.good()) { - if (__is.tie()) - __is.tie()->flush(); - - if (!__is.rdbuf()) - __is.setstate(ios_base::badbit); - } - else - __is.setstate(ios_base::failbit); - return __is.good(); -} - //---------------------------------------------------------------------- // Definitions of basic_istream<>'s noninline member functions. // Helper function for formatted input of numbers. template ios_base::iostate _STLP_CALL -_M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val) -{ +__get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val) { typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry; ios_base::iostate __err = 0; _Sentry __sentry( __that ); // Skip whitespace. @@ -240,7 +191,7 @@ typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > _Num_get; _STLP_TRY { ((const _Num_get&)use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()), - 0, __that, __err, __val); + 0, __that, __err, __val); } _STLP_CATCH_ALL { __that._M_handle_exception(ios_base::badbit); @@ -250,13 +201,117 @@ return __err; } +_STLP_MOVE_TO_STD_NAMESPACE + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (short& __val) { + long __lval; + _STLP_PRIV __get_num(*this, __lval); + if ( this->fail() ) { + return *this; + } + short __tmp = __STATIC_CAST(short, __lval); + unsigned short __uval = __STATIC_CAST(unsigned short, __lval); + // check if we lose digits + // if ((__val != __lval) && ((unsigned short)__val != __lval)) + if ((__tmp != __lval) && ((long)__uval != __lval)) + this->setstate(ios_base::failbit); + else + __val = __tmp; + return *this; +} + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (int& __val) { + long __lval; + _STLP_PRIV __get_num(*this, __lval); + if ( this->fail() ) { + return *this; + } + int __tmp = __lval; + unsigned int __uval = __lval; + // check if we lose digits + // if ((__val != __lval) && ((unsigned int)__val != __lval)) + if ((__tmp != __lval) && ((long)__uval != __lval)) + this->setstate(ios_base::failbit); + else + __val = __tmp; + return *this; +} + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned short& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned int& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (long& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned long& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} + +#if defined (_STLP_LONG_LONG) +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (_STLP_LONG_LONG& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned _STLP_LONG_LONG& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} +#endif +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (float& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (double& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} +#if !defined (_STLP_NO_LONG_DOUBLE) +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (long double& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} +#endif +#if !defined (_STLP_NO_BOOL) +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (bool& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} +#endif + +template +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (void*& __val) { + _STLP_PRIV __get_num(*this, __val); + return *this; +} // Unformatted input template __BIS_int_type__ -basic_istream<_CharT, _Traits>::peek() -{ +basic_istream<_CharT, _Traits>::peek() { typename _Traits::int_type __tmp = _Traits::eof(); this->_M_gcount = 0; @@ -269,23 +324,17 @@ _STLP_CATCH_ALL { this->_M_handle_exception(ios_base::badbit); } + if (this->_S_eof(__tmp)) + this->setstate(ios_base::eofbit); } - else - { - if (this->_S_eof(__tmp)) - { - this->clear(); - this->setstate(ios_base::eofbit); - } - } + return __tmp; } template __BIS_int_type__ -basic_istream<_CharT, _Traits>::get() -{ +basic_istream<_CharT, _Traits>::get() { typename _Traits::int_type __tmp = _Traits::eof(); sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; @@ -310,8 +359,7 @@ template basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::get(_CharT& __c) -{ +basic_istream<_CharT, _Traits>::get(_CharT& __c) { sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; @@ -337,14 +385,12 @@ } - // Read characters and discard them. The standard specifies a single // function with two arguments, each with a default. We instead use // three overloded functions, because it's possible to implement the // first two more efficiently than the fully general third version. template -basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore() -{ +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore() { sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; @@ -407,13 +453,7 @@ // if (!__buf || _Traits::eq_int_type(__buf->sungetc(), _Traits::eof())) if (__buf) { _STLP_TRY { - _CharT __tmp; - __tmp = __buf->sungetc(); -#ifdef __SYMBIAN32__ - if (__tmp == (_CharT)-1) //chek for eof -#else - if (this->_S_eof(__tmp)) -#endif + if (this->_S_eof(__buf->sungetc())) this->setstate(ios_base::badbit); } _STLP_CATCH_ALL { @@ -450,9 +490,8 @@ template __BIS_pos_type__ basic_istream<_CharT, _Traits>::tellg() { -#ifndef __SYMBIAN32__ sentry __sentry(*this, _No_Skip_WS()); -#endif + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); return (__buf && !this->fail()) ? __buf->pubseekoff(0, ios_base::cur, ios_base::in) : pos_type(-1); @@ -461,48 +500,38 @@ template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type __pos) { -#ifndef __SYMBIAN32__ sentry __sentry(*this, _No_Skip_WS()); -#endif + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); - if (!this->fail() && __buf) - { - pos_type pos = __buf->pubseekpos(__pos, ios_base::in); - if(pos == pos_type(off_type(-1))) - this->setstate(ios_base::failbit); + if (!this->fail() && __buf) { + if (__buf->pubseekpos(__pos) == pos_type(-1)) { + this->setstate(ios_base::failbit); + } } return *this; } template basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) -{ -#ifndef __SYMBIAN32__ +basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) { sentry __sentry(*this, _No_Skip_WS()); -#endif + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); if (!this->fail() && __buf) - { - - pos_type pos = __buf->pubseekoff(__off, __dir, ios_base::in); - if(pos == pos_type(off_type(-1))) - this->setstate(ios_base::failbit); - } + __buf->pubseekoff(__off, __dir); return *this; } // Formatted input of characters and character arrays. template -void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c) -{ +void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c) { // typename _Traits::int_type __tmp = _Traits::eof(); sentry __sentry(*this); // Skip whitespace. if (__sentry) { - typename _Traits::int_type __tmp = _Traits::eof(); + typename _Traits::int_type __tmp;// = _Traits::eof(); _STLP_TRY { __tmp = this->rdbuf()->sbumpc(); @@ -541,87 +570,48 @@ // delimiter if it is extracted. Note that the number of characaters // extracted isn't necessarily the same as the number stored. +_STLP_MOVE_TO_PRIV_NAMESPACE + template < class _CharT, class _Traits, class _Is_Delim> streamsize _STLP_CALL -_M_read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf, - streamsize _Num, _CharT* __s, - _Is_Delim __is_delim, - bool __extract_delim, bool __append_null, - bool __is_getline) -{ +__read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf, + streamsize _Num, _CharT* __s, + _Is_Delim __is_delim, + bool __extract_delim, bool __append_null, + bool __is_getline) { streamsize __n = 0; ios_base::iostate __status = 0; typedef typename basic_istream<_CharT, _Traits>::int_type int_type; // The operations that can potentially throw are sbumpc, snextc, and sgetc. _STLP_TRY { -# if 0 - int_type __c = __buf->sgetc(); - while (true) { + for (;;) { + int_type __c = __buf->sbumpc(); // sschwarz + if (__that->_S_eof(__c)) { if (__n < _Num || __is_getline) __status |= ios_base::eofbit; break; } - - else if (__is_delim(__c)) { - if (__extract_delim) { // Extract and discard current character. - __buf->sbumpc(); + else if (__is_delim(_Traits::to_char_type(__c))) { + if (__extract_delim) { // Extract and discard current character. ++__n; + } else if ( !__pushback(__buf, _Traits::to_char_type(__c)) ) { // leave delimiter + __status |= ios_base::failbit; } break; } + else { // regular character + *__s++ = _Traits::to_char_type(__c); + ++__n; + } - else if (__n == _Num) { - if (__is_getline) + if (__n == _Num) { + if (__is_getline) // didn't find delimiter as one of the _Num chars __status |= ios_base::failbit; break; } - - *__s++ = _Traits::to_char_type(__c); - ++__n; - __c = __buf->snextc(); } -# else -// int_type __c = __buf->sbumpc(); // __buf->sgetc(); -while (true) { - -int_type __c = __buf->sbumpc(); // sschwarz - -if (__that->_S_eof(__c)) { -if (__n < _Num || __is_getline) -__status |= ios_base::eofbit; -break; -} - -else if (__is_delim(__c)) { -if (__extract_delim) { // Extract and discard current character. -// __buf->sbumpc(); -++__n; -} -break; -} - -else { // regular character - -*__s++ = _Traits::to_char_type(__c); -++__n; - -} - -if (__n == _Num) { -if (__is_getline) // didn't find delimiter as one of the _Num chars -__status |= ios_base::failbit; -break; -} - -// *__s++ = _Traits::to_char_type(__c); -// ++__n; - -} - -# endif - } _STLP_CATCH_ALL { __that->_M_handle_exception(ios_base::badbit); @@ -636,18 +626,17 @@ return __n; } -// Much like _M_read_unbuffered, but with one additional function object: +// Much like __read_unbuffered, but with one additional function object: // __scan_delim(first, last) returns the first pointer p in [first, last) // such that __is_delim(p) is true. template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim> streamsize _STLP_CALL -_M_read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf, - streamsize _Num, _CharT* __s, - _Is_Delim __is_delim, _Scan_Delim __scan_delim, - bool __extract_delim, bool __append_null, - bool __is_getline) -{ +__read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf, + streamsize _Num, _CharT* __s, + _Is_Delim __is_delim, _Scan_Delim __scan_delim, + bool __extract_delim, bool __append_null, + bool __is_getline) { streamsize __n = 0; ios_base::iostate __status = 0; bool __done = false; @@ -656,7 +645,11 @@ while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) { const _CharT* __first = __buf->_M_gptr(); const _CharT* __last = __buf->_M_egptr(); - ptrdiff_t __request = _Num - __n; + //casting numeric_limits::max to streamsize only works is ptrdiff_t is signed or streamsize representation + //is larger than ptrdiff_t one. + _STLP_STATIC_ASSERT((sizeof(streamsize) > sizeof(ptrdiff_t)) || + (sizeof(streamsize) == sizeof(ptrdiff_t)) && numeric_limits::is_signed) + ptrdiff_t __request = __STATIC_CAST(ptrdiff_t, (min) (__STATIC_CAST(streamsize, (numeric_limits::max)()), _Num - __n)); const _CharT* __p = __scan_delim(__first, __last); ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request); @@ -675,7 +668,7 @@ } // We terminated by reading all the characters we were asked for. - else if(__n == _Num) { + else if (__n == _Num) { // Find out if we have reached eof. This matters for getline. if (__is_getline) { @@ -692,7 +685,7 @@ // The buffer contained fewer than _Num - __n characters. Either we're // at eof, or we should refill the buffer and try again. else { - if (__that->_S_eof(__buf->sgetc())) { + if (__that->_S_eof(__buf->sgetc())) { __status |= ios_base::eofbit; __done = true; } @@ -715,14 +708,13 @@ // If execution has reached this point, then we have an empty buffer but // we have not reached eof. What that means is that the streambuf has // decided to switch from buffered to unbuffered input. We switch to - // to _M_read_unbuffered. + // to __read_unbuffered. - return __n + _M_read_unbuffered(__that, __buf, _Num - __n, __s, __is_delim, - __extract_delim,__append_null,__is_getline); + return __n + __read_unbuffered(__that, __buf, _Num - __n, __s, __is_delim, + __extract_delim,__append_null,__is_getline); } - - +_STLP_MOVE_TO_STD_NAMESPACE template basic_istream<_CharT, _Traits>& @@ -737,20 +729,18 @@ if (__buf->egptr() != __buf->gptr()) this->_M_gcount = - _M_read_buffered(this, __buf, __n - 1, __s, - _Eq_char_bound<_Traits>(__delim), - _Scan_for_char_val<_Traits>(__delim), - false, true, false); + _STLP_PRIV __read_buffered(this, __buf, __n - 1, __s, + _STLP_PRIV _Eq_char_bound<_Traits>(__delim), + _STLP_PRIV _Scan_for_char_val<_Traits>(__delim), + false, true, false); else this->_M_gcount = - _M_read_unbuffered(this, __buf, __n - 1, __s, - _Eq_char_bound<_Traits>(__delim), - false, true, false); + _STLP_PRIV __read_unbuffered(this, __buf, __n - 1, __s, + _STLP_PRIV _Eq_char_bound<_Traits>(__delim), + false, true, false); } } -#ifdef __SYMBIAN32__ - *(__s + this->_M_gcount) = _STLP_DEFAULT_CONSTRUCTED(_CharT); -#endif //__SYMBIAN32__ + if (this->_M_gcount == 0) this->setstate(ios_base::failbit); @@ -770,13 +760,13 @@ if (__n > 0) { basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); this->_M_gcount = __buf->egptr() != __buf->gptr() - ? _M_read_buffered(this, __buf, __n - 1, __s, - _Eq_char_bound<_Traits>(__delim), - _Scan_for_char_val<_Traits>(__delim), - true, true, true) - : _M_read_unbuffered(this, __buf, __n - 1, __s, - _Eq_char_bound<_Traits>(__delim), - true, true, true); + ? _STLP_PRIV __read_buffered(this, __buf, __n - 1, __s, + _STLP_PRIV _Eq_char_bound<_Traits>(__delim), + _STLP_PRIV _Scan_for_char_val<_Traits>(__delim), + true, true, true) + : _STLP_PRIV __read_unbuffered(this, __buf, __n - 1, __s, + _STLP_PRIV _Eq_char_bound<_Traits>(__delim), + true, true, true); } } @@ -790,8 +780,7 @@ // put in a terminating null character. template basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) -{ +basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) { sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; @@ -799,15 +788,15 @@ basic_streambuf<_CharT, _Traits>*__buf = this->rdbuf(); if (__buf->gptr() != __buf->egptr()) _M_gcount - = _M_read_buffered(this, __buf, __n, __s, - _Constant_unary_fun(false), - _Project2nd(), - false, false, false); + = _STLP_PRIV __read_buffered(this, __buf, __n, __s, + _STLP_PRIV _Constant_unary_fun(false), + _STLP_PRIV _Project2nd(), + false, false, false); else _M_gcount - = _M_read_unbuffered(this, __buf, __n, __s, - _Constant_unary_fun(false), - false, false, false); + = _STLP_PRIV __read_unbuffered(this, __buf, __n, __s, + _STLP_PRIV _Constant_unary_fun(false), + false, false, false); } else this->setstate(ios_base::failbit); @@ -823,8 +812,7 @@ // we don't put in a terminating null character. template streamsize -basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax) -{ +basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax) { sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; @@ -841,15 +829,15 @@ if (__buf->gptr() != __buf->egptr()) _M_gcount - = _M_read_buffered(this, __buf, (min) (__avail, __nmax), __s, - _Constant_unary_fun(false), - _Project2nd(), - false, false, false); + = _STLP_PRIV __read_buffered(this, __buf, (min) (__avail, __nmax), __s, + _STLP_PRIV _Constant_unary_fun(false), + _STLP_PRIV _Project2nd(), + false, false, false); else _M_gcount - = _M_read_unbuffered(this, __buf, (min) (__avail, __nmax), __s, - _Constant_unary_fun(false), - false, false, false); + = _STLP_PRIV __read_unbuffered(this, __buf, (min) (__avail, __nmax), __s, + _STLP_PRIV _Constant_unary_fun(false), + false, false, false); } } else { @@ -857,17 +845,7 @@ if (this->eof()) this->setstate(ios_base::eofbit | ios_base::failbit); else - { - if (__nmax < 0) - { - basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); - streamsize __avail = __buf->in_avail(); - if(__avail == -1) - this->setstate(ios_base::eofbit); - } - else - this->setstate(ios_base::failbit); - } + this->setstate(ios_base::failbit); } // if (this->eof()) @@ -877,24 +855,23 @@ } template -void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s) -{ +void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s) { sentry __sentry(*this); // Skip whitespace. if (__sentry) { basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); streamsize __nmax = this->width() > 0 ? this->width() - 1 - : (numeric_limits::max)() / sizeof(_CharT) - 1; + : ((numeric_limits::max)() / sizeof(_CharT)) - 1; streamsize __n = __buf->gptr() != __buf->egptr() - ? _M_read_buffered(this, __buf, __nmax, __s, - _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), - _Scan_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), - false, true, false) - : _M_read_unbuffered(this, __buf, __nmax, __s, - _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), - false, true, false); + ? _STLP_PRIV __read_buffered(this, __buf, __nmax, __s, + _STLP_PRIV _Is_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())), + _STLP_PRIV _Scan_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())), + false, true, false) + : _STLP_PRIV __read_unbuffered(this, __buf, __nmax, __s, + _STLP_PRIV _Is_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())), + false, true, false); if (__n == 0) this->setstate(ios_base::failbit); } @@ -909,36 +886,14 @@ template < class _CharT, class _Traits, class _Is_Delim> void _STLP_CALL _M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that, - basic_streambuf<_CharT, _Traits>* __buf, - _Is_Delim __is_delim, - bool __extract_delim, bool __set_failbit) -{ + basic_streambuf<_CharT, _Traits>* __buf, + _Is_Delim __is_delim, + bool __extract_delim, bool __set_failbit) { bool __done = false; ios_base::iostate __status = 0; typedef typename basic_istream<_CharT, _Traits>::int_type int_type; _STLP_TRY { -#ifdef __SYMBIAN32__ - int_type __c = __buf->sgetc(); - do { - - if (__that->_S_eof(__c)) { - __done = true; - __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit - : ios_base::eofbit; - break; - } - - else if (__is_delim(__c)) { - __done = true; - if (__extract_delim) - __buf->snextc(); - break; - - } - __c = __buf->snextc(); - } while(!__done); -#else while (!__done) { int_type __c = __buf->sbumpc(); @@ -948,14 +903,13 @@ : ios_base::eofbit; } - else if (__is_delim(__c)) { + else if (__is_delim(_Traits::to_char_type(__c))) { __done = true; if (!__extract_delim) if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c)))) __status |= ios_base::failbit; } } -#endif } _STLP_CATCH_ALL { __that->_M_handle_exception(ios_base::badbit); @@ -972,10 +926,9 @@ template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim> void _STLP_CALL _M_ignore_buffered(basic_istream<_CharT, _Traits>* __that, - basic_streambuf<_CharT, _Traits>* __buf, - _Is_Delim __is_delim, _Scan_Delim __scan_delim, - bool __extract_delim, bool __set_failbit) -{ + basic_streambuf<_CharT, _Traits>* __buf, + _Is_Delim __is_delim, _Scan_Delim __scan_delim, + bool __extract_delim, bool __set_failbit) { bool __at_eof = false; bool __found_delim = false; @@ -1028,11 +981,10 @@ template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim> streamsize _STLP_CALL _M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that, - basic_streambuf<_CharT, _Traits>* __buf, - streamsize _Num, _Max_Chars __max_chars, - _Is_Delim __is_delim, - bool __extract_delim, bool __set_failbit) -{ + basic_streambuf<_CharT, _Traits>* __buf, + streamsize _Num, _Max_Chars __max_chars, + _Is_Delim __is_delim, + bool __extract_delim, bool __set_failbit) { streamsize __n = 0; ios_base::iostate __status = 0; typedef typename basic_istream<_CharT, _Traits>::int_type int_type; @@ -1047,7 +999,7 @@ break; } - else if (__is_delim(__c)) { + else if (__is_delim(_Traits::to_char_type(__c))) { if (__extract_delim) ++__n; else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c)))) @@ -1071,12 +1023,11 @@ template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim, class _Scan_Delim> streamsize _STLP_CALL _M_ignore_buffered(basic_istream<_CharT, _Traits>* __that, - basic_streambuf<_CharT, _Traits>* __buf, - streamsize _Num, - _Max_Chars __max_chars, - _Is_Delim __is_delim, _Scan_Delim __scan_delim, - bool __extract_delim, bool __set_failbit) -{ + basic_streambuf<_CharT, _Traits>* __buf, + streamsize _Num, + _Max_Chars __max_chars, + _Is_Delim __is_delim, _Scan_Delim __scan_delim, + bool __extract_delim, bool __set_failbit) { streamsize __n = 0; bool __at_eof = false; bool __done = false; @@ -1087,7 +1038,7 @@ streamsize __m = __max_chars(_Num, __n); if (__avail >= __m) { // We have more characters than we need. - const _CharT* __last = __buf->_M_gptr() + __m; + const _CharT* __last = __buf->_M_gptr() + __STATIC_CAST(ptrdiff_t, __m); const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last); ptrdiff_t __chunk = __p - __buf->_M_gptr(); __n += __chunk; @@ -1141,33 +1092,30 @@ // decided to switch from buffered to unbuffered input. We switch to // to _M_ignore_unbuffered. - return __n + _M_ignore_unbuffered( __that, __buf, _Num, __max_chars, + return __n + _M_ignore_unbuffered(__that, __buf, _Num, __max_chars, __is_delim, __extract_delim, __set_failbit); } template basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::ignore(streamsize __n) -{ +basic_istream<_CharT, _Traits>::ignore(streamsize __n) { sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; if (__sentry) { basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); - typedef _Constant_unary_fun _Const_bool; - typedef _Constant_binary_fun - _Const_streamsize; + typedef _STLP_PRIV _Constant_unary_fun _Const_bool; + typedef _STLP_PRIV _Constant_binary_fun _Const_streamsize; const streamsize __maxss = (numeric_limits::max)(); if (__n == (numeric_limits::max)()) { if (__buf->gptr() != __buf->egptr()) - _M_gcount - = _M_ignore_buffered(this, __buf, - __maxss, _Const_streamsize(__maxss), - _Const_bool(false), - _Project2nd(), - false, false); + _M_gcount = _M_ignore_buffered(this, __buf, + __maxss, _Const_streamsize(__maxss), + _Const_bool(false), + _STLP_PRIV _Project2nd(), + false, false); else _M_gcount = _M_ignore_unbuffered(this, __buf, __maxss, _Const_streamsize(__maxss), @@ -1175,12 +1123,11 @@ } else { if (__buf->gptr() != __buf->egptr()) - _M_gcount - = _M_ignore_buffered(this, __buf, - __n, minus(), - _Const_bool(false), - _Project2nd(), - false, false); + _M_gcount = _M_ignore_buffered(this, __buf, + __n, minus(), + _Const_bool(false), + _STLP_PRIV _Project2nd(), + false, false); else _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus(), _Const_bool(false), false, false); @@ -1192,15 +1139,14 @@ template basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim) -{ +basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim) { sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; if (__sentry) { basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); - typedef _Constant_unary_fun _Const_bool; - typedef _Constant_binary_fun + typedef _STLP_PRIV _Constant_unary_fun _Const_bool; + typedef _STLP_PRIV _Constant_binary_fun _Const_streamsize; const streamsize __maxss = (numeric_limits::max)(); @@ -1208,26 +1154,25 @@ if (__buf->gptr() != __buf->egptr()) _M_gcount = _M_ignore_buffered(this, __buf, __maxss, _Const_streamsize(__maxss), - _Eq_int_bound<_Traits>(__delim), - _Scan_for_int_val<_Traits>(__delim), + _STLP_PRIV _Eq_int_bound<_Traits>(__delim), + _STLP_PRIV _Scan_for_int_val<_Traits>(__delim), true, false); else _M_gcount = _M_ignore_unbuffered(this, __buf, __maxss, _Const_streamsize(__maxss), - _Eq_int_bound<_Traits>(__delim), + _STLP_PRIV _Eq_int_bound<_Traits>(__delim), true, false); } else { if (__buf->gptr() != __buf->egptr()) _M_gcount = _M_ignore_buffered(this, __buf, __n, minus(), - _Eq_int_bound<_Traits>( - __delim), - _Scan_for_int_val<_Traits>(__delim), + _STLP_PRIV _Eq_int_bound<_Traits>(__delim), + _STLP_PRIV _Scan_for_int_val<_Traits>(__delim), true, false); else _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus(), - _Eq_int_bound<_Traits>(__delim), + _STLP_PRIV _Eq_int_bound<_Traits>(__delim), true, false); } } @@ -1238,19 +1183,18 @@ // This member function does not construct a sentry object, because // it is called from sentry's constructor. template -void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit) -{ +void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit) { basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); if (!__buf) this->setstate(ios_base::badbit); else if (__buf->gptr() != __buf->egptr()) _M_ignore_buffered(this, __buf, - _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), - _Scan_for_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), + _STLP_PRIV _Is_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())), + _STLP_PRIV _Scan_for_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())), false, __set_failbit); else _M_ignore_unbuffered(this, __buf, - _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), + _STLP_PRIV _Is_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())), false, __set_failbit); } @@ -1262,55 +1206,21 @@ // We stop when we get an exception, when we fail to insert into the // output streambuf, or when __is_delim is true. +_STLP_MOVE_TO_PRIV_NAMESPACE + template < class _CharT, class _Traits, class _Is_Delim> streamsize _STLP_CALL -_M_copy_unbuffered( basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src, - basic_streambuf<_CharT, _Traits>* __dest, - _Is_Delim __is_delim, - bool __extract_delim, bool __rethrow) -{ +__copy_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src, + basic_streambuf<_CharT, _Traits>* __dest, + _Is_Delim __is_delim, + bool __extract_delim, bool __rethrow) { streamsize __extracted = 0; ios_base::iostate __status = 0; typedef typename basic_istream<_CharT, _Traits>::int_type int_type; int_type __c; _STLP_TRY { -#ifdef __SYMBIAN32__ - __c = __src->sgetc(); - for(;; __c = __src->snextc()){ - - // If we failed to get a character, then quit. - if (__that->_S_eof(__c)) { - __status |= ios_base::eofbit; - break; - } - // If it's the delimiter, then quit. - else if (__is_delim(__c)) { - if (!__extract_delim) - __status |= ios_base::failbit; - break; - } - - else { - - // Try to put the character in the output streambuf. - _STLP_TRY { - if (!__that->_S_eof(__dest->sputc(__c))) - ++__extracted; - else - break; - } - _STLP_CATCH_ALL { - __status |= ios_base::failbit; - break; - } - - } - - } /* while (true) */ -#else - while (true) { - + for (;;) { // Get a character. If there's an exception, catch and (maybe) rethrow it. __c = __src->sbumpc(); @@ -1320,18 +1230,16 @@ break; } // If it's the delimiter, then quit. - else if (__is_delim(__c)) { + else if (__is_delim(_Traits::to_char_type(__c))) { if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c))) __status |= ios_base::failbit; break; } - else { - // Try to put the character in the output streambuf. bool __failed = false; _STLP_TRY { - if (!__that->_S_eof(__dest->sputc(__c))) + if (!__that->_S_eof(__dest->sputc(_Traits::to_char_type(__c)))) ++__extracted; else __failed = true; @@ -1350,8 +1258,8 @@ break; } - } /* while (true) */ -#endif + } /* for (;;) */ + } // fbp : this try/catch moved here in reasonable assumption // __is_delim never throw (__pushback is guaranteed not to) @@ -1366,28 +1274,27 @@ // Buffered copying from one streambuf to another. We copy the characters // in chunks, rather than one at a time. We still have to worry about all -// of the error conditions we checked in _M_copy_unbuffered, plus one more: +// of the error conditions we checked in __copy_unbuffered, plus one more: // the streambuf might decide to switch from a buffered to an unbuffered mode. template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim> streamsize _STLP_CALL -_M_copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src, - basic_streambuf<_CharT, _Traits>* __dest, - _Scan_Delim __scan_delim, _Is_Delim __is_delim, - bool __extract_delim, bool __rethrow) -{ +__copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src, + basic_streambuf<_CharT, _Traits>* __dest, + _Scan_Delim __scan_delim, _Is_Delim __is_delim, + bool __extract_delim, bool __rethrow) { streamsize __extracted = 0; ios_base::iostate __status = 0; typedef typename basic_istream<_CharT, _Traits>::int_type int_type; - int_type __c = _Traits::eof(); + //Borland compiler generates a warning if assignment because value is never used: + int_type __c /*= _Traits::eof()*/; _CharT* __first = __src->_M_gptr(); ptrdiff_t __avail = __src->_M_egptr() - __first; // fbp : introduced to move catch/try blocks out of the loop - bool __do_handle_exceptions; + bool __do_handle_exceptions = false; _STLP_TRY { - while (true) { - __do_handle_exceptions = false ; + for (;;) { const _CharT* __last = __scan_delim(__first, __src->_M_egptr()); // Try to copy the entire input buffer to the output buffer. @@ -1411,15 +1318,18 @@ __avail = __src->_M_egptr() - __first; if (__avail > 0) - {} // dwa 1/16/00 -- suppress a Metrowerks warning + {} // dwa 1/16/00 -- suppress a Metrowerks warning else if (__that->_S_eof(__c)) { __status |= ios_base::eofbit; break; } - else - return __extracted + _M_copy_unbuffered(__that, __src, __dest, __is_delim, + else { + return __extracted + __copy_unbuffered(__that, __src, __dest, __is_delim, __extract_delim, __rethrow); - } /* while */ + } + + __do_handle_exceptions = false; + } } _STLP_CATCH_ALL { @@ -1433,13 +1343,12 @@ return __extracted; } - +_STLP_MOVE_TO_STD_NAMESPACE template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits> - ::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim) -{ + ::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim) { sentry __sentry(*this, _No_Skip_WS()); this->_M_gcount = 0; @@ -1448,13 +1357,13 @@ if (__src) this->_M_gcount = __src->egptr() != __src->gptr() - ? _M_copy_buffered(this, __src, &__dest, - _Scan_for_char_val<_Traits>(__delim), - _Eq_char_bound<_Traits>(__delim), - false, false) - : _M_copy_unbuffered(this, __src, &__dest, - _Eq_char_bound<_Traits>(__delim), - false, false); + ? _STLP_PRIV __copy_buffered(this, __src, &__dest, + _STLP_PRIV _Scan_for_char_val<_Traits>(__delim), + _STLP_PRIV _Eq_char_bound<_Traits>(__delim), + false, false) + : _STLP_PRIV __copy_unbuffered(this, __src, &__dest, + _STLP_PRIV _Eq_char_bound<_Traits>(__delim), + false, false); } if (this->_M_gcount == 0) @@ -1467,8 +1376,7 @@ template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits> - ::operator>>(basic_streambuf<_CharT, _Traits>* __dest) -{ + ::operator>>(basic_streambuf<_CharT, _Traits>* __dest) { streamsize __n = 0; typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry; _Sentry __sentry(*this); @@ -1476,13 +1384,13 @@ basic_streambuf<_CharT, _Traits>* __src = this->rdbuf(); if (__src && __dest) __n = __src->egptr() != __src->gptr() - ? _M_copy_buffered(this, __src, __dest, - _Project2nd(), - _Constant_unary_fun(false), - false, true) - : _M_copy_unbuffered(this, __src, __dest, - _Constant_unary_fun(false), - false, true); + ? _STLP_PRIV __copy_buffered(this, __src, __dest, + _STLP_PRIV _Project2nd(), + _STLP_PRIV _Constant_unary_fun(false), + false, true) + : _STLP_PRIV __copy_unbuffered(this, __src, __dest, + _STLP_PRIV _Constant_unary_fun(false), + false, true); } if (__n == 0) @@ -1496,39 +1404,26 @@ // ---------------------------------------------------------------- template -_STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits> +basic_iostream<_CharT, _Traits> ::basic_iostream(basic_streambuf<_CharT, _Traits>* __buf) : basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(__buf), - basic_ostream<_CharT, _Traits>(__buf) -{ + basic_ostream<_CharT, _Traits>(__buf) { this->init(__buf); } template -_STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits>::~basic_iostream() +basic_iostream<_CharT, _Traits>::~basic_iostream() {} - -template -_STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits> - ::basic_istream(basic_streambuf<_CharT, _Traits>* __buf) : - basic_ios<_CharT, _Traits>(), _M_gcount(0) { - this->init(__buf); - } - -template -_STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits> - ::~basic_istream() {} - - - _STLP_END_NAMESPACE -# undef __BIS_int_type__ -# undef __BIS_pos_type__ -# undef __BIS_off_type__ - -# endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */ +#undef __BIS_int_type__ +#undef __BIS_pos_type__ +#undef __BIS_off_type__ #endif /* _STLP_ISTREAM_C */ + +// Local Variables: +// mode:C++ +// End: