epoc32/include/stdapis/stlport/stl/_istream.c
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
 * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
williamr@4
     3
 * Copyright (c) 1999
williamr@4
     4
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     5
 *
williamr@4
     6
 * Copyright (c) 1999
williamr@4
     7
 * Boris Fomitchev
williamr@4
     8
 *
williamr@4
     9
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
    10
 * or implied. Any use is at your own risk.
williamr@4
    11
 *
williamr@4
    12
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    13
 * without fee, provided the above notices are retained on all copies.
williamr@4
    14
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    15
 * provided the above notices are retained, and a notice that the code was
williamr@4
    16
 * modified is included with the above copyright notice.
williamr@4
    17
 *
williamr@4
    18
 */
williamr@4
    19
#ifndef _STLP_ISTREAM_C
williamr@4
    20
#define _STLP_ISTREAM_C
williamr@4
    21
williamr@4
    22
#ifndef _STLP_INTERNAL_ISTREAM_H
williamr@4
    23
# include <stl/_istream.h>
williamr@4
    24
#endif
williamr@4
    25
williamr@4
    26
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
williamr@4
    27
williamr@4
    28
#ifndef _STLP_LIMITS_H
williamr@4
    29
# include <stl/_limits.h>
williamr@4
    30
#endif
williamr@4
    31
williamr@4
    32
#ifndef _STLP_INTERNAL_NUM_GET_H
williamr@4
    33
# include <stl/_num_get.h>
williamr@4
    34
#endif
williamr@4
    35
williamr@4
    36
# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
williamr@4
    37
// no wchar_t is supported for this mode
williamr@4
    38
# define __BIS_int_type__ int
williamr@4
    39
# define __BIS_pos_type__ streampos
williamr@4
    40
# define __BIS_off_type__ streamoff
williamr@4
    41
# else
williamr@4
    42
# define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type
williamr@4
    43
# define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type
williamr@4
    44
# define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type
williamr@4
    45
# endif
williamr@4
    46
williamr@4
    47
_STLP_BEGIN_NAMESPACE
williamr@4
    48
williamr@4
    49
//----------------------------------------------------------------------
williamr@4
    50
// Function object structs used by some member functions.
williamr@4
    51
williamr@4
    52
template <class _Traits>
williamr@4
    53
