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