1.1 --- a/epoc32/include/stdapis/stlport/stl/_istream.c Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/stlport/stl/_istream.c Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,1534 @@
1.4 -_istream.c
1.5 +/*
1.6 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.7 + * Copyright (c) 1999
1.8 + * Silicon Graphics Computer Systems, Inc.
1.9 + *
1.10 + * Copyright (c) 1999
1.11 + * Boris Fomitchev
1.12 + *
1.13 + * This material is provided "as is", with absolutely no warranty expressed
1.14 + * or implied. Any use is at your own risk.
1.15 + *
1.16 + * Permission to use or copy this software for any purpose is hereby granted
1.17 + * without fee, provided the above notices are retained on all copies.
1.18 + * Permission to modify the code and to distribute modified code is granted,
1.19 + * provided the above notices are retained, and a notice that the code was
1.20 + * modified is included with the above copyright notice.
1.21 + *
1.22 + */
1.23 +#ifndef _STLP_ISTREAM_C
1.24 +#define _STLP_ISTREAM_C
1.25 +
1.26 +#ifndef _STLP_INTERNAL_ISTREAM_H
1.27 +# include <stl/_istream.h>
1.28 +#endif
1.29 +
1.30 +# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
1.31 +
1.32 +#ifndef _STLP_LIMITS_H
1.33 +# include <stl/_limits.h>
1.34 +#endif
1.35 +
1.36 +#ifndef _STLP_INTERNAL_NUM_GET_H
1.37 +# include <stl/_num_get.h>
1.38 +#endif
1.39 +
1.40 +# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
1.41 +// no wchar_t is supported for this mode
1.42 +# define __BIS_int_type__ int
1.43 +# define __BIS_pos_type__ streampos
1.44 +# define __BIS_off_type__ streamoff
1.45 +# else
1.46 +# define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type
1.47 +# define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type
1.48 +# define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type
1.49 +# endif
1.50 +
1.51 +_STLP_BEGIN_NAMESPACE
1.52 +
1.53 +//----------------------------------------------------------------------
1.54 +// Function object structs used by some member functions.
1.55 +
1.56 +template <class _Traits>
1.57 +struct _Is_not_wspace {
1.58 + typedef typename _Traits::char_type argument_type;
1.59 + typedef bool result_type;
1.60 +
1.61 + const ctype<argument_type>* _M_ctype;
1.62 +
1.63 + _Is_not_wspace(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
1.64 + bool operator()(argument_type __c) const
1.65 + { return !_M_ctype->is(ctype_base::space, __c); }
1.66 +};
1.67 +
1.68 +template <class _Traits>
1.69 +struct _Is_wspace_null {
1.70 + typedef typename _Traits::char_type argument_type;
1.71 + typedef bool result_type;
1.72 +
1.73 + const ctype<argument_type>* _M_ctype;
1.74 +
1.75 + _Is_wspace_null(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
1.76 + bool operator()(argument_type __c) const {
1.77 + return _Traits::eq(__c, argument_type()) ||
1.78 + _M_ctype->is(ctype_base::space, __c);
1.79 + }
1.80 +};
1.81 +
1.82 +template <class _Traits>
1.83 +struct _Scan_for_wspace {
1.84 + typedef typename _Traits::char_type char_type;
1.85 + typedef char_type* first_argument_type;
1.86 + typedef char_type* second_argument_type;
1.87 + typedef char_type* result_type;
1.88 +
1.89 + const ctype<char_type>* _M_ctype;
1.90 +
1.91 + _Scan_for_wspace(const ctype<char_type>* __ctype) : _M_ctype(__ctype) {}
1.92 + const char_type*
1.93 + operator()(const char_type* __first, const char_type* __last) const {
1.94 + return _M_ctype->scan_is(ctype_base::space, __first, __last);
1.95 + }
1.96 +};
1.97 +
1.98 +template <class _Traits>
1.99 +struct _Scan_wspace_null {
1.100 + typedef typename _Traits::char_type char_type;
1.101 + typedef char_type* first_argument_type;
1.102 + typedef char_type* second_argument_type;
1.103 + typedef char_type* result_type;
1.104 +
1.105 + const ctype<char_type>* _M_ctype;
1.106 +
1.107 + _Scan_wspace_null(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
1.108 + const char_type*
1.109 + operator()(const char_type* __first, const char_type* __last) const {
1.110 + __last = find_if(__first, __last,
1.111 + _Eq_char_bound<_Traits>(char_type()));
1.112 + return _M_ctype->scan_is(ctype_base::space, __first, __last);
1.113 + }
1.114 +};
1.115 +
1.116 +template <class _Traits>
1.117 +struct _Scan_for_not_wspace {
1.118 + typedef typename _Traits::char_type char_type;
1.119 + typedef char_type* first_argument_type;
1.120 + typedef char_type* second_argument_type;
1.121 + typedef char_type* result_type;
1.122 +
1.123 + const ctype<char_type>* _M_ctype;
1.124 +
1.125 + _Scan_for_not_wspace(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
1.126 + const char_type*
1.127 + operator()(const char_type* __first, const char_type* __last) const {
1.128 + return _M_ctype->scan_not(ctype_base::space, __first, __last);
1.129 + }
1.130 +};
1.131 +
1.132 +template <class _Traits>
1.133 +struct _Scan_for_char_val
1.134 +{
1.135 + typedef typename _Traits::char_type char_type;
1.136 + typedef char_type* first_argument_type;
1.137 + typedef char_type* second_argument_type;
1.138 + typedef char_type* result_type;
1.139 +
1.140 + char_type _M_val;
1.141 +
1.142 + _Scan_for_char_val(char_type __val) : _M_val(__val) {}
1.143 +
1.144 + const char_type*
1.145 + operator()(const char_type* __first, const char_type* __last) const {
1.146 + return find_if(__first, __last, _Eq_char_bound<_Traits>(_M_val));
1.147 + }
1.148 +};
1.149 +
1.150 +template <class _Traits>
1.151 +struct _Scan_for_int_val
1.152 +{
1.153 + typedef typename _Traits::char_type char_type;
1.154 + typedef typename _Traits::int_type int_type;
1.155 + typedef char_type* first_argument_type;
1.156 + typedef char_type* second_argument_type;
1.157 + typedef char_type* result_type;
1.158 +
1.159 + int_type _M_val;
1.160 +
1.161 + _Scan_for_int_val(int_type __val) : _M_val(__val) {}
1.162 +
1.163 + const char_type*
1.164 + operator()(const char_type* __first, const char_type* __last) const {
1.165 + return find_if(__first, __last,
1.166 + _Eq_int_bound<_Traits>(_M_val));
1.167 + }
1.168 +};
1.169 +
1.170 +// Helper function: try to push back a character to a streambuf,
1.171 +// return true if the pushback succeeded. Does not throw.
1.172 +
1.173 +template <class _CharT, class _Traits>
1.174 +bool _STLP_CALL
1.175 +__pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c)
1.176 +{
1.177 + bool ret;
1.178 + _STLP_TRY {
1.179 + const typename _Traits::int_type __eof = _Traits::eof();
1.180 + ret = !_Traits::eq_int_type(__buf->sputbackc(__c), __eof);
1.181 + }
1.182 + _STLP_CATCH_ALL {
1.183 + ret = false;
1.184 + }
1.185 + return ret;
1.186 +}
1.187 +
1.188 +template <class _CharT, class _Traits>
1.189 +basic_istream<_CharT, _Traits>& _STLP_CALL
1.190 +ws(basic_istream<_CharT, _Traits>& __is)
1.191 +{
1.192 + typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
1.193 + _Sentry __sentry(__is, _No_Skip_WS()); // Don't skip whitespace.
1.194 + if (__sentry)
1.195 + __is._M_skip_whitespace(false);
1.196 + return __is;
1.197 +}
1.198 +
1.199 +// Helper functions for istream<>::sentry constructor.
1.200 +template <class _CharT, class _Traits>
1.201 +bool
1.202 +_M_init_skip(basic_istream<_CharT, _Traits>& __is) {
1.203 + if (__is.good()) {
1.204 + if (__is.tie())
1.205 + __is.tie()->flush();
1.206 +
1.207 + __is._M_skip_whitespace(true);
1.208 + }
1.209 +
1.210 + if (!__is.good()) {
1.211 + __is.setstate(ios_base::failbit);
1.212 + return false;
1.213 + } else
1.214 + return true;
1.215 +}
1.216 +
1.217 +template <class _CharT, class _Traits>
1.218 +bool
1.219 +_M_init_noskip(basic_istream<_CharT, _Traits>& __is){
1.220 + if (__is.good()) {
1.221 + if (__is.tie())
1.222 + __is.tie()->flush();
1.223 +
1.224 + if (!__is.rdbuf())
1.225 + __is.setstate(ios_base::badbit);
1.226 + }
1.227 + else
1.228 + __is.setstate(ios_base::failbit);
1.229 + return __is.good();
1.230 +}
1.231 +
1.232 +//----------------------------------------------------------------------
1.233 +// Definitions of basic_istream<>'s noninline member functions.
1.234 +
1.235 +// Helper function for formatted input of numbers.
1.236 +template <class _CharT, class _Traits, class _Number>
1.237 +ios_base::iostate _STLP_CALL
1.238 +_M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val)
1.239 +{
1.240 + typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
1.241 + ios_base::iostate __err = 0;
1.242 + _Sentry __sentry( __that ); // Skip whitespace.
1.243 + if (__sentry) {
1.244 + typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > _Num_get;
1.245 + _STLP_TRY {
1.246 + ((const _Num_get&)use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()),
1.247 + 0, __that, __err, __val);
1.248 + }
1.249 + _STLP_CATCH_ALL {
1.250 + __that._M_handle_exception(ios_base::badbit);
1.251 + }
1.252 + if (__err) __that.setstate(__err);
1.253 + }
1.254 + return __err;
1.255 +}
1.256 +
1.257 +
1.258 +// Unformatted input
1.259 +
1.260 +template <class _CharT, class _Traits>
1.261 +__BIS_int_type__
1.262 +basic_istream<_CharT, _Traits>::peek()
1.263 +{
1.264 + typename _Traits::int_type __tmp = _Traits::eof();
1.265 +
1.266 + this->_M_gcount = 0;
1.267 + sentry __sentry(*this, _No_Skip_WS());
1.268 +
1.269 + if (__sentry) {
1.270 + _STLP_TRY {
1.271 + __tmp = this->rdbuf()->sgetc();
1.272 + }
1.273 + _STLP_CATCH_ALL {
1.274 + this->_M_handle_exception(ios_base::badbit);
1.275 + }
1.276 + }
1.277 + else
1.278 + {
1.279 + if (this->_S_eof(__tmp))
1.280 + {
1.281 + this->clear();
1.282 + this->setstate(ios_base::eofbit);
1.283 + }
1.284 + }
1.285 + return __tmp;
1.286 +}
1.287 +
1.288 +
1.289 +template <class _CharT, class _Traits>
1.290 +__BIS_int_type__
1.291 +basic_istream<_CharT, _Traits>::get()
1.292 +{
1.293 + typename _Traits::int_type __tmp = _Traits::eof();
1.294 + sentry __sentry(*this, _No_Skip_WS());
1.295 + this->_M_gcount = 0;
1.296 +
1.297 + if (__sentry) {
1.298 + _STLP_TRY {
1.299 + __tmp = this->rdbuf()->sbumpc();
1.300 + }
1.301 + _STLP_CATCH_ALL {
1.302 + this->_M_handle_exception(ios_base::badbit);
1.303 + }
1.304 +
1.305 + if (!this->_S_eof(__tmp))
1.306 + this->_M_gcount = 1;
1.307 + }
1.308 +
1.309 + if (_M_gcount == 0)
1.310 + this->setstate(ios_base::eofbit | ios_base::failbit);
1.311 +
1.312 + return __tmp;
1.313 +}
1.314 +
1.315 +template <class _CharT, class _Traits>
1.316 +basic_istream<_CharT, _Traits>&
1.317 +basic_istream<_CharT, _Traits>::get(_CharT& __c)
1.318 +{
1.319 + sentry __sentry(*this, _No_Skip_WS());
1.320 + this->_M_gcount = 0;
1.321 +
1.322 + if (__sentry) {
1.323 + typename _Traits::int_type __tmp = _Traits::eof();
1.324 + _STLP_TRY {
1.325 + __tmp = this->rdbuf()->sbumpc();
1.326 + }
1.327 + _STLP_CATCH_ALL {
1.328 + this->_M_handle_exception(ios_base::badbit);
1.329 + }
1.330 +
1.331 + if (!this->_S_eof(__tmp)) {
1.332 + this->_M_gcount = 1;
1.333 + __c = _Traits::to_char_type(__tmp);
1.334 + }
1.335 + }
1.336 +
1.337 + if (this->_M_gcount == 0)
1.338 + this->setstate(ios_base::eofbit | ios_base::failbit);
1.339 +
1.340 + return *this;
1.341 +}
1.342 +
1.343 +
1.344 +
1.345 +// Read characters and discard them. The standard specifies a single
1.346 +// function with two arguments, each with a default. We instead use
1.347 +// three overloded functions, because it's possible to implement the
1.348 +// first two more efficiently than the fully general third version.
1.349 +template <class _CharT, class _Traits>
1.350 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore()
1.351 +{
1.352 + sentry __sentry(*this, _No_Skip_WS());
1.353 + this->_M_gcount = 0;
1.354 +
1.355 + if (__sentry) {
1.356 + int_type __c;
1.357 + _STLP_TRY {
1.358 + __c = this->rdbuf()->sbumpc();
1.359 + }
1.360 + _STLP_CATCH_ALL {
1.361 + this->_M_handle_exception(ios_base::badbit);
1.362 + return *this;
1.363 + }
1.364 +
1.365 + if (!this->_S_eof(__c))
1.366 + this->_M_gcount = 1;
1.367 + else
1.368 + this->setstate(ios_base::eofbit);
1.369 + }
1.370 +
1.371 + return *this;
1.372 +}
1.373 +
1.374 +// Putback
1.375 +
1.376 +template <class _CharT, class _Traits>
1.377 +basic_istream<_CharT, _Traits>&
1.378 +basic_istream<_CharT, _Traits>::putback(_CharT __c) {
1.379 + this->_M_gcount = 0;
1.380 + sentry __sentry(*this, _No_Skip_WS());
1.381 +
1.382 + if (__sentry) {
1.383 + typename _Traits::int_type __tmp = _Traits::eof();
1.384 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.385 +// if (!__buf || this->_S_eof(__buf->sputbackc(__c)))
1.386 + if (__buf) {
1.387 + _STLP_TRY {
1.388 + __tmp = __buf->sputbackc(__c);
1.389 + }
1.390 + _STLP_CATCH_ALL {
1.391 + this->_M_handle_exception(ios_base::badbit);
1.392 + }
1.393 + }
1.394 + if (this->_S_eof(__tmp))
1.395 + this->setstate(ios_base::badbit);
1.396 + }
1.397 + else
1.398 + this->setstate(ios_base::failbit);
1.399 +
1.400 + return *this;
1.401 +}
1.402 +
1.403 +template <class _CharT, class _Traits>
1.404 +basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
1.405 + this->_M_gcount = 0;
1.406 +
1.407 + sentry __sentry(*this, _No_Skip_WS());
1.408 +
1.409 + if (__sentry) {
1.410 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.411 + // if (!__buf || _Traits::eq_int_type(__buf->sungetc(), _Traits::eof()))
1.412 + if (__buf) {
1.413 + _STLP_TRY {
1.414 + _CharT __tmp;
1.415 + __tmp = __buf->sungetc();
1.416 +#ifdef __SYMBIAN32__
1.417 + if (__tmp == (_CharT)-1) //chek for eof
1.418 +#else
1.419 + if (this->_S_eof(__tmp))
1.420 +#endif
1.421 + this->setstate(ios_base::badbit);
1.422 + }
1.423 + _STLP_CATCH_ALL {
1.424 + this->_M_handle_exception(ios_base::badbit);
1.425 + }
1.426 + } else
1.427 + this->setstate(ios_base::badbit);
1.428 + }
1.429 + else
1.430 + this->setstate(ios_base::failbit);
1.431 +
1.432 + return *this;
1.433 +}
1.434 +
1.435 +// Positioning and buffer control.
1.436 +
1.437 +template <class _CharT, class _Traits>
1.438 +int basic_istream<_CharT, _Traits>::sync() {
1.439 + sentry __sentry(*this, _No_Skip_WS());
1.440 +
1.441 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.442 + if (__buf) {
1.443 + if (__buf->pubsync() == -1) {
1.444 + this->setstate(ios_base::badbit);
1.445 + return -1;
1.446 + }
1.447 + else
1.448 + return 0;
1.449 + }
1.450 + else
1.451 + return -1;
1.452 +}
1.453 +
1.454 +template <class _CharT, class _Traits>
1.455 +__BIS_pos_type__
1.456 +basic_istream<_CharT, _Traits>::tellg() {
1.457 +#ifndef __SYMBIAN32__
1.458 + sentry __sentry(*this, _No_Skip_WS());
1.459 +#endif
1.460 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.461 + return (__buf && !this->fail()) ? __buf->pubseekoff(0, ios_base::cur, ios_base::in)
1.462 + : pos_type(-1);
1.463 +}
1.464 +
1.465 +template <class _CharT, class _Traits>
1.466 +basic_istream<_CharT, _Traits>&
1.467 +basic_istream<_CharT, _Traits>::seekg(pos_type __pos) {
1.468 +#ifndef __SYMBIAN32__
1.469 + sentry __sentry(*this, _No_Skip_WS());
1.470 +#endif
1.471 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.472 + if (!this->fail() && __buf)
1.473 + {
1.474 + pos_type pos = __buf->pubseekpos(__pos, ios_base::in);
1.475 + if(pos == pos_type(off_type(-1)))
1.476 + this->setstate(ios_base::failbit);
1.477 + }
1.478 + return *this;
1.479 +}
1.480 +
1.481 +template <class _CharT, class _Traits>
1.482 +basic_istream<_CharT, _Traits>&
1.483 +basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
1.484 +{
1.485 +#ifndef __SYMBIAN32__
1.486 + sentry __sentry(*this, _No_Skip_WS());
1.487 +#endif
1.488 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.489 + if (!this->fail() && __buf)
1.490 + {
1.491 +
1.492 + pos_type pos = __buf->pubseekoff(__off, __dir, ios_base::in);
1.493 + if(pos == pos_type(off_type(-1)))
1.494 + this->setstate(ios_base::failbit);
1.495 + }
1.496 + return *this;
1.497 +}
1.498 +
1.499 +// Formatted input of characters and character arrays.
1.500 +
1.501 +template <class _CharT, class _Traits>
1.502 +void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c)
1.503 +{
1.504 +// typename _Traits::int_type __tmp = _Traits::eof();
1.505 +
1.506 + sentry __sentry(*this); // Skip whitespace.
1.507 +
1.508 + if (__sentry) {
1.509 + typename _Traits::int_type __tmp = _Traits::eof();
1.510 +
1.511 + _STLP_TRY {
1.512 + __tmp = this->rdbuf()->sbumpc();
1.513 + }
1.514 + _STLP_CATCH_ALL {
1.515 + this->_M_handle_exception(ios_base::badbit);
1.516 + return;
1.517 + }
1.518 +
1.519 + if (!this->_S_eof(__tmp))
1.520 + __c = _Traits::to_char_type(__tmp);
1.521 + else
1.522 + this->setstate(ios_base::eofbit | ios_base::failbit);
1.523 + }
1.524 +}
1.525 +
1.526 +
1.527 +//---------------------------------------------------------------------------
1.528 +// istream's helper functions.
1.529 +
1.530 +// A generic function for unbuffered input. We stop when we reach EOF,
1.531 +// or when we have extracted _Num characters, or when the function object
1.532 +// __is_delim return true. In the last case, it extracts the character
1.533 +// for which __is_delim is true, if and only if __extract_delim is true.
1.534 +// It appends a null character to the end of the string; this means that
1.535 +// it may store up to _Num + 1 characters.
1.536 +//
1.537 +// __is_getline governs two corner cases: reading _Num characters without
1.538 +// encountering delim or eof (in which case failbit is set if __is_getline
1.539 +// is true); and reading _Num characters where the _Num+1'st character is
1.540 +// eof (in which case eofbit is set if __is_getline is true).
1.541 +//
1.542 +// It is assumed that __is_delim never throws.
1.543 +//
1.544 +// Return value is the number of characters extracted, including the
1.545 +// delimiter if it is extracted. Note that the number of characaters
1.546 +// extracted isn't necessarily the same as the number stored.
1.547 +
1.548 +template < class _CharT, class _Traits, class _Is_Delim>
1.549 +streamsize _STLP_CALL
1.550 +_M_read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
1.551 + streamsize _Num, _CharT* __s,
1.552 + _Is_Delim __is_delim,
1.553 + bool __extract_delim, bool __append_null,
1.554 + bool __is_getline)
1.555 +{
1.556 + streamsize __n = 0;
1.557 + ios_base::iostate __status = 0;
1.558 +
1.559 + typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1.560 + // The operations that can potentially throw are sbumpc, snextc, and sgetc.
1.561 + _STLP_TRY {
1.562 +# if 0
1.563 + int_type __c = __buf->sgetc();
1.564 + while (true) {
1.565 + if (__that->_S_eof(__c)) {
1.566 + if (__n < _Num || __is_getline)
1.567 + __status |= ios_base::eofbit;
1.568 + break;
1.569 + }
1.570 +
1.571 + else if (__is_delim(__c)) {
1.572 + if (__extract_delim) { // Extract and discard current character.
1.573 + __buf->sbumpc();
1.574 + ++__n;
1.575 + }
1.576 + break;
1.577 + }
1.578 +
1.579 + else if (__n == _Num) {
1.580 + if (__is_getline)
1.581 + __status |= ios_base::failbit;
1.582 + break;
1.583 + }
1.584 +
1.585 + *__s++ = _Traits::to_char_type(__c);
1.586 + ++__n;
1.587 + __c = __buf->snextc();
1.588 + }
1.589 +# else
1.590 +// int_type __c = __buf->sbumpc(); // __buf->sgetc();
1.591 +while (true) {
1.592 +
1.593 +int_type __c = __buf->sbumpc(); // sschwarz
1.594 +
1.595 +if (__that->_S_eof(__c)) {
1.596 +if (__n < _Num || __is_getline)
1.597 +__status |= ios_base::eofbit;
1.598 +break;
1.599 +}
1.600 +
1.601 +else if (__is_delim(__c)) {
1.602 +if (__extract_delim) { // Extract and discard current character.
1.603 +// __buf->sbumpc();
1.604 +++__n;
1.605 +}
1.606 +break;
1.607 +}
1.608 +
1.609 +else { // regular character
1.610 +
1.611 +*__s++ = _Traits::to_char_type(__c);
1.612 +++__n;
1.613 +
1.614 +}
1.615 +
1.616 +if (__n == _Num) {
1.617 +if (__is_getline) // didn't find delimiter as one of the _Num chars
1.618 +__status |= ios_base::failbit;
1.619 +break;
1.620 +}
1.621 +
1.622 +// *__s++ = _Traits::to_char_type(__c);
1.623 +// ++__n;
1.624 +
1.625 +}
1.626 +
1.627 +# endif
1.628 +
1.629 + }
1.630 + _STLP_CATCH_ALL {
1.631 + __that->_M_handle_exception(ios_base::badbit);
1.632 + *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
1.633 + return __n;
1.634 + }
1.635 +
1.636 + if (__append_null)
1.637 + *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
1.638 + if (__status)
1.639 + __that->setstate(__status); // This might throw.
1.640 + return __n;
1.641 +}
1.642 +
1.643 +// Much like _M_read_unbuffered, but with one additional function object:
1.644 +// __scan_delim(first, last) returns the first pointer p in [first, last)
1.645 +// such that __is_delim(p) is true.
1.646 +
1.647 +template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
1.648 +streamsize _STLP_CALL
1.649 +_M_read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
1.650 + streamsize _Num, _CharT* __s,
1.651 + _Is_Delim __is_delim, _Scan_Delim __scan_delim,
1.652 + bool __extract_delim, bool __append_null,
1.653 + bool __is_getline)
1.654 +{
1.655 + streamsize __n = 0;
1.656 + ios_base::iostate __status = 0;
1.657 + bool __done = false;
1.658 +
1.659 + _STLP_TRY {
1.660 + while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
1.661 + const _CharT* __first = __buf->_M_gptr();
1.662 + const _CharT* __last = __buf->_M_egptr();
1.663 + ptrdiff_t __request = _Num - __n;
1.664 +
1.665 + const _CharT* __p = __scan_delim(__first, __last);
1.666 + ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request);
1.667 + _Traits::copy(__s, __first, __chunk);
1.668 + __s += __chunk;
1.669 + __n += __chunk;
1.670 + __buf->_M_gbump((int)__chunk);
1.671 +
1.672 + // We terminated by finding delim.
1.673 + if (__p != __last && __p - __first <= __request) {
1.674 + if (__extract_delim) {
1.675 + __n += 1;
1.676 + __buf->_M_gbump(1);
1.677 + }
1.678 + __done = true;
1.679 + }
1.680 +
1.681 + // We terminated by reading all the characters we were asked for.
1.682 + else if(__n == _Num) {
1.683 +
1.684 + // Find out if we have reached eof. This matters for getline.
1.685 + if (__is_getline) {
1.686 + if (__chunk == __last - __first) {
1.687 + if (__that->_S_eof(__buf->sgetc()))
1.688 + __status |= ios_base::eofbit;
1.689 + }
1.690 + else
1.691 + __status |= ios_base::failbit;
1.692 + }
1.693 + __done = true;
1.694 + }
1.695 +
1.696 + // The buffer contained fewer than _Num - __n characters. Either we're
1.697 + // at eof, or we should refill the buffer and try again.
1.698 + else {
1.699 + if (__that->_S_eof(__buf->sgetc())) {
1.700 + __status |= ios_base::eofbit;
1.701 + __done = true;
1.702 + }
1.703 + }
1.704 + } // Close the while loop.
1.705 + }
1.706 + _STLP_CATCH_ALL {
1.707 + __that->_M_handle_exception(ios_base::badbit);
1.708 + __done = true;
1.709 + }
1.710 +
1.711 + if (__done) {
1.712 + if (__append_null)
1.713 + *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
1.714 + if (__status != 0)
1.715 + __that->setstate(__status); // This might throw.
1.716 + return __n;
1.717 + }
1.718 +
1.719 + // If execution has reached this point, then we have an empty buffer but
1.720 + // we have not reached eof. What that means is that the streambuf has
1.721 + // decided to switch from buffered to unbuffered input. We switch to
1.722 + // to _M_read_unbuffered.
1.723 +
1.724 + return __n + _M_read_unbuffered(__that, __buf, _Num - __n, __s, __is_delim,
1.725 + __extract_delim,__append_null,__is_getline);
1.726 +}
1.727 +
1.728 +
1.729 +
1.730 +
1.731 +template <class _CharT, class _Traits>
1.732 +basic_istream<_CharT, _Traits>&
1.733 +basic_istream<_CharT, _Traits>::get(_CharT* __s, streamsize __n,
1.734 + _CharT __delim) {
1.735 + sentry __sentry(*this, _No_Skip_WS());
1.736 + this->_M_gcount = 0;
1.737 +
1.738 + if (__sentry) {
1.739 + if (__n > 0) {
1.740 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.741 +
1.742 + if (__buf->egptr() != __buf->gptr())
1.743 + this->_M_gcount =
1.744 + _M_read_buffered(this, __buf, __n - 1, __s,
1.745 + _Eq_char_bound<_Traits>(__delim),
1.746 + _Scan_for_char_val<_Traits>(__delim),
1.747 + false, true, false);
1.748 + else
1.749 + this->_M_gcount =
1.750 + _M_read_unbuffered(this, __buf, __n - 1, __s,
1.751 + _Eq_char_bound<_Traits>(__delim),
1.752 + false, true, false);
1.753 + }
1.754 + }
1.755 +#ifdef __SYMBIAN32__
1.756 + *(__s + this->_M_gcount) = _STLP_DEFAULT_CONSTRUCTED(_CharT);
1.757 +#endif //__SYMBIAN32__
1.758 + if (this->_M_gcount == 0)
1.759 + this->setstate(ios_base::failbit);
1.760 +
1.761 + return *this;
1.762 +}
1.763 +
1.764 +// Getline is essentially identical to get, except that it extracts
1.765 +// the delimiter.
1.766 +template <class _CharT, class _Traits>
1.767 +basic_istream<_CharT, _Traits>&
1.768 +basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n,
1.769 + _CharT __delim) {
1.770 + sentry __sentry(*this, _No_Skip_WS());
1.771 + this->_M_gcount = 0;
1.772 +
1.773 + if (__sentry) {
1.774 + if (__n > 0) {
1.775 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.776 + this->_M_gcount = __buf->egptr() != __buf->gptr()
1.777 + ? _M_read_buffered(this, __buf, __n - 1, __s,
1.778 + _Eq_char_bound<_Traits>(__delim),
1.779 + _Scan_for_char_val<_Traits>(__delim),
1.780 + true, true, true)
1.781 + : _M_read_unbuffered(this, __buf, __n - 1, __s,
1.782 + _Eq_char_bound<_Traits>(__delim),
1.783 + true, true, true);
1.784 + }
1.785 + }
1.786 +
1.787 + if (this->_M_gcount == 0)
1.788 + this->setstate(ios_base::failbit);
1.789 +
1.790 + return *this;
1.791 +}
1.792 +
1.793 +// Read n characters. We don't look for any delimiter, and we don't
1.794 +// put in a terminating null character.
1.795 +template <class _CharT, class _Traits>
1.796 +basic_istream<_CharT, _Traits>&
1.797 +basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
1.798 +{
1.799 + sentry __sentry(*this, _No_Skip_WS());
1.800 + this->_M_gcount = 0;
1.801 +
1.802 + if (__sentry && !this->eof()) {
1.803 + basic_streambuf<_CharT, _Traits>*__buf = this->rdbuf();
1.804 + if (__buf->gptr() != __buf->egptr())
1.805 + _M_gcount
1.806 + = _M_read_buffered(this, __buf, __n, __s,
1.807 + _Constant_unary_fun<bool, int_type>(false),
1.808 + _Project2nd<const _CharT*, const _CharT*>(),
1.809 + false, false, false);
1.810 + else
1.811 + _M_gcount
1.812 + = _M_read_unbuffered(this, __buf, __n, __s,
1.813 + _Constant_unary_fun<bool, int_type>(false),
1.814 + false, false, false);
1.815 + }
1.816 + else
1.817 + this->setstate(ios_base::failbit);
1.818 +
1.819 + if (this->eof())
1.820 + this->setstate(ios_base::eofbit | ios_base::failbit);
1.821 +
1.822 + return *this;
1.823 +}
1.824 +
1.825 +
1.826 +// Read n or fewer characters. We don't look for any delimiter, and
1.827 +// we don't put in a terminating null character.
1.828 +template <class _CharT, class _Traits>
1.829 +streamsize
1.830 +basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax)
1.831 +{
1.832 + sentry __sentry(*this, _No_Skip_WS());
1.833 + this->_M_gcount = 0;
1.834 +
1.835 + if (__sentry && !this->eof() && __nmax >= 0) {
1.836 +
1.837 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.838 + streamsize __avail = __buf->in_avail();
1.839 +
1.840 + // fbp : isn't full-blown setstate required here ?
1.841 + if (__avail == -1)
1.842 + this->_M_setstate_nothrow(ios_base::eofbit);
1.843 +
1.844 + else if (__avail != 0) {
1.845 +
1.846 + if (__buf->gptr() != __buf->egptr())
1.847 + _M_gcount
1.848 + = _M_read_buffered(this, __buf, (min) (__avail, __nmax), __s,
1.849 + _Constant_unary_fun<bool, int_type>(false),
1.850 + _Project2nd<const _CharT*, const _CharT*>(),
1.851 + false, false, false);
1.852 + else
1.853 + _M_gcount
1.854 + = _M_read_unbuffered(this, __buf, (min) (__avail, __nmax), __s,
1.855 + _Constant_unary_fun<bool, int_type>(false),
1.856 + false, false, false);
1.857 + }
1.858 + }
1.859 + else {
1.860 + // fbp : changed so that failbit is set only there, to pass Dietmar's test
1.861 + if (this->eof())
1.862 + this->setstate(ios_base::eofbit | ios_base::failbit);
1.863 + else
1.864 + {
1.865 + if (__nmax < 0)
1.866 + {
1.867 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.868 + streamsize __avail = __buf->in_avail();
1.869 + if(__avail == -1)
1.870 + this->setstate(ios_base::eofbit);
1.871 + }
1.872 + else
1.873 + this->setstate(ios_base::failbit);
1.874 + }
1.875 + }
1.876 +
1.877 + // if (this->eof())
1.878 + // this->setstate(ios_base::eofbit | ios_base::failbit);
1.879 +
1.880 + return _M_gcount;
1.881 +}
1.882 +
1.883 +template <class _CharT, class _Traits>
1.884 +void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s)
1.885 +{
1.886 + sentry __sentry(*this); // Skip whitespace.
1.887 +
1.888 + if (__sentry) {
1.889 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.890 + streamsize __nmax = this->width() > 0
1.891 + ? this->width() - 1
1.892 + : (numeric_limits<streamsize>::max)() / sizeof(_CharT) - 1;
1.893 +
1.894 + streamsize __n = __buf->gptr() != __buf->egptr()
1.895 + ? _M_read_buffered(this, __buf, __nmax, __s,
1.896 + _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1.897 + _Scan_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1.898 + false, true, false)
1.899 + : _M_read_unbuffered(this, __buf, __nmax, __s,
1.900 + _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1.901 + false, true, false);
1.902 + if (__n == 0)
1.903 + this->setstate(ios_base::failbit);
1.904 + }
1.905 + this->width(0);
1.906 +}
1.907 +
1.908 +// A generic unbuffered function for ignoring characters. We stop
1.909 +// when we reach EOF, or when the function object __is_delim returns
1.910 +// true. In the last case, it extracts the character for which
1.911 +// __is_delim is true, if and only if __extract_delim is true.
1.912 +
1.913 +template < class _CharT, class _Traits, class _Is_Delim>
1.914 +void _STLP_CALL
1.915 +_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
1.916 + basic_streambuf<_CharT, _Traits>* __buf,
1.917 + _Is_Delim __is_delim,
1.918 + bool __extract_delim, bool __set_failbit)
1.919 +{
1.920 + bool __done = false;
1.921 + ios_base::iostate __status = 0;
1.922 + typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1.923 +
1.924 + _STLP_TRY {
1.925 +#ifdef __SYMBIAN32__
1.926 + int_type __c = __buf->sgetc();
1.927 + do {
1.928 +
1.929 + if (__that->_S_eof(__c)) {
1.930 + __done = true;
1.931 + __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
1.932 + : ios_base::eofbit;
1.933 + break;
1.934 + }
1.935 +
1.936 + else if (__is_delim(__c)) {
1.937 + __done = true;
1.938 + if (__extract_delim)
1.939 + __buf->snextc();
1.940 + break;
1.941 +
1.942 + }
1.943 + __c = __buf->snextc();
1.944 + } while(!__done);
1.945 +#else
1.946 + while (!__done) {
1.947 + int_type __c = __buf->sbumpc();
1.948 +
1.949 + if (__that->_S_eof(__c)) {
1.950 + __done = true;
1.951 + __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
1.952 + : ios_base::eofbit;
1.953 + }
1.954 +
1.955 + else if (__is_delim(__c)) {
1.956 + __done = true;
1.957 + if (!__extract_delim)
1.958 + if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
1.959 + __status |= ios_base::failbit;
1.960 + }
1.961 + }
1.962 +#endif
1.963 + }
1.964 + _STLP_CATCH_ALL {
1.965 + __that->_M_handle_exception(ios_base::badbit);
1.966 + }
1.967 +
1.968 + __that->setstate(__status);
1.969 +}
1.970 +
1.971 +// A generic buffered function for ignoring characters. Much like
1.972 +// _M_ignore_unbuffered, but with one additional function object:
1.973 +// __scan_delim(first, last) returns the first pointer p in [first,
1.974 +// last) such that __is_delim(p) is true.
1.975 +
1.976 +template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
1.977 +void _STLP_CALL
1.978 +_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
1.979 + basic_streambuf<_CharT, _Traits>* __buf,
1.980 + _Is_Delim __is_delim, _Scan_Delim __scan_delim,
1.981 + bool __extract_delim, bool __set_failbit)
1.982 +{
1.983 + bool __at_eof = false;
1.984 + bool __found_delim = false;
1.985 +
1.986 + _STLP_TRY {
1.987 + while (__buf->_M_egptr() != __buf->_M_gptr() && !__at_eof && !__found_delim) {
1.988 + const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
1.989 + __buf->_M_gbump((int)(__p - __buf->_M_gptr()));
1.990 +
1.991 + if (__p != __buf->_M_egptr()) { // We found delim, so we're done.
1.992 + if (__extract_delim)
1.993 + __buf->_M_gbump(1);
1.994 + __found_delim = true;
1.995 + }
1.996 +
1.997 + else // No delim. Try to refil the buffer.
1.998 + __at_eof = __that->_S_eof(__buf->sgetc());
1.999 + } // Close the while loop.
1.1000 + }
1.1001 + _STLP_CATCH_ALL {
1.1002 + __that->_M_handle_exception(ios_base::badbit);
1.1003 + return;
1.1004 + }
1.1005 +
1.1006 + if (__at_eof) {
1.1007 + __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
1.1008 + : ios_base::eofbit);
1.1009 + return;
1.1010 + }
1.1011 + if (__found_delim)
1.1012 + return;
1.1013 +
1.1014 + // If execution has reached this point, then we have an empty buffer but
1.1015 + // we have not reached eof. What that means is that the streambuf has
1.1016 + // decided to switch from a buffered to an unbuffered mode. We switch
1.1017 + // to _M_ignore_unbuffered.
1.1018 + _M_ignore_unbuffered(__that, __buf, __is_delim, __extract_delim, __set_failbit);
1.1019 +}
1.1020 +
1.1021 +// Overloaded versions of _M_ignore_unbuffered and _M_ignore_unbuffered
1.1022 +// with an explicit count _Num. Return value is the number of
1.1023 +// characters extracted.
1.1024 +//
1.1025 +// The function object __max_chars takes two arguments, _Num and __n
1.1026 +// (the latter being the number of characters we have already read),
1.1027 +// and returns the maximum number of characters to read from the buffer.
1.1028 +// We parameterize _M_ignore_buffered so that we can use it for both
1.1029 +// bounded and unbounded input; for the former the function object should
1.1030 +// be minus<>, and for the latter it should return a constant maximum value.
1.1031 +
1.1032 +template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim>
1.1033 +streamsize _STLP_CALL
1.1034 +_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
1.1035 + basic_streambuf<_CharT, _Traits>* __buf,
1.1036 + streamsize _Num, _Max_Chars __max_chars,
1.1037 + _Is_Delim __is_delim,
1.1038 + bool __extract_delim, bool __set_failbit)
1.1039 +{
1.1040 + streamsize __n = 0;
1.1041 + ios_base::iostate __status = 0;
1.1042 + typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1.1043 +
1.1044 + _STLP_TRY {
1.1045 + while (__max_chars(_Num, __n) > 0) {
1.1046 + int_type __c = __buf->sbumpc();
1.1047 +
1.1048 + if (__that->_S_eof(__c)) {
1.1049 + __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
1.1050 + : ios_base::eofbit;
1.1051 + break;
1.1052 + }
1.1053 +
1.1054 + else if (__is_delim(__c)) {
1.1055 + if (__extract_delim)
1.1056 + ++__n;
1.1057 + else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
1.1058 + __status |= ios_base::failbit;
1.1059 +
1.1060 + break;
1.1061 + }
1.1062 + // fbp : added counter increment to pass Dietmar's test
1.1063 + ++__n;
1.1064 + }
1.1065 + }
1.1066 + _STLP_CATCH_ALL {
1.1067 + __that->_M_handle_exception(ios_base::badbit);
1.1068 + }
1.1069 +
1.1070 + if (__status)
1.1071 + __that->setstate(__status); // This might throw.
1.1072 + return __n;
1.1073 +}
1.1074 +
1.1075 +template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim, class _Scan_Delim>
1.1076 +streamsize _STLP_CALL
1.1077 +_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
1.1078 + basic_streambuf<_CharT, _Traits>* __buf,
1.1079 + streamsize _Num,
1.1080 + _Max_Chars __max_chars,
1.1081 + _Is_Delim __is_delim, _Scan_Delim __scan_delim,
1.1082 + bool __extract_delim, bool __set_failbit)
1.1083 +{
1.1084 + streamsize __n = 0;
1.1085 + bool __at_eof = false;
1.1086 + bool __done = false;
1.1087 +
1.1088 + _STLP_TRY {
1.1089 + while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
1.1090 + ptrdiff_t __avail = __buf->_M_egptr() - __buf->_M_gptr();
1.1091 + streamsize __m = __max_chars(_Num, __n);
1.1092 +
1.1093 + if (__avail >= __m) { // We have more characters than we need.
1.1094 + const _CharT* __last = __buf->_M_gptr() + __m;
1.1095 + const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last);
1.1096 + ptrdiff_t __chunk = __p - __buf->_M_gptr();
1.1097 + __n += __chunk;
1.1098 + __buf->_M_gbump((int)__chunk);
1.1099 +
1.1100 + if (__extract_delim && __p != __last) {
1.1101 + __n += 1;
1.1102 + __buf->_M_gbump(1);
1.1103 + }
1.1104 +
1.1105 + __done = true;
1.1106 + }
1.1107 +
1.1108 + else {
1.1109 + const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
1.1110 + ptrdiff_t __chunk = __p - __buf->_M_gptr();
1.1111 + __n += __chunk;
1.1112 + __buf->_M_gbump((int)__chunk);
1.1113 +
1.1114 + if (__p != __buf->_M_egptr()) { // We found delim.
1.1115 + if (__extract_delim) {
1.1116 + __n += 1;
1.1117 + __buf->_M_gbump(1);
1.1118 + }
1.1119 +
1.1120 + __done = true;
1.1121 + }
1.1122 +
1.1123 + // We didn't find delim. Try to refill the buffer.
1.1124 + else if (__that->_S_eof(__buf->sgetc())) {
1.1125 + __done = true;
1.1126 + __at_eof = true;
1.1127 + }
1.1128 + }
1.1129 + } // Close the while loop.
1.1130 + }
1.1131 + _STLP_CATCH_ALL {
1.1132 + __that->_M_handle_exception(ios_base::badbit);
1.1133 + return __n;
1.1134 + }
1.1135 +
1.1136 + if (__at_eof)
1.1137 + __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
1.1138 + : ios_base::eofbit);
1.1139 +
1.1140 + if (__done)
1.1141 + return __n;
1.1142 +
1.1143 + // If execution has reached this point, then we have an empty buffer but
1.1144 + // we have not reached eof. What that means is that the streambuf has
1.1145 + // decided to switch from buffered to unbuffered input. We switch to
1.1146 + // to _M_ignore_unbuffered.
1.1147 +
1.1148 + return __n + _M_ignore_unbuffered( __that, __buf, _Num, __max_chars,
1.1149 + __is_delim, __extract_delim, __set_failbit);
1.1150 +}
1.1151 +
1.1152 +
1.1153 +template <class _CharT, class _Traits>
1.1154 +basic_istream<_CharT, _Traits>&
1.1155 +basic_istream<_CharT, _Traits>::ignore(streamsize __n)
1.1156 +{
1.1157 + sentry __sentry(*this, _No_Skip_WS());
1.1158 + this->_M_gcount = 0;
1.1159 +
1.1160 + if (__sentry) {
1.1161 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.1162 + typedef _Constant_unary_fun<bool, int_type> _Const_bool;
1.1163 + typedef _Constant_binary_fun<streamsize, streamsize, streamsize>
1.1164 + _Const_streamsize;
1.1165 + const streamsize __maxss = (numeric_limits<streamsize>::max)();
1.1166 +
1.1167 + if (__n == (numeric_limits<int>::max)()) {
1.1168 + if (__buf->gptr() != __buf->egptr())
1.1169 + _M_gcount
1.1170 + = _M_ignore_buffered(this, __buf,
1.1171 + __maxss, _Const_streamsize(__maxss),
1.1172 + _Const_bool(false),
1.1173 + _Project2nd<const _CharT*, const _CharT*>(),
1.1174 + false, false);
1.1175 + else
1.1176 + _M_gcount = _M_ignore_unbuffered(this, __buf,
1.1177 + __maxss, _Const_streamsize(__maxss),
1.1178 + _Const_bool(false), false, false);
1.1179 + }
1.1180 + else {
1.1181 + if (__buf->gptr() != __buf->egptr())
1.1182 + _M_gcount
1.1183 + = _M_ignore_buffered(this, __buf,
1.1184 + __n, minus<streamsize>(),
1.1185 + _Const_bool(false),
1.1186 + _Project2nd<const _CharT*, const _CharT*>(),
1.1187 + false, false);
1.1188 + else
1.1189 + _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(),
1.1190 + _Const_bool(false), false, false);
1.1191 + }
1.1192 + }
1.1193 +
1.1194 + return *this;
1.1195 +}
1.1196 +
1.1197 +template <class _CharT, class _Traits>
1.1198 +basic_istream<_CharT, _Traits>&
1.1199 +basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim)
1.1200 +{
1.1201 + sentry __sentry(*this, _No_Skip_WS());
1.1202 + this->_M_gcount = 0;
1.1203 +
1.1204 + if (__sentry) {
1.1205 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.1206 + typedef _Constant_unary_fun<bool, int_type> _Const_bool;
1.1207 + typedef _Constant_binary_fun<streamsize, streamsize, streamsize>
1.1208 + _Const_streamsize;
1.1209 + const streamsize __maxss = (numeric_limits<streamsize>::max)();
1.1210 +
1.1211 + if (__n == (numeric_limits<int>::max)()) {
1.1212 + if (__buf->gptr() != __buf->egptr())
1.1213 + _M_gcount = _M_ignore_buffered(this, __buf,
1.1214 + __maxss, _Const_streamsize(__maxss),
1.1215 + _Eq_int_bound<_Traits>(__delim),
1.1216 + _Scan_for_int_val<_Traits>(__delim),
1.1217 + true, false);
1.1218 + else
1.1219 + _M_gcount = _M_ignore_unbuffered(this, __buf,
1.1220 + __maxss, _Const_streamsize(__maxss),
1.1221 + _Eq_int_bound<_Traits>(__delim),
1.1222 + true, false);
1.1223 + }
1.1224 + else {
1.1225 + if (__buf->gptr() != __buf->egptr())
1.1226 + _M_gcount = _M_ignore_buffered(this, __buf,
1.1227 + __n, minus<streamsize>(),
1.1228 + _Eq_int_bound<_Traits>(
1.1229 + __delim),
1.1230 + _Scan_for_int_val<_Traits>(__delim),
1.1231 + true, false);
1.1232 + else
1.1233 + _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(),
1.1234 + _Eq_int_bound<_Traits>(__delim),
1.1235 + true, false);
1.1236 + }
1.1237 + }
1.1238 +
1.1239 + return *this;
1.1240 +}
1.1241 +
1.1242 +// This member function does not construct a sentry object, because
1.1243 +// it is called from sentry's constructor.
1.1244 +template <class _CharT, class _Traits>
1.1245 +void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit)
1.1246 +{
1.1247 + basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1.1248 + if (!__buf)
1.1249 + this->setstate(ios_base::badbit);
1.1250 + else if (__buf->gptr() != __buf->egptr())
1.1251 + _M_ignore_buffered(this, __buf,
1.1252 + _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1.1253 + _Scan_for_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1.1254 + false, __set_failbit);
1.1255 + else
1.1256 + _M_ignore_unbuffered(this, __buf,
1.1257 + _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1.1258 + false, __set_failbit);
1.1259 +}
1.1260 +
1.1261 +
1.1262 +// This is a very simple loop that reads characters from __src and puts
1.1263 +// them into __dest. It looks complicated because of the (standard-
1.1264 +// mandated) exception handling policy.
1.1265 +//
1.1266 +// We stop when we get an exception, when we fail to insert into the
1.1267 +// output streambuf, or when __is_delim is true.
1.1268 +
1.1269 +template < class _CharT, class _Traits, class _Is_Delim>
1.1270 +streamsize _STLP_CALL
1.1271 +_M_copy_unbuffered( basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
1.1272 + basic_streambuf<_CharT, _Traits>* __dest,
1.1273 + _Is_Delim __is_delim,
1.1274 + bool __extract_delim, bool __rethrow)
1.1275 +{
1.1276 + streamsize __extracted = 0;
1.1277 + ios_base::iostate __status = 0;
1.1278 + typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1.1279 + int_type __c;
1.1280 +
1.1281 + _STLP_TRY {
1.1282 +#ifdef __SYMBIAN32__
1.1283 + __c = __src->sgetc();
1.1284 + for(;; __c = __src->snextc()){
1.1285 +
1.1286 + // If we failed to get a character, then quit.
1.1287 + if (__that->_S_eof(__c)) {
1.1288 + __status |= ios_base::eofbit;
1.1289 + break;
1.1290 + }
1.1291 + // If it's the delimiter, then quit.
1.1292 + else if (__is_delim(__c)) {
1.1293 + if (!__extract_delim)
1.1294 + __status |= ios_base::failbit;
1.1295 + break;
1.1296 + }
1.1297 +
1.1298 + else {
1.1299 +
1.1300 + // Try to put the character in the output streambuf.
1.1301 + _STLP_TRY {
1.1302 + if (!__that->_S_eof(__dest->sputc(__c)))
1.1303 + ++__extracted;
1.1304 + else
1.1305 + break;
1.1306 + }
1.1307 + _STLP_CATCH_ALL {
1.1308 + __status |= ios_base::failbit;
1.1309 + break;
1.1310 + }
1.1311 +
1.1312 + }
1.1313 +
1.1314 + } /* while (true) */
1.1315 +#else
1.1316 + while (true) {
1.1317 +
1.1318 + // Get a character. If there's an exception, catch and (maybe) rethrow it.
1.1319 + __c = __src->sbumpc();
1.1320 +
1.1321 + // If we failed to get a character, then quit.
1.1322 + if (__that->_S_eof(__c)) {
1.1323 + __status |= ios_base::eofbit;
1.1324 + break;
1.1325 + }
1.1326 + // If it's the delimiter, then quit.
1.1327 + else if (__is_delim(__c)) {
1.1328 + if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c)))
1.1329 + __status |= ios_base::failbit;
1.1330 + break;
1.1331 + }
1.1332 +
1.1333 + else {
1.1334 +
1.1335 + // Try to put the character in the output streambuf.
1.1336 + bool __failed = false;
1.1337 + _STLP_TRY {
1.1338 + if (!__that->_S_eof(__dest->sputc(__c)))
1.1339 + ++__extracted;
1.1340 + else
1.1341 + __failed = true;
1.1342 + }
1.1343 + _STLP_CATCH_ALL {
1.1344 + __failed = true;
1.1345 + }
1.1346 +
1.1347 + // If we failed to put the character in the output streambuf, then
1.1348 + // try to push it back to the input streambuf.
1.1349 + if (__failed && !__pushback(__src, _Traits::to_char_type(__c)))
1.1350 + __status |= ios_base::failbit;
1.1351 +
1.1352 + // fbp : avoiding infinite loop in io-27-6-1-2-3.exp
1.1353 + if (__failed)
1.1354 + break;
1.1355 + }
1.1356 +
1.1357 + } /* while (true) */
1.1358 +#endif
1.1359 + }
1.1360 + // fbp : this try/catch moved here in reasonable assumption
1.1361 + // __is_delim never throw (__pushback is guaranteed not to)
1.1362 + _STLP_CATCH_ALL {
1.1363 + // See 27.6.1.2.3, paragraph 13.
1.1364 + if (__rethrow && __extracted == 0)
1.1365 + __that->_M_handle_exception(ios_base::failbit);
1.1366 + }
1.1367 + __that->setstate(__status);
1.1368 + return __extracted;
1.1369 +}
1.1370 +
1.1371 +// Buffered copying from one streambuf to another. We copy the characters
1.1372 +// in chunks, rather than one at a time. We still have to worry about all
1.1373 +// of the error conditions we checked in _M_copy_unbuffered, plus one more:
1.1374 +// the streambuf might decide to switch from a buffered to an unbuffered mode.
1.1375 +
1.1376 +template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
1.1377 +streamsize _STLP_CALL
1.1378 +_M_copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
1.1379 + basic_streambuf<_CharT, _Traits>* __dest,
1.1380 + _Scan_Delim __scan_delim, _Is_Delim __is_delim,
1.1381 + bool __extract_delim, bool __rethrow)
1.1382 +{
1.1383 + streamsize __extracted = 0;
1.1384 + ios_base::iostate __status = 0;
1.1385 + typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1.1386 + int_type __c = _Traits::eof();
1.1387 + _CharT* __first = __src->_M_gptr();
1.1388 + ptrdiff_t __avail = __src->_M_egptr() - __first;
1.1389 + // fbp : introduced to move catch/try blocks out of the loop
1.1390 + bool __do_handle_exceptions;
1.1391 +
1.1392 + _STLP_TRY {
1.1393 + while (true) {
1.1394 + __do_handle_exceptions = false ;
1.1395 + const _CharT* __last = __scan_delim(__first, __src->_M_egptr());
1.1396 +
1.1397 + // Try to copy the entire input buffer to the output buffer.
1.1398 + streamsize __n = __dest->sputn(__first, __extract_delim && __last != __src->_M_egptr()
1.1399 + ? (__last - __first) + 1
1.1400 + : (__last - __first));
1.1401 + __src->_M_gbump((int)__n);
1.1402 + __extracted += __n;
1.1403 +
1.1404 + // from this on, catch() will call _M_handle_exceptions()
1.1405 + __do_handle_exceptions = true;
1.1406 +
1.1407 + if (__n < __avail) // We found the delimiter, or else failed to
1.1408 + break; // copy some characters.
1.1409 +
1.1410 + __c = __src->sgetc();
1.1411 +
1.1412 + // Three possibilities: we succeeded in refilling the buffer, or
1.1413 + // we got EOF, or the streambuf has switched to unbuffered mode.
1.1414 + __first = __src->_M_gptr();
1.1415 + __avail = __src->_M_egptr() - __first;
1.1416 +
1.1417 + if (__avail > 0)
1.1418 + {} // dwa 1/16/00 -- suppress a Metrowerks warning
1.1419 + else if (__that->_S_eof(__c)) {
1.1420 + __status |= ios_base::eofbit;
1.1421 + break;
1.1422 + }
1.1423 + else
1.1424 + return __extracted + _M_copy_unbuffered(__that, __src, __dest, __is_delim,
1.1425 + __extract_delim, __rethrow);
1.1426 + } /* while */
1.1427 + }
1.1428 +
1.1429 + _STLP_CATCH_ALL {
1.1430 + // See 27.6.1.2.3, paragraph 13.
1.1431 + if (__rethrow && __do_handle_exceptions && __extracted == 0)
1.1432 + __that->_M_handle_exception(ios_base::failbit);
1.1433 + }
1.1434 +
1.1435 + if (__status)
1.1436 + __that->setstate(__status); // This might throw.
1.1437 + return __extracted;
1.1438 +}
1.1439 +
1.1440 +
1.1441 +
1.1442 +template <class _CharT, class _Traits>
1.1443 +basic_istream<_CharT, _Traits>&
1.1444 +basic_istream<_CharT, _Traits>
1.1445 + ::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim)
1.1446 +{
1.1447 + sentry __sentry(*this, _No_Skip_WS());
1.1448 + this->_M_gcount = 0;
1.1449 +
1.1450 + if (__sentry) {
1.1451 + basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
1.1452 +
1.1453 + if (__src)
1.1454 + this->_M_gcount = __src->egptr() != __src->gptr()
1.1455 + ? _M_copy_buffered(this, __src, &__dest,
1.1456 + _Scan_for_char_val<_Traits>(__delim),
1.1457 + _Eq_char_bound<_Traits>(__delim),
1.1458 + false, false)
1.1459 + : _M_copy_unbuffered(this, __src, &__dest,
1.1460 + _Eq_char_bound<_Traits>(__delim),
1.1461 + false, false);
1.1462 + }
1.1463 +
1.1464 + if (this->_M_gcount == 0)
1.1465 + this->setstate(ios_base::failbit);
1.1466 +
1.1467 + return *this;
1.1468 +}
1.1469 +
1.1470 +// Copying characters into a streambuf.
1.1471 +template <class _CharT, class _Traits>
1.1472 +basic_istream<_CharT, _Traits>&
1.1473 +basic_istream<_CharT, _Traits>
1.1474 + ::operator>>(basic_streambuf<_CharT, _Traits>* __dest)
1.1475 +{
1.1476 + streamsize __n = 0;
1.1477 + typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
1.1478 + _Sentry __sentry(*this);
1.1479 + if (__sentry) {
1.1480 + basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
1.1481 + if (__src && __dest)
1.1482 + __n = __src->egptr() != __src->gptr()
1.1483 + ? _M_copy_buffered(this, __src, __dest,
1.1484 + _Project2nd<const _CharT*, const _CharT*>(),
1.1485 + _Constant_unary_fun<bool, int_type>(false),
1.1486 + false, true)
1.1487 + : _M_copy_unbuffered(this, __src, __dest,
1.1488 + _Constant_unary_fun<bool, int_type>(false),
1.1489 + false, true);
1.1490 + }
1.1491 +
1.1492 + if (__n == 0)
1.1493 + this->setstate(ios_base::failbit);
1.1494 +
1.1495 + return *this;
1.1496 +}
1.1497 +
1.1498 +// ----------------------------------------------------------------
1.1499 +// basic_iostream<> class
1.1500 +// ----------------------------------------------------------------
1.1501 +
1.1502 +template <class _CharT, class _Traits>
1.1503 +_STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits>
1.1504 + ::basic_iostream(basic_streambuf<_CharT, _Traits>* __buf)
1.1505 + : basic_ios<_CharT, _Traits>(),
1.1506 + basic_istream<_CharT, _Traits>(__buf),
1.1507 + basic_ostream<_CharT, _Traits>(__buf)
1.1508 +{
1.1509 + this->init(__buf);
1.1510 +}
1.1511 +
1.1512 +template <class _CharT, class _Traits>
1.1513 +_STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits>::~basic_iostream()
1.1514 +{}
1.1515 +
1.1516 +
1.1517 +template <class _CharT, class _Traits>
1.1518 +_STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits>
1.1519 + ::basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
1.1520 + basic_ios<_CharT, _Traits>(), _M_gcount(0) {
1.1521 + this->init(__buf);
1.1522 + }
1.1523 +
1.1524 +template <class _CharT, class _Traits>
1.1525 +_STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits>
1.1526 + ::~basic_istream() {}
1.1527 +
1.1528 +
1.1529 +
1.1530 +_STLP_END_NAMESPACE
1.1531 +
1.1532 +# undef __BIS_int_type__
1.1533 +# undef __BIS_pos_type__
1.1534 +# undef __BIS_off_type__
1.1535 +
1.1536 +# endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
1.1537 +
1.1538 +#endif /* _STLP_ISTREAM_C */