struct _Is_not_wspace {
williamr@4
    54
  typedef typename _Traits::char_type argument_type;
williamr@4
    55
  typedef bool                        result_type;
williamr@4
    56
williamr@4
    57
  const ctype<argument_type>* _M_ctype;
williamr@4
    58
williamr@4
    59
  _Is_not_wspace(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
williamr@4
    60
  bool operator()(argument_type __c) const
williamr@4
    61
    { return !_M_ctype->is(ctype_base::space, __c); }
williamr@4
    62
};
williamr@4
    63
williamr@4
    64
template <class _Traits>
williamr@4
    65
struct _Is_wspace_null {
williamr@4
    66
  typedef typename _Traits::char_type argument_type;
williamr@4
    67
  typedef bool                        result_type;
williamr@4
    68
williamr@4
    69
  const ctype<argument_type>* _M_ctype;
williamr@4
    70
williamr@4
    71
  _Is_wspace_null(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
williamr@4
    72
  bool operator()(argument_type __c) const {
williamr@4
    73
    return _Traits::eq(__c, argument_type()) ||
williamr@4
    74
           _M_ctype->is(ctype_base::space, __c);
williamr@4
    75
  }
williamr@4
    76
};
williamr@4
    77
williamr@4
    78
template <class _Traits>
williamr@4
    79
struct _Scan_for_wspace {
williamr@4
    80
  typedef typename _Traits::char_type  char_type;
williamr@4
    81
  typedef char_type*                   first_argument_type;
williamr@4
    82
  typedef char_type*                   second_argument_type;
williamr@4
    83
  typedef char_type*                   result_type;
williamr@4
    84
williamr@4
    85
  const ctype<char_type>* _M_ctype;
williamr@4
    86
williamr@4
    87
  _Scan_for_wspace(const ctype<char_type>* __ctype) : _M_ctype(__ctype) {}
williamr@4
    88
  const char_type*
williamr@4
    89
  operator()(const char_type* __first, const char_type* __last) const {
williamr@4
    90
    return _M_ctype->scan_is(ctype_base::space, __first, __last);
williamr@4
    91
  }
williamr@4
    92
};
williamr@4
    93
williamr@4
    94
template <class _Traits>
williamr@4
    95
struct _Scan_wspace_null {
williamr@4
    96
  typedef typename _Traits::char_type  char_type;
williamr@4
    97
  typedef char_type*                   first_argument_type;
williamr@4
    98
  typedef char_type*                   second_argument_type;
williamr@4
    99
  typedef char_type*                   result_type;
williamr@4
   100
williamr@4
   101
  const ctype<char_type>* _M_ctype;
williamr@4
   102
williamr@4
   103
  _Scan_wspace_null(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
williamr@4
   104
  const char_type*
williamr@4
   105
  operator()(const char_type* __first, const char_type* __last) const {
williamr@4
   106
    __last = find_if(__first, __last,
williamr@4
   107
                     _Eq_char_bound<_Traits>(char_type()));
williamr@4
   108
    return _M_ctype->scan_is(ctype_base::space, __first, __last);
williamr@4
   109
  }
williamr@4
   110
};
williamr@4
   111
williamr@4
   112
template <class _Traits>
williamr@4
   113
struct _Scan_for_not_wspace {
williamr@4
   114
  typedef typename _Traits::char_type  char_type;
williamr@4
   115
  typedef char_type*                   first_argument_type;
williamr@4
   116
  typedef char_type*                   second_argument_type;
williamr@4
   117
  typedef char_type*                   result_type;
williamr@4
   118
williamr@4
   119
  const ctype<char_type>* _M_ctype;
williamr@4
   120
williamr@4
   121
  _Scan_for_not_wspace(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
williamr@4
   122
  const char_type*
williamr@4
   123
  operator()(const char_type* __first, const char_type* __last) const {
williamr@4
   124
    return _M_ctype->scan_not(ctype_base::space, __first, __last);
williamr@4
   125
  }
williamr@4
   126
};
williamr@4
   127
williamr@4
   128
template <class _Traits>
williamr@4
   129
struct _Scan_for_char_val
williamr@4
   130
{
williamr@4
   131
  typedef typename _Traits::char_type char_type;
williamr@4
   132
  typedef char_type*                  first_argument_type;
williamr@4
   133
  typedef char_type*                  second_argument_type;
williamr@4
   134
  typedef char_type*                  result_type;
williamr@4
   135
williamr@4
   136
  char_type _M_val;
williamr@4
   137
williamr@4
   138
  _Scan_for_char_val(char_type __val) : _M_val(__val) {}
williamr@4
   139
williamr@4
   140
  const char_type*
williamr@4
   141
  operator()(const char_type* __first, const char_type* __last) const {
williamr@4
   142
    return find_if(__first, __last, _Eq_char_bound<_Traits>(_M_val));
williamr@4
   143
  }
williamr@4
   144
};
williamr@4
   145
williamr@4
   146
template <class _Traits>
williamr@4
   147
struct _Scan_for_int_val
williamr@4
   148
{
williamr@4
   149
  typedef typename _Traits::char_type char_type;
williamr@4
   150
  typedef typename _Traits::int_type  int_type;
williamr@4
   151
  typedef char_type*                  first_argument_type;
williamr@4
   152
  typedef char_type*                  second_argument_type;
williamr@4
   153
  typedef char_type*                  result_type;
williamr@4
   154
williamr@4
   155
  int_type _M_val;
williamr@4
   156
williamr@4
   157
  _Scan_for_int_val(int_type __val) : _M_val(__val) {}
williamr@4
   158
williamr@4
   159
  const char_type*
williamr@4
   160
  operator()(const char_type* __first, const char_type* __last) const {
williamr@4
   161
    return find_if(__first, __last,
williamr@4
   162
                   _Eq_int_bound<_Traits>(_M_val));
williamr@4
   163
  }
williamr@4
   164
};
williamr@4
   165
williamr@4
   166
// Helper function: try to push back a character to a streambuf,
williamr@4
   167
// return true if the pushback succeeded.  Does not throw.
williamr@4
   168
williamr@4
   169
template <class _CharT, class _Traits>
williamr@4
   170
bool _STLP_CALL
williamr@4
   171
__pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c)
williamr@4
   172
{
williamr@4
   173
  bool ret;
williamr@4
   174
  _STLP_TRY {
williamr@4
   175
    const typename _Traits::int_type __eof = _Traits::eof();
williamr@4
   176
    ret = !_Traits::eq_int_type(__buf->sputbackc(__c), __eof);
williamr@4
   177
  }
williamr@4
   178
  _STLP_CATCH_ALL {
williamr@4
   179
    ret = false;
williamr@4
   180
  }
williamr@4
   181
  return ret;
williamr@4
   182
}
williamr@4
   183
williamr@4
   184
template <class _CharT, class _Traits>
williamr@4
   185
basic_istream<_CharT, _Traits>& _STLP_CALL
williamr@4
   186
ws(basic_istream<_CharT, _Traits>& __is)
williamr@4
   187
{
williamr@4
   188
  typedef typename basic_istream<_CharT, _Traits>::sentry      _Sentry;
williamr@4
   189
  _Sentry __sentry(__is, _No_Skip_WS()); // Don't skip whitespace.
williamr@4
   190
  if (__sentry)
williamr@4
   191
    __is._M_skip_whitespace(false);
williamr@4
   192
  return __is;
williamr@4
   193
}
williamr@4
   194
williamr@4
   195
// Helper functions for istream<>::sentry constructor.
williamr@4
   196
template <class _CharT, class _Traits>
williamr@4
   197
bool
williamr@4
   198
_M_init_skip(basic_istream<_CharT, _Traits>& __is) {
williamr@4
   199
  if (__is.good()) {
williamr@4
   200
    if (__is.tie())
williamr@4
   201
      __is.tie()->flush();
williamr@4
   202
williamr@4
   203
    __is._M_skip_whitespace(true);
williamr@4
   204
  }
williamr@4
   205
williamr@4
   206
  if (!__is.good()) {
williamr@4
   207
    __is.setstate(ios_base::failbit);
williamr@4
   208
    return false;
williamr@4
   209
  } else
williamr@4
   210
    return true;
williamr@4
   211
}
williamr@4
   212
williamr@4
   213
template <class _CharT, class _Traits>
williamr@4
   214
bool
williamr@4
   215
_M_init_noskip(basic_istream<_CharT, _Traits>& __is){
williamr@4
   216
  if (__is.good()) {
williamr@4
   217
    if (__is.tie())
williamr@4
   218
      __is.tie()->flush();
williamr@4
   219
williamr@4
   220
    if (!__is.rdbuf())
williamr@4
   221
      __is.setstate(ios_base::badbit);
williamr@4
   222
  }
williamr@4
   223
  else
williamr@4
   224
    __is.setstate(ios_base::failbit);
williamr@4
   225
  return __is.good();
williamr@4
   226
}
williamr@4
   227
williamr@4
   228
//----------------------------------------------------------------------
williamr@4
   229
// Definitions of basic_istream<>'s noninline member functions.
williamr@4
   230
williamr@4
   231
// Helper function for formatted input of numbers.
williamr@4
   232
template <class _CharT, class _Traits, class _Number>
williamr@4
   233
ios_base::iostate _STLP_CALL
williamr@4
   234
_M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val)
williamr@4
   235
{
williamr@4
   236
  typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
williamr@4
   237
  ios_base::iostate __err = 0;
williamr@4
   238
  _Sentry __sentry( __that );     // Skip whitespace.
williamr@4
   239
  if (__sentry) {
williamr@4
   240
    typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > _Num_get;
williamr@4
   241
    _STLP_TRY {
williamr@4
   242
      ((const _Num_get&)use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()),
williamr@4
   243
					0, __that, __err, __val);
williamr@4
   244
    }
williamr@4
   245
    _STLP_CATCH_ALL {
williamr@4
   246
      __that._M_handle_exception(ios_base::badbit);
williamr@4
   247
    }
williamr@4
   248
    if (__err) __that.setstate(__err);
williamr@4
   249
  }
williamr@4
   250
  return __err;
williamr@4
   251
}
williamr@4
   252
williamr@4
   253
williamr@4
   254
// Unformatted input
williamr@4
   255
williamr@4
   256
template <class _CharT, class _Traits>
williamr@4
   257
__BIS_int_type__
williamr@4
   258
basic_istream<_CharT, _Traits>::peek()
williamr@4
   259
{
williamr@4
   260
  typename _Traits::int_type __tmp = _Traits::eof();
williamr@4
   261
williamr@4
   262
  this->_M_gcount = 0;
williamr@4
   263
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   264
williamr@4
   265
  if (__sentry) {
williamr@4
   266
    _STLP_TRY {
williamr@4
   267
      __tmp = this->rdbuf()->sgetc();
williamr@4
   268
    }
williamr@4
   269
    _STLP_CATCH_ALL {
williamr@4
   270
      this->_M_handle_exception(ios_base::badbit);
williamr@4
   271
    }
williamr@4
   272
  }
williamr@4
   273
  else
williamr@4
   274
  {
williamr@4
   275
    if (this->_S_eof(__tmp))
williamr@4
   276
    {
williamr@4
   277
      this->clear();
williamr@4
   278
      this->setstate(ios_base::eofbit);
williamr@4
   279
    }
williamr@4
   280
  }
williamr@4
   281
  return __tmp;
williamr@4
   282
}
williamr@4
   283
williamr@4
   284
williamr@4
   285
template <class _CharT, class _Traits>
williamr@4
   286
__BIS_int_type__
williamr@4
   287
basic_istream<_CharT, _Traits>::get()
williamr@4
   288
{
williamr@4
   289
  typename _Traits::int_type __tmp = _Traits::eof();
williamr@4
   290
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   291
  this->_M_gcount = 0;
williamr@4
   292
williamr@4
   293
  if (__sentry) {
williamr@4
   294
    _STLP_TRY {
williamr@4
   295
      __tmp = this->rdbuf()->sbumpc();
williamr@4
   296
    }
williamr@4
   297
    _STLP_CATCH_ALL {
williamr@4
   298
      this->_M_handle_exception(ios_base::badbit);
williamr@4
   299
    }
williamr@4
   300
williamr@4
   301
    if (!this->_S_eof(__tmp))
williamr@4
   302
      this->_M_gcount = 1;
williamr@4
   303
  }
williamr@4
   304
williamr@4
   305
  if (_M_gcount == 0)
williamr@4
   306
    this->setstate(ios_base::eofbit | ios_base::failbit);
williamr@4
   307
williamr@4
   308
  return __tmp;
williamr@4
   309
}
williamr@4
   310
williamr@4
   311
template <class _CharT, class _Traits>
williamr@4
   312
basic_istream<_CharT, _Traits>&
williamr@4
   313
basic_istream<_CharT, _Traits>::get(_CharT& __c)
williamr@4
   314
{
williamr@4
   315
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   316
  this->_M_gcount = 0;
williamr@4
   317
williamr@4
   318
  if (__sentry) {
williamr@4
   319
    typename _Traits::int_type __tmp = _Traits::eof();
williamr@4
   320
    _STLP_TRY {
williamr@4
   321
      __tmp = this->rdbuf()->sbumpc();
williamr@4
   322
    }
williamr@4
   323
    _STLP_CATCH_ALL {
williamr@4
   324
      this->_M_handle_exception(ios_base::badbit);
williamr@4
   325
    }
williamr@4
   326
williamr@4
   327
    if (!this->_S_eof(__tmp)) {
williamr@4
   328
      this->_M_gcount = 1;
williamr@4
   329
      __c = _Traits::to_char_type(__tmp);
williamr@4
   330
    }
williamr@4
   331
  }
williamr@4
   332
williamr@4
   333
  if (this->_M_gcount == 0)
williamr@4
   334
    this->setstate(ios_base::eofbit | ios_base::failbit);
williamr@4
   335
williamr@4
   336
  return *this;
williamr@4
   337
}
williamr@4
   338
williamr@4
   339
williamr@4
   340
williamr@4
   341
// Read characters and discard them.  The standard specifies a single
williamr@4
   342
// function with two arguments, each with a default.  We instead use
williamr@4
   343
// three overloded functions, because it's possible to implement the
williamr@4
   344
// first two more efficiently than the fully general third version.
williamr@4
   345
template <class _CharT, class _Traits>
williamr@4
   346
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore()
williamr@4
   347
{
williamr@4
   348
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   349
  this->_M_gcount = 0;
williamr@4
   350
williamr@4
   351
  if (__sentry) {
williamr@4
   352
    int_type __c;
williamr@4
   353
    _STLP_TRY {
williamr@4
   354
      __c = this->rdbuf()->sbumpc();
williamr@4
   355
    }
williamr@4
   356
    _STLP_CATCH_ALL {
williamr@4
   357
      this->_M_handle_exception(ios_base::badbit);
williamr@4
   358
      return *this;
williamr@4
   359
    }
williamr@4
   360
williamr@4
   361
    if (!this->_S_eof(__c))
williamr@4
   362
      this->_M_gcount = 1;
williamr@4
   363
    else
williamr@4
   364
      this->setstate(ios_base::eofbit);
williamr@4
   365
  }
williamr@4
   366
williamr@4
   367
  return *this;
williamr@4
   368
}
williamr@4
   369
williamr@4
   370
// Putback
williamr@4
   371
williamr@4
   372
template <class _CharT, class _Traits>
williamr@4
   373
basic_istream<_CharT, _Traits>&
williamr@4
   374
basic_istream<_CharT, _Traits>::putback(_CharT __c) {
williamr@4
   375
  this->_M_gcount = 0;
williamr@4
   376
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   377
williamr@4
   378
  if (__sentry) {
williamr@4
   379
    typename _Traits::int_type __tmp = _Traits::eof();
williamr@4
   380
    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   381
//    if (!__buf || this->_S_eof(__buf->sputbackc(__c)))
williamr@4
   382
    if (__buf) {
williamr@4
   383
      _STLP_TRY {
williamr@4
   384
        __tmp = __buf->sputbackc(__c);
williamr@4
   385
      }
williamr@4
   386
      _STLP_CATCH_ALL {
williamr@4
   387
        this->_M_handle_exception(ios_base::badbit);
williamr@4
   388
      }
williamr@4
   389
    }
williamr@4
   390
    if (this->_S_eof(__tmp))
williamr@4
   391
      this->setstate(ios_base::badbit);
williamr@4
   392
  }
williamr@4
   393
  else
williamr@4
   394
    this->setstate(ios_base::failbit);
williamr@4
   395
williamr@4
   396
  return *this;
williamr@4
   397
}
williamr@4
   398
williamr@4
   399
template <class _CharT, class _Traits>
williamr@4
   400
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
williamr@4
   401
  this->_M_gcount = 0;
williamr@4
   402
williamr@4
   403
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   404
williamr@4
   405
  if (__sentry) {
williamr@4
   406
    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   407
    //     if (!__buf || _Traits::eq_int_type(__buf->sungetc(), _Traits::eof()))
williamr@4
   408
    if (__buf) {
williamr@4
   409
      _STLP_TRY {
williamr@4
   410
        _CharT __tmp;
williamr@4
   411
        __tmp = __buf->sungetc();
williamr@4
   412
#ifdef 	__SYMBIAN32__
williamr@4
   413
	if (__tmp == (_CharT)-1) //chek for eof
williamr@4
   414
#else
williamr@4
   415
        if (this->_S_eof(__tmp))
williamr@4
   416
#endif			
williamr@4
   417
          this->setstate(ios_base::badbit);
williamr@4
   418
      }
williamr@4
   419
      _STLP_CATCH_ALL {
williamr@4
   420
        this->_M_handle_exception(ios_base::badbit);
williamr@4
   421
      }
williamr@4
   422
    } else
williamr@4
   423
      this->setstate(ios_base::badbit);
williamr@4
   424
  }
williamr@4
   425
  else
williamr@4
   426
    this->setstate(ios_base::failbit);
williamr@4
   427
williamr@4
   428
  return *this;
williamr@4
   429
}
williamr@4
   430
williamr@4
   431
// Positioning and buffer control.
williamr@4
   432
williamr@4
   433
template <class _CharT, class _Traits>
williamr@4
   434
int basic_istream<_CharT, _Traits>::sync() {
williamr@4
   435
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   436
williamr@4
   437
  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   438
  if (__buf) {
williamr@4
   439
    if (__buf->pubsync() == -1) {
williamr@4
   440
      this->setstate(ios_base::badbit);
williamr@4
   441
      return -1;
williamr@4
   442
    }
williamr@4
   443
    else
williamr@4
   444
      return 0;
williamr@4
   445
  }
williamr@4
   446
  else
williamr@4
   447
    return -1;
williamr@4
   448
}
williamr@4
   449
williamr@4
   450
template <class _CharT, class _Traits>
williamr@4
   451
__BIS_pos_type__
williamr@4
   452
basic_istream<_CharT, _Traits>::tellg() {
williamr@4
   453
#ifndef __SYMBIAN32__
williamr@4
   454
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   455
#endif
williamr@4
   456
  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   457
  return (__buf && !this->fail()) ? __buf->pubseekoff(0, ios_base::cur, ios_base::in)
williamr@4
   458
    : pos_type(-1);
williamr@4
   459
}
williamr@4
   460
williamr@4
   461
template <class _CharT, class _Traits>
williamr@4
   462
basic_istream<_CharT, _Traits>&
williamr@4
   463
basic_istream<_CharT, _Traits>::seekg(pos_type __pos) {
williamr@4
   464
#ifndef __SYMBIAN32__
williamr@4
   465
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   466
#endif
williamr@4
   467
  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   468
  if (!this->fail() && __buf)
williamr@4
   469
  {
williamr@4
   470
    pos_type pos = __buf->pubseekpos(__pos, ios_base::in);
williamr@4
   471
    if(pos == pos_type(off_type(-1)))
williamr@4
   472
    	this->setstate(ios_base::failbit);
williamr@4
   473
  }
williamr@4
   474
  return *this;
williamr@4
   475
}
williamr@4
   476
williamr@4
   477
template <class _CharT, class _Traits>
williamr@4
   478
basic_istream<_CharT, _Traits>&
williamr@4
   479
basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
williamr@4
   480
{
williamr@4
   481
#ifndef __SYMBIAN32__
williamr@4
   482
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   483
#endif
williamr@4
   484
  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   485
  if (!this->fail() && __buf)
williamr@4
   486
  {
williamr@4
   487
williamr@4
   488
    pos_type pos = __buf->pubseekoff(__off, __dir, ios_base::in);
williamr@4
   489
    if(pos == pos_type(off_type(-1)))
williamr@4
   490
     	this->setstate(ios_base::failbit);
williamr@4
   491
  }
williamr@4
   492
  return *this;
williamr@4
   493
}
williamr@4
   494
williamr@4
   495
// Formatted input of characters and character arrays.
williamr@4
   496
williamr@4
   497
template <class _CharT, class _Traits>
williamr@4
   498
void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c)
williamr@4
   499
{
williamr@4
   500
//  typename _Traits::int_type __tmp = _Traits::eof();
williamr@4
   501
williamr@4
   502
  sentry __sentry(*this); // Skip whitespace.
williamr@4
   503
williamr@4
   504
  if (__sentry) {
williamr@4
   505
    typename _Traits::int_type __tmp = _Traits::eof();
williamr@4
   506
williamr@4
   507
    _STLP_TRY {
williamr@4
   508
      __tmp = this->rdbuf()->sbumpc();
williamr@4
   509
    }
williamr@4
   510
    _STLP_CATCH_ALL {
williamr@4
   511
      this->_M_handle_exception(ios_base::badbit);
williamr@4
   512
      return;
williamr@4
   513
    }
williamr@4
   514
williamr@4
   515
    if (!this->_S_eof(__tmp))
williamr@4
   516
      __c = _Traits::to_char_type(__tmp);
williamr@4
   517
    else
williamr@4
   518
      this->setstate(ios_base::eofbit | ios_base::failbit);
williamr@4
   519
  }
williamr@4
   520
}
williamr@4
   521
williamr@4
   522
williamr@4
   523
//---------------------------------------------------------------------------
williamr@4
   524
// istream's helper functions.
williamr@4
   525
williamr@4
   526
// A generic function for unbuffered input.  We stop when we reach EOF,
williamr@4
   527
// or when we have extracted _Num characters, or when the function object
williamr@4
   528
// __is_delim return true.  In the last case, it extracts the character
williamr@4
   529
// for which __is_delim is true, if and only if __extract_delim is true.
williamr@4
   530
// It appends a null character to the end of the string; this means that
williamr@4
   531
// it may store up to _Num + 1 characters.
williamr@4
   532
//
williamr@4
   533
// __is_getline governs two corner cases: reading _Num characters without
williamr@4
   534
// encountering delim or eof (in which case failbit is set if __is_getline
williamr@4
   535
// is true); and reading _Num characters where the _Num+1'st character is
williamr@4
   536
// eof (in which case eofbit is set if __is_getline is true).
williamr@4
   537
//
williamr@4
   538
// It is assumed that __is_delim never throws.
williamr@4
   539
//
williamr@4
   540
// Return value is the number of characters extracted, including the
williamr@4
   541
// delimiter if it is extracted.  Note that the number of characaters
williamr@4
   542
// extracted isn't necessarily the same as the number stored.
williamr@4
   543
williamr@4
   544
template < class _CharT, class _Traits, class _Is_Delim>
williamr@4
   545
streamsize _STLP_CALL
williamr@4
   546
_M_read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
williamr@4
   547
                       streamsize _Num, _CharT* __s,
williamr@4
   548
                       _Is_Delim __is_delim,
williamr@4
   549
                       bool __extract_delim, bool __append_null,
williamr@4
   550
                       bool __is_getline)
williamr@4
   551
{
williamr@4
   552
  streamsize __n = 0;
williamr@4
   553
  ios_base::iostate __status = 0;
williamr@4
   554
williamr@4
   555
  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
williamr@4
   556
  // The operations that can potentially throw are sbumpc, snextc, and sgetc.
williamr@4
   557
  _STLP_TRY {
williamr@4
   558
# if 0
williamr@4
   559
    int_type __c = __buf->sgetc();
williamr@4
   560
    while (true) {
williamr@4
   561
      if (__that->_S_eof(__c)) {
williamr@4
   562
        if (__n < _Num || __is_getline)
williamr@4
   563
          __status |= ios_base::eofbit;
williamr@4
   564
        break;
williamr@4
   565
      }
williamr@4
   566
williamr@4
   567
      else if (__is_delim(__c)) {
williamr@4
   568
        if (__extract_delim) {  // Extract and discard current character.
williamr@4
   569
          __buf->sbumpc();
williamr@4
   570
          ++__n;
williamr@4
   571
        }
williamr@4
   572
        break;
williamr@4
   573
      }
williamr@4
   574
williamr@4
   575
      else if (__n == _Num) {
williamr@4
   576
        if (__is_getline)
williamr@4
   577
          __status |= ios_base::failbit;
williamr@4
   578
        break;
williamr@4
   579
      }
williamr@4
   580
williamr@4
   581
      *__s++ = _Traits::to_char_type(__c);
williamr@4
   582
      ++__n;
williamr@4
   583
      __c = __buf->snextc();
williamr@4
   584
    }
williamr@4
   585
# else
williamr@4
   586
// int_type __c = __buf->sbumpc(); // __buf->sgetc();
williamr@4
   587
while (true) {
williamr@4
   588
williamr@4
   589
int_type __c = __buf->sbumpc(); // sschwarz
williamr@4
   590
williamr@4
   591
if (__that->_S_eof(__c)) {
williamr@4
   592
if (__n < _Num || __is_getline)
williamr@4
   593
__status |= ios_base::eofbit;
williamr@4
   594
break;
williamr@4
   595
}
williamr@4
   596
williamr@4
   597
else if (__is_delim(__c)) {
williamr@4
   598
if (__extract_delim) { // Extract and discard current character.
williamr@4
   599
// __buf->sbumpc();
williamr@4
   600
++__n;
williamr@4
   601
}
williamr@4
   602
break;
williamr@4
   603
}
williamr@4
   604
williamr@4
   605
else { // regular character
williamr@4
   606
williamr@4
   607
*__s++ = _Traits::to_char_type(__c);
williamr@4
   608
++__n;
williamr@4
   609
williamr@4
   610
}
williamr@4
   611
williamr@4
   612
if (__n == _Num) {
williamr@4
   613
if (__is_getline) // didn't find delimiter as one of the _Num chars
williamr@4
   614
__status |= ios_base::failbit;
williamr@4
   615
break;
williamr@4
   616
}
williamr@4
   617
williamr@4
   618
// *__s++ = _Traits::to_char_type(__c);
williamr@4
   619
// ++__n;
williamr@4
   620
williamr@4
   621
}
williamr@4
   622
williamr@4
   623
# endif
williamr@4
   624
williamr@4
   625
  }
williamr@4
   626
  _STLP_CATCH_ALL {
williamr@4
   627
    __that->_M_handle_exception(ios_base::badbit);
williamr@4
   628
    *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
williamr@4
   629
    return __n;
williamr@4
   630
  }
williamr@4
   631
williamr@4
   632
  if (__append_null)
williamr@4
   633
    *__s =  _STLP_DEFAULT_CONSTRUCTED(_CharT);
williamr@4
   634
  if (__status)
williamr@4
   635
    __that->setstate(__status);    // This might throw.
williamr@4
   636
  return __n;
williamr@4
   637
}
williamr@4
   638
williamr@4
   639
// Much like _M_read_unbuffered, but with one additional function object:
williamr@4
   640
// __scan_delim(first, last) returns the first pointer p in [first, last)
williamr@4
   641
// such that __is_delim(p) is true.
williamr@4
   642
williamr@4
   643
template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
williamr@4
   644
streamsize _STLP_CALL
williamr@4
   645
_M_read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
williamr@4
   646
                     streamsize _Num, _CharT* __s,
williamr@4
   647
                     _Is_Delim __is_delim, _Scan_Delim __scan_delim,
williamr@4
   648
                     bool __extract_delim, bool __append_null,
williamr@4
   649
                     bool __is_getline)
williamr@4
   650
{
williamr@4
   651
  streamsize __n = 0;
williamr@4
   652
  ios_base::iostate __status = 0;
williamr@4
   653
  bool __done    = false;
williamr@4
   654
williamr@4
   655
  _STLP_TRY {
williamr@4
   656
    while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
williamr@4
   657
      const _CharT* __first = __buf->_M_gptr();
williamr@4
   658
      const _CharT* __last  = __buf->_M_egptr();
williamr@4
   659
      ptrdiff_t __request = _Num - __n;
williamr@4
   660
williamr@4
   661
      const _CharT* __p  = __scan_delim(__first, __last);
williamr@4
   662
      ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request);
williamr@4
   663
      _Traits::copy(__s, __first, __chunk);
williamr@4
   664
      __s += __chunk;
williamr@4
   665
      __n += __chunk;
williamr@4
   666
      __buf->_M_gbump((int)__chunk);
williamr@4
   667
williamr@4
   668
      // We terminated by finding delim.
williamr@4
   669
      if (__p != __last && __p - __first <= __request) {
williamr@4
   670
        if (__extract_delim) {
williamr@4
   671
          __n += 1;
williamr@4
   672
          __buf->_M_gbump(1);
williamr@4
   673
        }
williamr@4
   674
        __done = true;
williamr@4
   675
      }
williamr@4
   676
williamr@4
   677
      // We terminated by reading all the characters we were asked for.
williamr@4
   678
      else if(__n == _Num) {
williamr@4
   679
williamr@4
   680
        // Find out if we have reached eof.  This matters for getline.
williamr@4
   681
        if (__is_getline) {
williamr@4
   682
          if (__chunk == __last - __first) {
williamr@4
   683
            if (__that->_S_eof(__buf->sgetc()))
williamr@4
   684
              __status |= ios_base::eofbit;
williamr@4
   685
          }
williamr@4
   686
          else
williamr@4
   687
            __status |= ios_base::failbit;
williamr@4
   688
        }
williamr@4
   689
        __done   = true;
williamr@4
   690
      }
williamr@4
   691
williamr@4
   692
      // The buffer contained fewer than _Num - __n characters.  Either we're
williamr@4
   693
      // at eof, or we should refill the buffer and try again.
williamr@4
   694
      else {
williamr@4
   695
	if (__that->_S_eof(__buf->sgetc())) {
williamr@4
   696
          __status |= ios_base::eofbit;
williamr@4
   697
          __done = true;
williamr@4
   698
        }
williamr@4
   699
      }
williamr@4
   700
    } // Close the while loop.
williamr@4
   701
  }
williamr@4
   702
  _STLP_CATCH_ALL {
williamr@4
   703
    __that->_M_handle_exception(ios_base::badbit);
williamr@4
   704
    __done = true;
williamr@4
   705
  }
williamr@4
   706
williamr@4
   707
  if (__done) {
williamr@4
   708
    if (__append_null)
williamr@4
   709
        *__s =  _STLP_DEFAULT_CONSTRUCTED(_CharT);
williamr@4
   710
    if (__status != 0)
williamr@4
   711
      __that->setstate(__status);   // This might throw.
williamr@4
   712
    return __n;
williamr@4
   713
  }
williamr@4
   714
williamr@4
   715
  // If execution has reached this point, then we have an empty buffer but
williamr@4
   716
  // we have not reached eof.  What that means is that the streambuf has
williamr@4
   717
  // decided to switch from buffered to unbuffered input.  We switch to
williamr@4
   718
  // to _M_read_unbuffered.
williamr@4
   719
williamr@4
   720
  return __n + _M_read_unbuffered(__that,  __buf, _Num - __n, __s, __is_delim,
williamr@4
   721
                                  __extract_delim,__append_null,__is_getline);
williamr@4
   722
}
williamr@4
   723
williamr@4
   724
williamr@4
   725
williamr@4
   726
williamr@4
   727
template <class _CharT, class _Traits>
williamr@4
   728
basic_istream<_CharT, _Traits>&
williamr@4
   729
basic_istream<_CharT, _Traits>::get(_CharT* __s, streamsize __n,
williamr@4
   730
                                    _CharT __delim) {
williamr@4
   731
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   732
  this->_M_gcount = 0;
williamr@4
   733
williamr@4
   734
  if (__sentry) {
williamr@4
   735
    if (__n > 0) {
williamr@4
   736
      basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   737
williamr@4
   738
      if (__buf->egptr() != __buf->gptr())
williamr@4
   739
        this->_M_gcount =
williamr@4
   740
          _M_read_buffered(this,  __buf, __n - 1, __s,
williamr@4
   741
                           _Eq_char_bound<_Traits>(__delim),
williamr@4
   742
                           _Scan_for_char_val<_Traits>(__delim),
williamr@4
   743
                           false, true, false);
williamr@4
   744
      else
williamr@4
   745
        this->_M_gcount =
williamr@4
   746
          _M_read_unbuffered(this,  __buf, __n - 1, __s,
williamr@4
   747
                             _Eq_char_bound<_Traits>(__delim),
williamr@4
   748
                             false, true, false);
williamr@4
   749
    }
williamr@4
   750
  }
williamr@4
   751
#ifdef __SYMBIAN32__
williamr@4
   752
  *(__s + this->_M_gcount) = _STLP_DEFAULT_CONSTRUCTED(_CharT);
williamr@4
   753
#endif //__SYMBIAN32__  
williamr@4
   754
  if (this->_M_gcount == 0)
williamr@4
   755
    this->setstate(ios_base::failbit);
williamr@4
   756
williamr@4
   757
  return *this;
williamr@4
   758
}
williamr@4
   759
williamr@4
   760
// Getline is essentially identical to get, except that it extracts
williamr@4
   761
// the delimiter.
williamr@4
   762
template <class _CharT, class _Traits>
williamr@4
   763
basic_istream<_CharT, _Traits>&
williamr@4
   764
basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n,
williamr@4
   765
                                        _CharT __delim) {
williamr@4
   766
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   767
  this->_M_gcount = 0;
williamr@4
   768
williamr@4
   769
  if (__sentry) {
williamr@4
   770
    if (__n > 0) {
williamr@4
   771
      basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   772
      this->_M_gcount = __buf->egptr() != __buf->gptr()
williamr@4
   773
        ? _M_read_buffered(this,  __buf, __n - 1, __s,
williamr@4
   774
                           _Eq_char_bound<_Traits>(__delim),
williamr@4
   775
                           _Scan_for_char_val<_Traits>(__delim),
williamr@4
   776
                           true, true, true)
williamr@4
   777
        : _M_read_unbuffered(this,  __buf, __n - 1, __s,
williamr@4
   778
                             _Eq_char_bound<_Traits>(__delim),
williamr@4
   779
                             true, true, true);
williamr@4
   780
    }
williamr@4
   781
  }
williamr@4
   782
williamr@4
   783
  if (this->_M_gcount == 0)
williamr@4
   784
    this->setstate(ios_base::failbit);
williamr@4
   785
williamr@4
   786
  return *this;
williamr@4
   787
}
williamr@4
   788
williamr@4
   789
// Read n characters.  We don't look for any delimiter, and we don't
williamr@4
   790
// put in a terminating null character.
williamr@4
   791
template <class _CharT, class _Traits>
williamr@4
   792
basic_istream<_CharT, _Traits>&
williamr@4
   793
basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
williamr@4
   794
{
williamr@4
   795
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   796
  this->_M_gcount = 0;
williamr@4
   797
williamr@4
   798
  if (__sentry && !this->eof()) {
williamr@4
   799
    basic_streambuf<_CharT, _Traits>*__buf = this->rdbuf();
williamr@4
   800
    if (__buf->gptr() != __buf->egptr())
williamr@4
   801
      _M_gcount
williamr@4
   802
        = _M_read_buffered(this,  __buf, __n, __s,
williamr@4
   803
                           _Constant_unary_fun<bool, int_type>(false),
williamr@4
   804
                           _Project2nd<const _CharT*, const _CharT*>(),
williamr@4
   805
                           false, false, false);
williamr@4
   806
    else
williamr@4
   807
      _M_gcount
williamr@4
   808
        = _M_read_unbuffered(this,  __buf, __n, __s,
williamr@4
   809
                             _Constant_unary_fun<bool, int_type>(false),
williamr@4
   810
                             false, false, false);
williamr@4
   811
  }
williamr@4
   812
  else
williamr@4
   813
    this->setstate(ios_base::failbit);
williamr@4
   814
williamr@4
   815
  if (this->eof())
williamr@4
   816
    this->setstate(ios_base::eofbit | ios_base::failbit);
williamr@4
   817
williamr@4
   818
  return *this;
williamr@4
   819
}
williamr@4
   820
williamr@4
   821
williamr@4
   822
// Read n or fewer characters.  We don't look for any delimiter, and
williamr@4
   823
// we don't put in a terminating null character.
williamr@4
   824
template <class _CharT, class _Traits>
williamr@4
   825
streamsize
williamr@4
   826
basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax)
williamr@4
   827
{
williamr@4
   828
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
   829
  this->_M_gcount = 0;
williamr@4
   830
williamr@4
   831
  if (__sentry && !this->eof() && __nmax >= 0) {
williamr@4
   832
williamr@4
   833
    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   834
    streamsize __avail = __buf->in_avail();
williamr@4
   835
williamr@4
   836
    // fbp : isn't full-blown setstate required here ?
williamr@4
   837
    if (__avail == -1)
williamr@4
   838
      this->_M_setstate_nothrow(ios_base::eofbit);
williamr@4
   839
williamr@4
   840
    else if (__avail != 0) {
williamr@4
   841
williamr@4
   842
      if (__buf->gptr() != __buf->egptr())
williamr@4
   843
        _M_gcount
williamr@4
   844
          = _M_read_buffered(this,  __buf, (min) (__avail, __nmax), __s,
williamr@4
   845
                             _Constant_unary_fun<bool, int_type>(false),
williamr@4
   846
                             _Project2nd<const _CharT*, const _CharT*>(),
williamr@4
   847
                             false, false, false);
williamr@4
   848
      else
williamr@4
   849
        _M_gcount
williamr@4
   850
          = _M_read_unbuffered(this,  __buf, (min) (__avail, __nmax), __s,
williamr@4
   851
                               _Constant_unary_fun<bool, int_type>(false),
williamr@4
   852
                               false, false, false);
williamr@4
   853
    }
williamr@4
   854
  }
williamr@4
   855
  else {
williamr@4
   856
    // fbp : changed so that failbit is set only there, to pass Dietmar's test
williamr@4
   857
    if (this->eof())
williamr@4
   858
      this->setstate(ios_base::eofbit | ios_base::failbit);
williamr@4
   859
    else
williamr@4
   860
      {
williamr@4
   861
      if (__nmax < 0)
williamr@4
   862
        {
williamr@4
   863
        basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   864
        streamsize __avail = __buf->in_avail();
williamr@4
   865
        if(__avail == -1)
williamr@4
   866
            this->setstate(ios_base::eofbit);
williamr@4
   867
        }
williamr@4
   868
      else
williamr@4
   869
        this->setstate(ios_base::failbit);
williamr@4
   870
      }
williamr@4
   871
  }
williamr@4
   872
williamr@4
   873
  //  if (this->eof())
williamr@4
   874
  //    this->setstate(ios_base::eofbit | ios_base::failbit);
williamr@4
   875
williamr@4
   876
  return _M_gcount;
williamr@4
   877
}
williamr@4
   878
williamr@4
   879
template <class _CharT, class _Traits>
williamr@4
   880
void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s)
williamr@4
   881
{
williamr@4
   882
  sentry __sentry(*this); // Skip whitespace.
williamr@4
   883
williamr@4
   884
  if (__sentry) {
williamr@4
   885
    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
   886
    streamsize __nmax = this->width() > 0
williamr@4
   887
      ? this->width() - 1
williamr@4
   888
      : (numeric_limits<streamsize>::max)() / sizeof(_CharT) - 1;
williamr@4
   889
williamr@4
   890
    streamsize __n = __buf->gptr() != __buf->egptr()
williamr@4
   891
      ? _M_read_buffered(this,  __buf, __nmax, __s,
williamr@4
   892
                         _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
williamr@4
   893
                         _Scan_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
williamr@4
   894
			 false, true, false)
williamr@4
   895
      : _M_read_unbuffered(this,  __buf, __nmax, __s,
williamr@4
   896
                           _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
williamr@4
   897
			   false, true, false);
williamr@4
   898
    if (__n == 0)
williamr@4
   899
      this->setstate(ios_base::failbit);
williamr@4
   900
  }
williamr@4
   901
  this->width(0);
williamr@4
   902
}
williamr@4
   903
williamr@4
   904
// A generic unbuffered function for ignoring characters.  We stop
williamr@4
   905
// when we reach EOF, or when the function object __is_delim returns
williamr@4
   906
// true.  In the last case, it extracts the character for which
williamr@4
   907
// __is_delim is true, if and only if __extract_delim is true.
williamr@4
   908
williamr@4
   909
template < class _CharT, class _Traits, class _Is_Delim>
williamr@4
   910
void _STLP_CALL
williamr@4
   911
_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
williamr@4
   912
		     basic_streambuf<_CharT, _Traits>* __buf,
williamr@4
   913
		     _Is_Delim __is_delim,
williamr@4
   914
		     bool __extract_delim, bool __set_failbit)
williamr@4
   915
{
williamr@4
   916
  bool __done = false;
williamr@4
   917
  ios_base::iostate __status = 0;
williamr@4
   918
  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
williamr@4
   919
williamr@4
   920
  _STLP_TRY {
williamr@4
   921
#ifdef __SYMBIAN32__
williamr@4
   922
    int_type __c = __buf->sgetc();
williamr@4
   923
    do {
williamr@4
   924
williamr@4
   925
      if (__that->_S_eof(__c)) {
williamr@4
   926
        __done = true;
williamr@4
   927
        __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
williamr@4
   928
                                  : ios_base::eofbit;
williamr@4
   929
        break;
williamr@4
   930
      }
williamr@4
   931
williamr@4
   932
      else if (__is_delim(__c)) {
williamr@4
   933
        __done = true;
williamr@4
   934
        if (__extract_delim)
williamr@4
   935
            __buf->snextc();
williamr@4
   936
        break;
williamr@4
   937
        
williamr@4
   938
        }
williamr@4
   939
      __c = __buf->snextc();        
williamr@4
   940
      } while(!__done);
williamr@4
   941
#else
williamr@4
   942
    while (!__done) {
williamr@4
   943
      int_type __c = __buf->sbumpc();
williamr@4
   944
williamr@4
   945
      if (__that->_S_eof(__c)) {
williamr@4
   946
        __done = true;
williamr@4
   947
        __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
williamr@4
   948
                                  : ios_base::eofbit;
williamr@4
   949
      }
williamr@4
   950
williamr@4
   951
      else if (__is_delim(__c)) {
williamr@4
   952
        __done = true;
williamr@4
   953
        if (!__extract_delim)
williamr@4
   954
          if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
williamr@4
   955
            __status |= ios_base::failbit;
williamr@4
   956
      }
williamr@4
   957
    }
williamr@4
   958
#endif
williamr@4
   959
  }
williamr@4
   960
  _STLP_CATCH_ALL {
williamr@4
   961
    __that->_M_handle_exception(ios_base::badbit);
williamr@4
   962
  }
williamr@4
   963
williamr@4
   964
  __that->setstate(__status);
williamr@4
   965
}
williamr@4
   966
williamr@4
   967
// A generic buffered function for ignoring characters.  Much like
williamr@4
   968
// _M_ignore_unbuffered, but with one additional function object:
williamr@4
   969
// __scan_delim(first, last) returns the first pointer p in [first,
williamr@4
   970
// last) such that __is_delim(p) is true.
williamr@4
   971
williamr@4
   972
template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
williamr@4
   973
void _STLP_CALL
williamr@4
   974
_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
williamr@4
   975
		   basic_streambuf<_CharT, _Traits>* __buf,
williamr@4
   976
		   _Is_Delim __is_delim, _Scan_Delim __scan_delim,
williamr@4
   977
		   bool __extract_delim, bool __set_failbit)
williamr@4
   978
{
williamr@4
   979
  bool __at_eof      = false;
williamr@4
   980
  bool __found_delim = false;
williamr@4
   981
williamr@4
   982
  _STLP_TRY {
williamr@4
   983
    while (__buf->_M_egptr() != __buf->_M_gptr() && !__at_eof && !__found_delim) {
williamr@4
   984
      const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
williamr@4
   985
      __buf->_M_gbump((int)(__p - __buf->_M_gptr()));
williamr@4
   986
williamr@4
   987
      if (__p != __buf->_M_egptr()) { // We found delim, so we're done.
williamr@4
   988
        if (__extract_delim)
williamr@4
   989
          __buf->_M_gbump(1);
williamr@4
   990
        __found_delim = true;
williamr@4
   991
      }
williamr@4
   992
williamr@4
   993
      else                         // No delim.  Try to refil the buffer.
williamr@4
   994
        __at_eof = __that->_S_eof(__buf->sgetc());
williamr@4
   995
    }                              // Close the while loop.
williamr@4
   996
  }
williamr@4
   997
  _STLP_CATCH_ALL {
williamr@4
   998
    __that->_M_handle_exception(ios_base::badbit);
williamr@4
   999
    return;
williamr@4
  1000
  }
williamr@4
  1001
williamr@4
  1002
  if (__at_eof) {
williamr@4
  1003
    __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
williamr@4
  1004
                                   : ios_base::eofbit);
williamr@4
  1005
    return;
williamr@4
  1006
  }
williamr@4
  1007
  if (__found_delim)
williamr@4
  1008
    return;
williamr@4
  1009
williamr@4
  1010
  // If execution has reached this point, then we have an empty buffer but
williamr@4
  1011
  // we have not reached eof.  What that means is that the streambuf has
williamr@4
  1012
  // decided to switch from a buffered to an unbuffered mode.  We switch
williamr@4
  1013
  // to _M_ignore_unbuffered.
williamr@4
  1014
  _M_ignore_unbuffered(__that,  __buf, __is_delim, __extract_delim, __set_failbit);
williamr@4
  1015
}
williamr@4
  1016
williamr@4
  1017
// Overloaded versions of _M_ignore_unbuffered and _M_ignore_unbuffered
williamr@4
  1018
// with an explicit count _Num.  Return value is the number of
williamr@4
  1019
// characters extracted.
williamr@4
  1020
//
williamr@4
  1021
// The function object __max_chars takes two arguments, _Num and __n
williamr@4
  1022
// (the latter being the number of characters we have already read),
williamr@4
  1023
// and returns the maximum number of characters to read from the buffer.
williamr@4
  1024
// We parameterize _M_ignore_buffered so that we can use it for both
williamr@4
  1025
// bounded and unbounded input; for the former the function object should
williamr@4
  1026
// be minus<>, and for the latter it should return a constant maximum value.
williamr@4
  1027
williamr@4
  1028
template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim>
williamr@4
  1029
streamsize _STLP_CALL
williamr@4
  1030
_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
williamr@4
  1031
		     basic_streambuf<_CharT, _Traits>* __buf,
williamr@4
  1032
		     streamsize _Num, _Max_Chars __max_chars,
williamr@4
  1033
		     _Is_Delim __is_delim,
williamr@4
  1034
		     bool __extract_delim, bool __set_failbit)
williamr@4
  1035
{
williamr@4
  1036
  streamsize __n = 0;
williamr@4
  1037
  ios_base::iostate __status = 0;
williamr@4
  1038
  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
williamr@4
  1039
williamr@4
  1040
  _STLP_TRY {
williamr@4
  1041
    while (__max_chars(_Num, __n) > 0) {
williamr@4
  1042
      int_type __c = __buf->sbumpc();
williamr@4
  1043
williamr@4
  1044
      if (__that->_S_eof(__c)) {
williamr@4
  1045
        __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
williamr@4
  1046
                                  : ios_base::eofbit;
williamr@4
  1047
        break;
williamr@4
  1048
      }
williamr@4
  1049
williamr@4
  1050
      else if (__is_delim(__c)) {
williamr@4
  1051
        if (__extract_delim)
williamr@4
  1052
          ++__n;
williamr@4
  1053
        else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
williamr@4
  1054
          __status |= ios_base::failbit;
williamr@4
  1055
williamr@4
  1056
        break;
williamr@4
  1057
      }
williamr@4
  1058
      // fbp : added counter increment to pass Dietmar's test
williamr@4
  1059
      ++__n;
williamr@4
  1060
    }
williamr@4
  1061
  }
williamr@4
  1062
  _STLP_CATCH_ALL {
williamr@4
  1063
    __that->_M_handle_exception(ios_base::badbit);
williamr@4
  1064
  }
williamr@4
  1065
williamr@4
  1066
  if (__status)
williamr@4
  1067
    __that->setstate(__status);   // This might throw.
williamr@4
  1068
  return __n;
williamr@4
  1069
}
williamr@4
  1070
williamr@4
  1071
template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim, class _Scan_Delim>
williamr@4
  1072
streamsize _STLP_CALL
williamr@4
  1073
_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
williamr@4
  1074
		   basic_streambuf<_CharT, _Traits>* __buf,
williamr@4
  1075
		   streamsize _Num,
williamr@4
  1076
		   _Max_Chars __max_chars,
williamr@4
  1077
		   _Is_Delim __is_delim, _Scan_Delim __scan_delim,
williamr@4
  1078
		   bool __extract_delim, bool __set_failbit)
williamr@4
  1079
{
williamr@4
  1080
  streamsize __n = 0;
williamr@4
  1081
  bool __at_eof = false;
williamr@4
  1082
  bool __done   = false;
williamr@4
  1083
williamr@4
  1084
  _STLP_TRY {
williamr@4
  1085
    while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
williamr@4
  1086
      ptrdiff_t __avail = __buf->_M_egptr() - __buf->_M_gptr();
williamr@4
  1087
      streamsize __m = __max_chars(_Num, __n);
williamr@4
  1088
williamr@4
  1089
      if (__avail >= __m) {       // We have more characters than we need.
williamr@4
  1090
        const _CharT* __last = __buf->_M_gptr() + __m;
williamr@4
  1091
        const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last);
williamr@4
  1092
        ptrdiff_t __chunk = __p - __buf->_M_gptr();
williamr@4
  1093
        __n += __chunk;
williamr@4
  1094
        __buf->_M_gbump((int)__chunk);
williamr@4
  1095
williamr@4
  1096
        if (__extract_delim && __p != __last) {
williamr@4
  1097
          __n += 1;
williamr@4
  1098
          __buf->_M_gbump(1);
williamr@4
  1099
        }
williamr@4
  1100
williamr@4
  1101
        __done = true;
williamr@4
  1102
      }
williamr@4
  1103
williamr@4
  1104
      else {
williamr@4
  1105
        const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
williamr@4
  1106
        ptrdiff_t __chunk = __p - __buf->_M_gptr();
williamr@4
  1107
        __n += __chunk;
williamr@4
  1108
        __buf->_M_gbump((int)__chunk);
williamr@4
  1109
williamr@4
  1110
        if (__p != __buf->_M_egptr()) { // We found delim.
williamr@4
  1111
          if (__extract_delim) {
williamr@4
  1112
            __n += 1;
williamr@4
  1113
            __buf->_M_gbump(1);
williamr@4
  1114
          }
williamr@4
  1115
williamr@4
  1116
          __done = true;
williamr@4
  1117
        }
williamr@4
  1118
williamr@4
  1119
        // We didn't find delim.  Try to refill the buffer.
williamr@4
  1120
        else if (__that->_S_eof(__buf->sgetc())) {
williamr@4
  1121
          __done   = true;
williamr@4
  1122
          __at_eof = true;
williamr@4
  1123
        }
williamr@4
  1124
      }
williamr@4
  1125
    } // Close the while loop.
williamr@4
  1126
  }
williamr@4
  1127
  _STLP_CATCH_ALL {
williamr@4
  1128
    __that->_M_handle_exception(ios_base::badbit);
williamr@4
  1129
    return __n;
williamr@4
  1130
  }
williamr@4
  1131
williamr@4
  1132
  if (__at_eof)
williamr@4
  1133
    __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
williamr@4
  1134
                                   : ios_base::eofbit);
williamr@4
  1135
williamr@4
  1136
  if (__done)
williamr@4
  1137
    return __n;
williamr@4
  1138
williamr@4
  1139
  // If execution has reached this point, then we have an empty buffer but
williamr@4
  1140
  // we have not reached eof.  What that means is that the streambuf has
williamr@4
  1141
  // decided to switch from buffered to unbuffered input.  We switch to
williamr@4
  1142
  // to _M_ignore_unbuffered.
williamr@4
  1143
williamr@4
  1144
  return __n + _M_ignore_unbuffered( __that,  __buf, _Num, __max_chars,
williamr@4
  1145
                                    __is_delim, __extract_delim, __set_failbit);
williamr@4
  1146
}
williamr@4
  1147
williamr@4
  1148
williamr@4
  1149
template <class _CharT, class _Traits>
williamr@4
  1150
basic_istream<_CharT, _Traits>&
williamr@4
  1151
basic_istream<_CharT, _Traits>::ignore(streamsize __n)
williamr@4
  1152
{
williamr@4
  1153
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
  1154
  this->_M_gcount = 0;
williamr@4
  1155
williamr@4
  1156
  if (__sentry) {
williamr@4
  1157
    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
  1158
    typedef _Constant_unary_fun<bool, int_type> _Const_bool;
williamr@4
  1159
    typedef _Constant_binary_fun<streamsize, streamsize, streamsize>
williamr@4
  1160
      _Const_streamsize;
williamr@4
  1161
    const streamsize __maxss = (numeric_limits<streamsize>::max)();
williamr@4
  1162
williamr@4
  1163
    if (__n == (numeric_limits<int>::max)()) {
williamr@4
  1164
      if (__buf->gptr() != __buf->egptr())
williamr@4
  1165
        _M_gcount
williamr@4
  1166
          = _M_ignore_buffered(this,  __buf,
williamr@4
  1167
                               __maxss, _Const_streamsize(__maxss),
williamr@4
  1168
                               _Const_bool(false),
williamr@4
  1169
                               _Project2nd<const _CharT*, const _CharT*>(),
williamr@4
  1170
                               false, false);
williamr@4
  1171
      else
williamr@4
  1172
        _M_gcount = _M_ignore_unbuffered(this,  __buf,
williamr@4
  1173
                                         __maxss, _Const_streamsize(__maxss),
williamr@4
  1174
                                         _Const_bool(false), false, false);
williamr@4
  1175
    }
williamr@4
  1176
    else {
williamr@4
  1177
      if (__buf->gptr() != __buf->egptr())
williamr@4
  1178
        _M_gcount
williamr@4
  1179
          = _M_ignore_buffered(this,  __buf,
williamr@4
  1180
                               __n, minus<streamsize>(),
williamr@4
  1181
                               _Const_bool(false),
williamr@4
  1182
                               _Project2nd<const _CharT*, const _CharT*>(),
williamr@4
  1183
                               false, false);
williamr@4
  1184
      else
williamr@4
  1185
        _M_gcount = _M_ignore_unbuffered(this,  __buf, __n, minus<streamsize>(),
williamr@4
  1186
                                         _Const_bool(false), false, false);
williamr@4
  1187
    }
williamr@4
  1188
  }
williamr@4
  1189
williamr@4
  1190
  return *this;
williamr@4
  1191
}
williamr@4
  1192
williamr@4
  1193
template <class _CharT, class _Traits>
williamr@4
  1194
basic_istream<_CharT, _Traits>&
williamr@4
  1195
basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim)
williamr@4
  1196
{
williamr@4
  1197
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
  1198
  this->_M_gcount = 0;
williamr@4
  1199
williamr@4
  1200
  if (__sentry) {
williamr@4
  1201
    basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
  1202
    typedef _Constant_unary_fun<bool, int_type> _Const_bool;
williamr@4
  1203
    typedef _Constant_binary_fun<streamsize, streamsize, streamsize>
williamr@4
  1204
      _Const_streamsize;
williamr@4
  1205
    const streamsize __maxss = (numeric_limits<streamsize>::max)();
williamr@4
  1206
williamr@4
  1207
    if (__n == (numeric_limits<int>::max)()) {
williamr@4
  1208
      if (__buf->gptr() != __buf->egptr())
williamr@4
  1209
        _M_gcount = _M_ignore_buffered(this,  __buf,
williamr@4
  1210
                                       __maxss, _Const_streamsize(__maxss),
williamr@4
  1211
                                       _Eq_int_bound<_Traits>(__delim),
williamr@4
  1212
                                       _Scan_for_int_val<_Traits>(__delim),
williamr@4
  1213
                                       true, false);
williamr@4
  1214
      else
williamr@4
  1215
        _M_gcount = _M_ignore_unbuffered(this,  __buf,
williamr@4
  1216
                                         __maxss, _Const_streamsize(__maxss),
williamr@4
  1217
                                         _Eq_int_bound<_Traits>(__delim),
williamr@4
  1218
                                         true, false);
williamr@4
  1219
    }
williamr@4
  1220
    else {
williamr@4
  1221
      if (__buf->gptr() != __buf->egptr())
williamr@4
  1222
        _M_gcount = _M_ignore_buffered(this,  __buf,
williamr@4
  1223
                                       __n, minus<streamsize>(),
williamr@4
  1224
                                       _Eq_int_bound<_Traits>(
williamr@4
  1225
                                               __delim),
williamr@4
  1226
                                       _Scan_for_int_val<_Traits>(__delim),
williamr@4
  1227
                                       true, false);
williamr@4
  1228
      else
williamr@4
  1229
        _M_gcount = _M_ignore_unbuffered(this,  __buf, __n, minus<streamsize>(),
williamr@4
  1230
                                         _Eq_int_bound<_Traits>(__delim),
williamr@4
  1231
                                         true, false);
williamr@4
  1232
    }
williamr@4
  1233
  }
williamr@4
  1234
williamr@4
  1235
  return *this;
williamr@4
  1236
}
williamr@4
  1237
williamr@4
  1238
// This member function does not construct a sentry object, because
williamr@4
  1239
// it is called from sentry's constructor.
williamr@4
  1240
template <class _CharT, class _Traits>
williamr@4
  1241
void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit)
williamr@4
  1242
{
williamr@4
  1243
  basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
williamr@4
  1244
  if (!__buf)
williamr@4
  1245
    this->setstate(ios_base::badbit);
williamr@4
  1246
  else if (__buf->gptr() != __buf->egptr())
williamr@4
  1247
    _M_ignore_buffered(this,  __buf,
williamr@4
  1248
                       _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
williamr@4
  1249
                       _Scan_for_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
williamr@4
  1250
                       false, __set_failbit);
williamr@4
  1251
  else
williamr@4
  1252
    _M_ignore_unbuffered(this,  __buf,
williamr@4
  1253
                         _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
williamr@4
  1254
                         false, __set_failbit);
williamr@4
  1255
}
williamr@4
  1256
williamr@4
  1257
williamr@4
  1258
// This is a very simple loop that reads characters from __src and puts
williamr@4
  1259
// them into __dest.  It looks complicated because of the (standard-
williamr@4
  1260
// mandated) exception handling policy.
williamr@4
  1261
//
williamr@4
  1262
// We stop when we get an exception, when we fail to insert into the
williamr@4
  1263
// output streambuf, or when __is_delim is true.
williamr@4
  1264
williamr@4
  1265
template < class _CharT, class _Traits, class _Is_Delim>
williamr@4
  1266
streamsize _STLP_CALL
williamr@4
  1267
_M_copy_unbuffered( basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
williamr@4
  1268
		    basic_streambuf<_CharT, _Traits>* __dest,
williamr@4
  1269
		    _Is_Delim __is_delim,
williamr@4
  1270
		    bool __extract_delim, bool __rethrow)
williamr@4
  1271
{
williamr@4
  1272
  streamsize __extracted = 0;
williamr@4
  1273
  ios_base::iostate __status = 0;
williamr@4
  1274
  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
williamr@4
  1275
  int_type __c;
williamr@4
  1276
williamr@4
  1277
  _STLP_TRY {
williamr@4
  1278
#ifdef __SYMBIAN32__
williamr@4
  1279
    __c = __src->sgetc();
williamr@4
  1280
    for(;; __c =  __src->snextc()){
williamr@4
  1281
  
williamr@4
  1282
      // If we failed to get a character, then quit.
williamr@4
  1283
      if (__that->_S_eof(__c)) {
williamr@4
  1284
        __status |= ios_base::eofbit;
williamr@4
  1285
        break;
williamr@4
  1286
      }  
williamr@4
  1287
      // If it's the delimiter, then quit.
williamr@4
  1288
      else if (__is_delim(__c)) {
williamr@4
  1289
        if (!__extract_delim)
williamr@4
  1290
          __status |= ios_base::failbit;
williamr@4
  1291
        break;
williamr@4
  1292
      }
williamr@4
  1293
      
williamr@4
  1294
      else {
williamr@4
  1295
      
williamr@4
  1296
        // Try to put the character in the output streambuf.
williamr@4
  1297
        _STLP_TRY {
williamr@4
  1298
          if (!__that->_S_eof(__dest->sputc(__c)))
williamr@4
  1299
            ++__extracted;
williamr@4
  1300
          else
williamr@4
  1301
            break;
williamr@4
  1302
        }
williamr@4
  1303
        _STLP_CATCH_ALL {
williamr@4
  1304
          __status |= ios_base::failbit;
williamr@4
  1305
          break;
williamr@4
  1306
        }
williamr@4
  1307
        
williamr@4
  1308
      }
williamr@4
  1309
williamr@4
  1310
    } /* while (true) */
williamr@4
  1311
#else
williamr@4
  1312
    while (true) {
williamr@4
  1313
williamr@4
  1314
      // Get a character. If there's an exception, catch and (maybe) rethrow it.
williamr@4
  1315
      __c = __src->sbumpc();
williamr@4
  1316
williamr@4
  1317
      // If we failed to get a character, then quit.
williamr@4
  1318
      if (__that->_S_eof(__c)) {
williamr@4
  1319
        __status |= ios_base::eofbit;
williamr@4
  1320
        break;
williamr@4
  1321
      }
williamr@4
  1322
      // If it's the delimiter, then quit.
williamr@4
  1323
      else if (__is_delim(__c)) {
williamr@4
  1324
        if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c)))
williamr@4
  1325
          __status |= ios_base::failbit;
williamr@4
  1326
        break;
williamr@4
  1327
      }
williamr@4
  1328
williamr@4
  1329
      else {
williamr@4
  1330
williamr@4
  1331
        // Try to put the character in the output streambuf.
williamr@4
  1332
        bool __failed = false;
williamr@4
  1333
        _STLP_TRY {
williamr@4
  1334
          if (!__that->_S_eof(__dest->sputc(__c)))
williamr@4
  1335
            ++__extracted;
williamr@4
  1336
          else
williamr@4
  1337
            __failed = true;
williamr@4
  1338
        }
williamr@4
  1339
        _STLP_CATCH_ALL {
williamr@4
  1340
          __failed = true;
williamr@4
  1341
        }
williamr@4
  1342
williamr@4
  1343
        // If we failed to put the character in the output streambuf, then
williamr@4
  1344
        // try to push it back to the input streambuf.
williamr@4
  1345
        if (__failed && !__pushback(__src, _Traits::to_char_type(__c)))
williamr@4
  1346
          __status |= ios_base::failbit;
williamr@4
  1347
williamr@4
  1348
        // fbp : avoiding infinite loop in io-27-6-1-2-3.exp
williamr@4
  1349
        if (__failed)
williamr@4
  1350
          break;
williamr@4
  1351
      }
williamr@4
  1352
williamr@4
  1353
    } /* while (true) */
williamr@4
  1354
#endif    
williamr@4
  1355
  }
williamr@4
  1356
  // fbp : this try/catch moved here in reasonable assumption
williamr@4
  1357
  // __is_delim never throw (__pushback is guaranteed not to)
williamr@4
  1358
  _STLP_CATCH_ALL {
williamr@4
  1359
    // See 27.6.1.2.3, paragraph 13.
williamr@4
  1360
    if (__rethrow && __extracted == 0)
williamr@4
  1361
      __that->_M_handle_exception(ios_base::failbit);
williamr@4
  1362
  }
williamr@4
  1363
  __that->setstate(__status);
williamr@4
  1364
  return __extracted;
williamr@4
  1365
}
williamr@4
  1366
williamr@4
  1367
// Buffered copying from one streambuf to another.  We copy the characters
williamr@4
  1368
// in chunks, rather than one at a time.  We still have to worry about all
williamr@4
  1369
// of the error conditions we checked in _M_copy_unbuffered, plus one more:
williamr@4
  1370
// the streambuf might decide to switch from a buffered to an unbuffered mode.
williamr@4
  1371
williamr@4
  1372
template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
williamr@4
  1373
streamsize _STLP_CALL
williamr@4
  1374
_M_copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
williamr@4
  1375
                     basic_streambuf<_CharT, _Traits>* __dest,
williamr@4
  1376
                     _Scan_Delim __scan_delim, _Is_Delim __is_delim,
williamr@4
  1377
                     bool __extract_delim, bool __rethrow)
williamr@4
  1378
{
williamr@4
  1379
  streamsize __extracted = 0;
williamr@4
  1380
  ios_base::iostate __status = 0;
williamr@4
  1381
  typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
williamr@4
  1382
  int_type __c = _Traits::eof();
williamr@4
  1383
  _CharT* __first = __src->_M_gptr();
williamr@4
  1384
  ptrdiff_t __avail = __src->_M_egptr() - __first;
williamr@4
  1385
  // fbp : introduced to move catch/try blocks out of the loop
williamr@4
  1386
  bool __do_handle_exceptions;
williamr@4
  1387
williamr@4
  1388
  _STLP_TRY {
williamr@4
  1389
    while (true) {
williamr@4
  1390
      __do_handle_exceptions = false ;
williamr@4
  1391
      const _CharT* __last = __scan_delim(__first, __src->_M_egptr());
williamr@4
  1392
williamr@4
  1393
      // Try to copy the entire input buffer to the output buffer.
williamr@4
  1394
      streamsize __n = __dest->sputn(__first, __extract_delim && __last != __src->_M_egptr()
williamr@4
  1395
                                     ? (__last - __first) + 1
williamr@4
  1396
                                     : (__last - __first));
williamr@4
  1397
      __src->_M_gbump((int)__n);
williamr@4
  1398
      __extracted += __n;
williamr@4
  1399
williamr@4
  1400
      // from this on, catch() will call _M_handle_exceptions()
williamr@4
  1401
      __do_handle_exceptions = true;
williamr@4
  1402
williamr@4
  1403
      if (__n < __avail)          // We found the delimiter, or else failed to
williamr@4
  1404
        break;                    // copy some characters.
williamr@4
  1405
williamr@4
  1406
      __c = __src->sgetc();
williamr@4
  1407
williamr@4
  1408
      // Three possibilities: we succeeded in refilling the buffer, or
williamr@4
  1409
      // we got EOF, or the streambuf has switched to unbuffered mode.
williamr@4
  1410
      __first = __src->_M_gptr();
williamr@4
  1411
      __avail = __src->_M_egptr() - __first;
williamr@4
  1412
williamr@4
  1413
      if (__avail > 0)
williamr@4
  1414
        {}	// dwa 1/16/00 -- suppress a Metrowerks warning
williamr@4
  1415
      else if (__that->_S_eof(__c)) {
williamr@4
  1416
        __status |= ios_base::eofbit;
williamr@4
  1417
        break;
williamr@4
  1418
      }
williamr@4
  1419
      else
williamr@4
  1420
        return __extracted + _M_copy_unbuffered(__that,  __src, __dest, __is_delim,
williamr@4
  1421
                                                __extract_delim, __rethrow);
williamr@4
  1422
    } /* while */
williamr@4
  1423
  }
williamr@4
  1424
williamr@4
  1425
  _STLP_CATCH_ALL {
williamr@4
  1426
    // See 27.6.1.2.3, paragraph 13.
williamr@4
  1427
    if (__rethrow && __do_handle_exceptions &&  __extracted == 0)
williamr@4
  1428
      __that->_M_handle_exception(ios_base::failbit);
williamr@4
  1429
  }
williamr@4
  1430
williamr@4
  1431
  if (__status)
williamr@4
  1432
    __that->setstate(__status);   // This might throw.
williamr@4
  1433
  return __extracted;
williamr@4
  1434
}
williamr@4
  1435
williamr@4
  1436
williamr@4
  1437
williamr@4
  1438
template <class _CharT, class _Traits>
williamr@4
  1439
basic_istream<_CharT, _Traits>&
williamr@4
  1440
basic_istream<_CharT, _Traits>
williamr@4
  1441
  ::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim)
williamr@4
  1442
{
williamr@4
  1443
  sentry __sentry(*this, _No_Skip_WS());
williamr@4
  1444
  this->_M_gcount = 0;
williamr@4
  1445
williamr@4
  1446
  if (__sentry) {
williamr@4
  1447
    basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
williamr@4
  1448
williamr@4
  1449
    if (__src)
williamr@4
  1450
      this->_M_gcount = __src->egptr() != __src->gptr()
williamr@4
  1451
        ? _M_copy_buffered(this,  __src, &__dest,
williamr@4
  1452
                           _Scan_for_char_val<_Traits>(__delim),
williamr@4
  1453
                           _Eq_char_bound<_Traits>(__delim),
williamr@4
  1454
                           false, false)
williamr@4
  1455
        : _M_copy_unbuffered(this,  __src, &__dest,
williamr@4
  1456
                             _Eq_char_bound<_Traits>(__delim),
williamr@4
  1457
                             false, false);
williamr@4
  1458
  }
williamr@4
  1459
williamr@4
  1460
  if (this->_M_gcount == 0)
williamr@4
  1461
    this->setstate(ios_base::failbit);
williamr@4
  1462
williamr@4
  1463
  return *this;
williamr@4
  1464
}
williamr@4
  1465
williamr@4
  1466
// Copying characters into a streambuf.
williamr@4
  1467
template <class _CharT, class _Traits>
williamr@4
  1468
basic_istream<_CharT, _Traits>&
williamr@4
  1469
basic_istream<_CharT, _Traits>
williamr@4
  1470
  ::operator>>(basic_streambuf<_CharT, _Traits>* __dest)
williamr@4
  1471
{
williamr@4
  1472
  streamsize __n = 0;
williamr@4
  1473
  typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
williamr@4
  1474
  _Sentry __sentry(*this);
williamr@4
  1475
  if (__sentry) {
williamr@4
  1476
    basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
williamr@4
  1477
    if (__src && __dest)
williamr@4
  1478
      __n = __src->egptr() != __src->gptr()
williamr@4
  1479
        ? _M_copy_buffered(this,  __src, __dest,
williamr@4
  1480
                           _Project2nd<const _CharT*, const _CharT*>(),
williamr@4
  1481
                           _Constant_unary_fun<bool, int_type>(false),
williamr@4
  1482
                           false, true)
williamr@4
  1483
        : _M_copy_unbuffered(this,  __src, __dest,
williamr@4
  1484
                             _Constant_unary_fun<bool, int_type>(false),
williamr@4
  1485
                             false, true);
williamr@4
  1486
  }
williamr@4
  1487
williamr@4
  1488
  if (__n == 0)
williamr@4
  1489
    this->setstate(ios_base::failbit);
williamr@4
  1490
williamr@4
  1491
  return *this;
williamr@4
  1492
}
williamr@4
  1493
williamr@4
  1494
// ----------------------------------------------------------------
williamr@4
  1495
// basic_iostream<> class
williamr@4
  1496
// ----------------------------------------------------------------
williamr@4
  1497
williamr@4
  1498
template <class _CharT, class _Traits>
williamr@4
  1499
_STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits>
williamr@4
  1500
  ::basic_iostream(basic_streambuf<_CharT, _Traits>* __buf)
williamr@4
  1501
    : basic_ios<_CharT, _Traits>(),
williamr@4
  1502
      basic_istream<_CharT, _Traits>(__buf),
williamr@4
  1503
      basic_ostream<_CharT, _Traits>(__buf)
williamr@4
  1504
{
williamr@4
  1505
  this->init(__buf);
williamr@4
  1506
}
williamr@4
  1507
williamr@4
  1508
template <class _CharT, class _Traits>
williamr@4
  1509
_STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits>::~basic_iostream()
williamr@4
  1510
{}
williamr@4
  1511
williamr@4
  1512
williamr@4
  1513
template <class _CharT, class _Traits>
williamr@4
  1514
_STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits>
williamr@4
  1515
    ::basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
williamr@4
  1516
    basic_ios<_CharT, _Traits>(), _M_gcount(0) {
williamr@4
  1517
    this->init(__buf);
williamr@4
  1518
  }
williamr@4
  1519
williamr@4
  1520
template <class _CharT, class _Traits>
williamr@4
  1521
_STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits>
williamr@4
  1522
  ::~basic_istream() {}
williamr@4
  1523
williamr@4
  1524
williamr@4
  1525
williamr@4
  1526
_STLP_END_NAMESPACE
williamr@4
  1527
williamr@4
  1528
# undef __BIS_int_type__
williamr@4
  1529
# undef __BIS_pos_type__
williamr@4
  1530
# undef __BIS_off_type__
williamr@4
  1531
williamr@4
  1532
# endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
williamr@4
  1533
williamr@4
  1534
#endif /* _STLP_ISTREAM_C */