epoc32/include/stdapis/stlportv5/stl/_sstream.c
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
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@2
     1
/*
williamr@2
     2
 * Copyright (c) 1999
williamr@2
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     4
 *
williamr@4
     5
 * Copyright (c) 1999
williamr@2
     6
 * Boris Fomitchev
williamr@2
     7
 *
williamr@2
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
     9
 * or implied. Any use is at your own risk.
williamr@2
    10
 *
williamr@4
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
    12
 * without fee, provided the above notices are retained on all copies.
williamr@2
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    14
 * provided the above notices are retained, and a notice that the code was
williamr@2
    15
 * modified is included with the above copyright notice.
williamr@2
    16
 *
williamr@4
    17
 */
williamr@2
    18
williamr@2
    19
#ifndef _STLP_SSTREAM_C
williamr@2
    20
#define _STLP_SSTREAM_C
williamr@2
    21
williamr@4
    22
#ifndef _STLP_INTERNAL_SSTREAM
williamr@4
    23
#  include <stl/_sstream.h>
williamr@2
    24
#endif
williamr@2
    25
williamr@4
    26
#if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
williamr@2
    27
// no wint_t is supported for this mode
williamr@4
    28
#  define __BSB_int_type__ int
williamr@4
    29
#  define __BSB_pos_type__ streampos
williamr@4
    30
#else
williamr@4
    31
#  define __BSB_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
williamr@4
    32
#  define __BSB_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
williamr@4
    33
#endif
williamr@2
    34
williamr@2
    35
_STLP_BEGIN_NAMESPACE
williamr@2
    36
williamr@2
    37
//----------------------------------------------------------------------
williamr@2
    38
// Non-inline stringbuf member functions.
williamr@2
    39
williamr@2
    40
// Constructors.  Note that the base class constructor sets all of the
williamr@2
    41
// get and area pointers to null.
williamr@2
    42
williamr@2
    43
template <class _CharT, class _Traits, class _Alloc>
williamr@4
    44
basic_stringbuf<_CharT, _Traits, _Alloc>
williamr@2
    45
  ::basic_stringbuf(ios_base::openmode __mode)
williamr@2
    46
    : basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str()
williamr@4
    47
{}
williamr@2
    48
williamr@2
    49
template <class _CharT, class _Traits, class _Alloc>
williamr@4
    50
basic_stringbuf<_CharT, _Traits, _Alloc>
williamr@2
    51
  ::basic_stringbuf(const basic_string<_CharT, _Traits, _Alloc>& __s, ios_base::openmode __mode)
williamr@2
    52
    : basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str(__s)
williamr@2
    53
{
williamr@2
    54
  _M_set_ptrs();
williamr@2
    55
}
williamr@2
    56
williamr@2
    57
template <class _CharT, class _Traits, class _Alloc>
williamr@4
    58
basic_stringbuf<_CharT, _Traits, _Alloc>::~basic_stringbuf()
williamr@2
    59
{}
williamr@2
    60
williamr@2
    61
// Set the underlying string to a new value.
williamr@2
    62
template <class _CharT, class _Traits, class _Alloc>
williamr@4
    63
void
williamr@2
    64
basic_stringbuf<_CharT, _Traits, _Alloc>::str(const basic_string<_CharT, _Traits, _Alloc>& __s)
williamr@2
    65
{
williamr@2
    66
  _M_str = __s;
williamr@2
    67
  _M_set_ptrs();
williamr@2
    68
}
williamr@2
    69
williamr@2
    70
template <class _CharT, class _Traits, class _Alloc>
williamr@4
    71
void
williamr@2
    72
basic_stringbuf<_CharT, _Traits, _Alloc>::_M_set_ptrs() {
williamr@2
    73
  _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
williamr@2
    74
  _CharT* __data_end = __data_ptr + _M_str.size();
williamr@2
    75
  // The initial read position is the beginning of the string.
williamr@2
    76
  if (_M_mode & ios_base::in) {
williamr@2
    77
    if (_M_mode & ios_base::ate)
williamr@2
    78
      this->setg(__data_ptr, __data_end, __data_end);
williamr@2
    79
    else
williamr@2
    80
      this->setg(__data_ptr, __data_ptr, __data_end);
williamr@2
    81
  }
williamr@4
    82
williamr@2
    83
  // The initial write position is the beginning of the string.
williamr@2
    84
  if (_M_mode & ios_base::out) {
williamr@2
    85
    if (_M_mode & (ios_base::app | ios_base::ate))
williamr@2
    86
      this->setp(__data_end, __data_end);
williamr@2
    87
    else
williamr@2
    88
      this->setp(__data_ptr, __data_end);
williamr@2
    89
  }
williamr@2
    90
}
williamr@2
    91
williamr@2
    92
// Precondition: gptr() >= egptr().  Returns a character, if one is available.
williamr@2
    93
template <class _CharT, class _Traits, class _Alloc>
williamr@4
    94
__BSB_int_type__
williamr@4
    95
basic_stringbuf<_CharT, _Traits, _Alloc>::underflow() {
williamr@2
    96
  return this->gptr() != this->egptr()
williamr@2
    97
    ? _Traits::to_int_type(*this->gptr())
williamr@2
    98
    : _Traits::eof();
williamr@2
    99
}
williamr@2
   100
williamr@2
   101
// Precondition: gptr() >= egptr().
williamr@2
   102
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   103
__BSB_int_type__
williamr@4
   104
basic_stringbuf<_CharT, _Traits, _Alloc>::uflow() {
williamr@2
   105
  if (this->gptr() != this->egptr()) {
williamr@2
   106
    int_type __c = _Traits::to_int_type(*this->gptr());
williamr@2
   107
    this->gbump(1);
williamr@2
   108
    return __c;
williamr@2
   109
  }
williamr@2
   110
  else
williamr@2
   111
    return _Traits::eof();
williamr@2
   112
}
williamr@2
   113
williamr@2
   114
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   115
__BSB_int_type__
williamr@4
   116
basic_stringbuf<_CharT, _Traits, _Alloc>::pbackfail(int_type __c) {
williamr@2
   117
  if (this->gptr() != this->eback()) {
williamr@2
   118
    if (!_Traits::eq_int_type(__c, _Traits::eof())) {
williamr@4
   119
      if (_Traits::eq(_Traits::to_char_type(__c), this->gptr()[-1])) {
williamr@2
   120
        this->gbump(-1);
williamr@4
   121
        return __c;
williamr@2
   122
      }
williamr@4
   123
      else if (_M_mode & ios_base::out) {
williamr@4
   124
        this->gbump(-1);
williamr@4
   125
        *this->gptr() = _Traits::to_char_type(__c);
williamr@4
   126
        return __c;
williamr@4
   127
      }
williamr@4
   128
      else
williamr@4
   129
        return _Traits::eof();
williamr@2
   130
    }
williamr@2
   131
    else {
williamr@2
   132
      this->gbump(-1);
williamr@2
   133
      return _Traits::not_eof(__c);
williamr@2
   134
    }
williamr@2
   135
  }
williamr@4
   136
  else
williamr@2
   137
    return _Traits::eof();
williamr@2
   138
}
williamr@2
   139
williamr@2
   140
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   141
__BSB_int_type__
williamr@4
   142
basic_stringbuf<_CharT, _Traits, _Alloc>::overflow(int_type __c) {
williamr@2
   143
  // fbp : reverse order of "ifs" to pass Dietmar's test.
williamr@2
   144
  // Apparently, standard allows overflow with eof even for read-only streams.
williamr@2
   145
  if (!_Traits::eq_int_type(__c, _Traits::eof())) {
williamr@2
   146
    if (_M_mode & ios_base::out) {
williamr@2
   147
      if (!(_M_mode & ios_base::in)) {
williamr@2
   148
        // It's a write-only streambuf, so we can use special append buffer.
williamr@2
   149
        if (this->pptr() == this->epptr())
williamr@2
   150
          this->_M_append_buffer();
williamr@4
   151
williamr@2
   152
        if (this->pptr() != this->epptr()) {
williamr@2
   153
          *this->pptr() = _Traits::to_char_type(__c);
williamr@2
   154
          this->pbump(1);
williamr@2
   155
          return __c;
williamr@2
   156
        }
williamr@2
   157
        else
williamr@2
   158
          return _Traits::eof();
williamr@2
   159
      }
williamr@2
   160
      else {
williamr@2
   161
        // We're not using a special append buffer, just the string itself.
williamr@2
   162
        if (this->pptr() == this->epptr()) {
williamr@2
   163
          ptrdiff_t __offset = this->gptr() - this->eback();
williamr@2
   164
          _M_str.push_back(_Traits::to_char_type(__c));
williamr@2
   165
williamr@4
   166
          _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
williamr@4
   167
          size_t __data_size = _M_str.size();
williamr@2
   168
williamr@2
   169
          this->setg(__data_ptr, __data_ptr + __offset, __data_ptr+__data_size);
williamr@2
   170
          this->setp(__data_ptr, __data_ptr + __data_size);
williamr@2
   171
          this->pbump((int)__data_size);
williamr@2
   172
          return __c;
williamr@2
   173
        }
williamr@2
   174
        else {
williamr@2
   175
          *this->pptr() = _Traits::to_char_type(__c);
williamr@2
   176
          this->pbump(1);
williamr@2
   177
          return __c;
williamr@2
   178
        }
williamr@2
   179
      }
williamr@2
   180
    }
williamr@4
   181
    else                          // Overflow always fails if it's read-only
williamr@2
   182
      return _Traits::eof();
williamr@2
   183
  }
williamr@2
   184
  else                        // __c is EOF, so we don't have to do anything
williamr@2
   185
    return _Traits::not_eof(__c);
williamr@2
   186
}
williamr@2
   187
williamr@2
   188
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   189
streamsize
williamr@2
   190
basic_stringbuf<_CharT, _Traits, _Alloc>::xsputn(const char_type* __s,
williamr@4
   191
                                                 streamsize __n) {
williamr@2
   192
  streamsize __nwritten = 0;
williamr@2
   193
williamr@2
   194
  if ((_M_mode & ios_base::out) && __n > 0) {
williamr@2
   195
    // If the put pointer is somewhere in the middle of the string,
williamr@2
   196
    // then overwrite instead of append.
williamr@2
   197
    if (this->pbase() == _M_str.data() ) {
williamr@2
   198
      ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
williamr@2
   199
      if (__avail > __n) {
williamr@4
   200
        _Traits::copy(this->pptr(), __s, __STATIC_CAST(size_t, __n));
williamr@2
   201
        this->pbump((int)__n);
williamr@2
   202
        return __n;
williamr@2
   203
      }
williamr@2
   204
      else {
williamr@2
   205
        _Traits::copy(this->pptr(), __s, __avail);
williamr@2
   206
        __nwritten += __avail;
williamr@2
   207
        __n -= __avail;
williamr@2
   208
        __s += __avail;
williamr@2
   209
        this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
williamr@2
   210
      }
williamr@2
   211
    }
williamr@2
   212
williamr@2
   213
    // At this point we know we're appending.
williamr@2
   214
    if (_M_mode & ios_base::in) {
williamr@2
   215
      ptrdiff_t __get_offset = this->gptr() - this->eback();
williamr@4
   216
      _M_str.append(__s, __s + __STATIC_CAST(ptrdiff_t, __n));
williamr@4
   217
williamr@4
   218
      _CharT* __data_ptr = __CONST_CAST(_CharT*, _M_str.data());
williamr@2
   219
      size_t __data_size = _M_str.size();
williamr@2
   220
williamr@4
   221
      this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr + __data_size);
williamr@2
   222
      this->setp(__data_ptr, __data_ptr + __data_size);
williamr@2
   223
      this->pbump((int)__data_size);
williamr@2
   224
    }
williamr@2
   225
    else {
williamr@2
   226
      _M_append_buffer();
williamr@4
   227
      _M_str.append(__s, __s + __STATIC_CAST(ptrdiff_t, __n));
williamr@2
   228
    }
williamr@4
   229
williamr@2
   230
    __nwritten += __n;
williamr@2
   231
  }
williamr@2
   232
williamr@2
   233
  return __nwritten;
williamr@2
   234
}
williamr@2
   235
williamr@2
   236
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   237
streamsize
williamr@2
   238
basic_stringbuf<_CharT, _Traits, _Alloc>::_M_xsputnc(char_type __c,
williamr@4
   239
                                                     streamsize __n) {
williamr@2
   240
  streamsize __nwritten = 0;
williamr@2
   241
williamr@2
   242
  if ((_M_mode & ios_base::out) && __n > 0) {
williamr@2
   243
    // If the put pointer is somewhere in the middle of the string,
williamr@2
   244
    // then overwrite instead of append.
williamr@2
   245
    if (this->pbase() == _M_str.data()) {
williamr@2
   246
      ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
williamr@2
   247
      if (__avail > __n) {
williamr@4
   248
        _Traits::assign(this->pptr(), __STATIC_CAST(size_t, __n), __c);
williamr@4
   249
        this->pbump(__STATIC_CAST(int, __n));
williamr@2
   250
        return __n;
williamr@2
   251
      }
williamr@2
   252
      else {
williamr@2
   253
        _Traits::assign(this->pptr(), __avail, __c);
williamr@2
   254
        __nwritten += __avail;
williamr@2
   255
        __n -= __avail;
williamr@2
   256
        this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
williamr@2
   257
      }
williamr@2
   258
    }
williamr@2
   259
williamr@2
   260
    // At this point we know we're appending.
williamr@4
   261
    size_t __app_size = sizeof(streamsize) > sizeof(size_t) ? __STATIC_CAST(size_t, (min)(__n, __STATIC_CAST(streamsize, _M_str.max_size())))
williamr@4
   262
                                                            : __STATIC_CAST(size_t, __n);
williamr@2
   263
    if (this->_M_mode & ios_base::in) {
williamr@2
   264
      ptrdiff_t __get_offset = this->gptr() - this->eback();
williamr@4
   265
      _M_str.append(__app_size, __c);
williamr@2
   266
williamr@2
   267
      _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
williamr@2
   268
      size_t __data_size = _M_str.size();
williamr@2
   269
williamr@4
   270
      this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr + __data_size);
williamr@2
   271
      this->setp(__data_ptr, __data_ptr + __data_size);
williamr@2
   272
      this->pbump((int)__data_size);
williamr@2
   273
    }
williamr@2
   274
    else {
williamr@2
   275
      _M_append_buffer();
williamr@4
   276
      _M_str.append(__app_size, __c);
williamr@2
   277
    }
williamr@2
   278
williamr@4
   279
    __nwritten += __app_size;
williamr@2
   280
  }
williamr@2
   281
williamr@2
   282
  return __nwritten;
williamr@2
   283
}
williamr@2
   284
williamr@2
   285
// According to the C++ standard the effects of setbuf are implementation
williamr@2
   286
// defined, except that setbuf(0, 0) has no effect.  In this implementation,
williamr@2
   287
// setbuf(<anything>, n), for n > 0, calls reserve(n) on the underlying
williamr@2
   288
// string.
williamr@2
   289
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   290
basic_streambuf<_CharT, _Traits>*
williamr@4
   291
basic_stringbuf<_CharT, _Traits, _Alloc>::setbuf(_CharT*, streamsize __n) {
williamr@2
   292
  if (__n > 0) {
williamr@2
   293
    bool __do_get_area = false;
williamr@2
   294
    bool __do_put_area = false;
williamr@2
   295
    ptrdiff_t __offg = 0;
williamr@2
   296
    ptrdiff_t __offp = 0;
williamr@2
   297
williamr@2
   298
    if (this->pbase() == _M_str.data()) {
williamr@2
   299
      __do_put_area = true;
williamr@2
   300
      __offp = this->pptr() - this->pbase();
williamr@2
   301
    }
williamr@2
   302
williamr@2
   303
    if (this->eback() == _M_str.data()) {
williamr@2
   304
      __do_get_area = true;
williamr@2
   305
      __offg = this->gptr() - this->eback();
williamr@2
   306
    }
williamr@2
   307
williamr@2
   308
    if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
williamr@2
   309
      _M_append_buffer();
williamr@2
   310
williamr@4
   311
    _M_str.reserve(sizeof(streamsize) > sizeof(size_t) ? __STATIC_CAST(size_t, (min)(__n, __STATIC_CAST(streamsize, _M_str.max_size())))
williamr@4
   312
                                                       : __STATIC_CAST(size_t, __n));
williamr@2
   313
williamr@4
   314
    _CharT* __data_ptr = __CONST_CAST(_CharT*, _M_str.data());
williamr@2
   315
    size_t __data_size = _M_str.size();
williamr@2
   316
williamr@2
   317
    if (__do_get_area) {
williamr@4
   318
      this->setg(__data_ptr, __data_ptr + __offg, __data_ptr + __data_size);
williamr@2
   319
    }
williamr@2
   320
williamr@2
   321
    if (__do_put_area) {
williamr@4
   322
      this->setp(__data_ptr, __data_ptr + __data_size);
williamr@2
   323
      this->pbump((int)__offp);
williamr@2
   324
    }
williamr@2
   325
  }
williamr@2
   326
williamr@2
   327
  return this;
williamr@2
   328
}
williamr@2
   329
williamr@2
   330
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   331
__BSB_pos_type__
williamr@4
   332
basic_stringbuf<_CharT, _Traits, _Alloc>
williamr@4
   333
  ::seekoff(off_type __off,
williamr@2
   334
            ios_base::seekdir __dir,
williamr@4
   335
            ios_base::openmode __mode) {
williamr@4
   336
  __mode &= _M_mode;
williamr@2
   337
williamr@4
   338
  bool __imode  = (__mode & ios_base::in) != 0;
williamr@4
   339
  bool __omode = (__mode & ios_base::out) != 0;
williamr@4
   340
williamr@4
   341
  if ( !(__imode || __omode) )
williamr@2
   342
    return pos_type(off_type(-1));
williamr@2
   343
williamr@4
   344
  if ( (__imode && (this->gptr() == 0)) || (__omode && (this->pptr() == 0)) )
williamr@4
   345
    return pos_type(off_type(-1));
williamr@4
   346
williamr@4
   347
#ifndef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
williamr@2
   348
  if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
williamr@4
   349
    _M_append_buffer();
williamr@2
   350
#endif
williamr@2
   351
williamr@2
   352
  streamoff __newoff;
williamr@2
   353
  switch(__dir) {
williamr@2
   354
  case ios_base::beg:
williamr@2
   355
    __newoff = 0;
williamr@2
   356
    break;
williamr@2
   357
  case ios_base::end:
williamr@2
   358
    __newoff = _M_str.size();
williamr@2
   359
    break;
williamr@2
   360
  case ios_base::cur:
williamr@4
   361
    __newoff = __imode ? this->gptr() - this->eback() : this->pptr() - this->pbase();
williamr@4
   362
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
williamr@4
   363
      if ( __off == 0 ) {
williamr@4
   364
        return pos_type(__newoff);
williamr@4
   365
      }
williamr@4
   366
#endif
williamr@2
   367
    break;
williamr@2
   368
  default:
williamr@2
   369
    return pos_type(off_type(-1));
williamr@2
   370
  }
williamr@2
   371
williamr@2
   372
  __off += __newoff;
williamr@4
   373
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
williamr@4
   374
  _CharT* __data_ptr = __CONST_CAST(_CharT*, _M_str.data());
williamr@4
   375
  size_t __data_size = _M_str.size();
williamr@4
   376
#endif
williamr@2
   377
williamr@4
   378
  if (__imode) {
williamr@2
   379
    ptrdiff_t __n = this->egptr() - this->eback();
williamr@2
   380
williamr@2
   381
    if (__off < 0 || __off > __n)
williamr@2
   382
      return pos_type(off_type(-1));
williamr@4
   383
    this->setg(this->eback(), this->eback() + __STATIC_CAST(ptrdiff_t, __off),
williamr@4
   384
                              this->eback() + __STATIC_CAST(ptrdiff_t, __n));
williamr@2
   385
  }
williamr@2
   386
williamr@4
   387
  if (__omode) {
williamr@4
   388
    ptrdiff_t __n = this->epptr() - this->pbase();
williamr@4
   389
williamr@2
   390
    if (__off < 0 || __off > __n)
williamr@2
   391
      return pos_type(off_type(-1));
williamr@4
   392
#ifdef SYMBIAN_OE_ENHANCED_LOCALE_SUPPORT
williamr@4
   393
 this->setp(__data_ptr, __data_ptr+__data_size);
williamr@4
   394
#else
williamr@4
   395
    this->setp(this->pbase(), this->pbase() + __n);
williamr@4
   396
#endif
williamr@4
   397
    this->pbump((int)__off);
williamr@2
   398
  }
williamr@2
   399
williamr@2
   400
  return pos_type(__off);
williamr@2
   401
}
williamr@2
   402
williamr@2
   403
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   404
__BSB_pos_type__
williamr@2
   405
basic_stringbuf<_CharT, _Traits, _Alloc>
williamr@4
   406
  ::seekpos(pos_type __pos, ios_base::openmode __mode) {
williamr@4
   407
  __mode &= _M_mode;
williamr@2
   408
williamr@4
   409
  bool __imode  = (__mode & ios_base::in) != 0;
williamr@4
   410
  bool __omode = (__mode & ios_base::out) != 0;
williamr@4
   411
williamr@4
   412
  if ( !(__imode || __omode) )
williamr@4
   413
    return pos_type(off_type(-1));
williamr@4
   414
williamr@4
   415
  if ( (__imode && (this->gptr() == 0)) || (__omode && (this->pptr() == 0)) )
williamr@2
   416
    return pos_type(off_type(-1));
williamr@2
   417
williamr@2
   418
  const off_type __n = __pos - pos_type(off_type(0));
williamr@2
   419
  if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
williamr@2
   420
    _M_append_buffer();
williamr@2
   421
williamr@4
   422
  if (__imode) {
williamr@2
   423
    if (__n < 0 || __n > this->egptr() - this->eback())
williamr@2
   424
      return pos_type(off_type(-1));
williamr@4
   425
    this->setg(this->eback(), this->eback() + __STATIC_CAST(ptrdiff_t, __n), this->egptr());
williamr@2
   426
  }
williamr@2
   427
williamr@4
   428
  if (__omode) {
williamr@2
   429
    if (__n < 0 || size_t(__n) > _M_str.size())
williamr@2
   430
      return pos_type(off_type(-1));
williamr@2
   431
williamr@2
   432
    _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
williamr@2
   433
    size_t __data_size = _M_str.size();
williamr@4
   434
williamr@2
   435
    this->setp(__data_ptr, __data_ptr+__data_size);
williamr@2
   436
    this->pbump((int)__n);
williamr@2
   437
  }
williamr@2
   438
williamr@2
   439
  return __pos;
williamr@2
   440
}
williamr@2
   441
williamr@4
   442
// This is declared as a const member function because it is
williamr@2
   443
// called by basic_stringbuf<>::str().  Precondition: this is a
williamr@2
   444
// write-only stringbuf.  We can't use an output buffer for read-
williamr@2
   445
// write stringbufs.  Postcondition: pptr is reset to the beginning
williamr@2
   446
// of the buffer.
williamr@2
   447
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   448
void basic_stringbuf<_CharT, _Traits, _Alloc>::_M_append_buffer() const {
williamr@2
   449
  // Do we have a buffer to append?
williamr@2
   450
  if (this->pbase() == this->_M_Buf && this->pptr() != this->_M_Buf) {
williamr@2
   451
    basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
williamr@2
   452
    __this->_M_str.append((const _CharT*)this->pbase(), (const _CharT*)this->pptr());
williamr@4
   453
#ifndef __MWERKS__
williamr@2
   454
    __this->setp(__CONST_CAST(_CharT*,_M_Buf),
williamr@2
   455
                 __CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
williamr@4
   456
#else // CodeWarrior treat const char * and const char [8] as different types
williamr@4
   457
    __this->setp((_CharT*)_M_Buf,
williamr@4
   458
                 (_CharT*)(_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
williamr@4
   459
#endif
williamr@2
   460
  }
williamr@2
   461
williamr@2
   462
  // Have we run off the end of the string?
williamr@2
   463
  else if (this->pptr() == this->epptr()) {
williamr@2
   464
    basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
williamr@4
   465
#ifndef __MWERKS__
williamr@2
   466
    __this->setp(__CONST_CAST(_CharT*,_M_Buf),
williamr@2
   467
                 __CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
williamr@4
   468
#else // CodeWarrior treat const char * and const char [8] as different types
williamr@4
   469
    __this->setp((_CharT*)_M_Buf,
williamr@4
   470
                 (_CharT*)(_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
williamr@4
   471
#endif
williamr@2
   472
  }
williamr@2
   473
}
williamr@2
   474
williamr@2
   475
//----------------------------------------------------------------------
williamr@2
   476
// Non-inline istringstream member functions.
williamr@2
   477
williamr@2
   478
template <class _CharT, class _Traits, class _Alloc>
williamr@2
   479
basic_istringstream<_CharT, _Traits, _Alloc>
williamr@2
   480
  ::basic_istringstream(ios_base::openmode __mode)
williamr@2
   481
    : basic_istream<_CharT, _Traits>(0),
williamr@4
   482
      _M_buf(__mode | ios_base::in) {
williamr@2
   483
  this->init(&_M_buf);
williamr@2
   484
}
williamr@2
   485
williamr@2
   486
template <class _CharT, class _Traits, class _Alloc>
williamr@2
   487
basic_istringstream<_CharT, _Traits, _Alloc>
williamr@2
   488
  ::basic_istringstream(const _String& __str,ios_base::openmode __mode)
williamr@2
   489
    : basic_istream<_CharT, _Traits>(0),
williamr@4
   490
      _M_buf(__str, __mode | ios_base::in) {
williamr@2
   491
  this->init(&_M_buf);
williamr@2
   492
}
williamr@2
   493
williamr@2
   494
template <class _CharT, class _Traits, class _Alloc>
williamr@2
   495
basic_istringstream<_CharT, _Traits, _Alloc>::~basic_istringstream()
williamr@2
   496
{}
williamr@2
   497
williamr@2
   498
//----------------------------------------------------------------------
williamr@2
   499
// Non-inline ostringstream member functions.
williamr@2
   500
williamr@2
   501
template <class _CharT, class _Traits, class _Alloc>
williamr@2
   502
basic_ostringstream<_CharT, _Traits, _Alloc>
williamr@2
   503
  ::basic_ostringstream(ios_base::openmode __mode)
williamr@2
   504
    : basic_ostream<_CharT, _Traits>(0),
williamr@4
   505
      _M_buf(__mode | ios_base::out) {
williamr@2
   506
  this->init(&_M_buf);
williamr@2
   507
}
williamr@4
   508
williamr@2
   509
template <class _CharT, class _Traits, class _Alloc>
williamr@2
   510
basic_ostringstream<_CharT, _Traits, _Alloc>
williamr@2
   511
  ::basic_ostringstream(const _String& __str, ios_base::openmode __mode)
williamr@2
   512
    : basic_ostream<_CharT, _Traits>(0),
williamr@4
   513
      _M_buf(__str, __mode | ios_base::out) {
williamr@2
   514
  this->init(&_M_buf);
williamr@2
   515
}
williamr@2
   516
williamr@2
   517
template <class _CharT, class _Traits, class _Alloc>
williamr@2
   518
basic_ostringstream<_CharT, _Traits, _Alloc>::~basic_ostringstream()
williamr@2
   519
{}
williamr@2
   520
williamr@2
   521
//----------------------------------------------------------------------
williamr@2
   522
// Non-inline stringstream member functions.
williamr@2
   523
williamr@2
   524
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   525
basic_stringstream<_CharT, _Traits, _Alloc>
williamr@2
   526
  ::basic_stringstream(ios_base::openmode __mode)
williamr@4
   527
    : basic_iostream<_CharT, _Traits>(0), _M_buf(__mode) {
williamr@2
   528
   this->init(&_M_buf);
williamr@2
   529
}
williamr@2
   530
williamr@2
   531
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   532
basic_stringstream<_CharT, _Traits, _Alloc>
williamr@2
   533
  ::basic_stringstream(const _String& __str, ios_base::openmode __mode)
williamr@4
   534
    : basic_iostream<_CharT, _Traits>(0), _M_buf(__str, __mode) {
williamr@2
   535
  this->init(&_M_buf);
williamr@2
   536
}
williamr@2
   537
williamr@2
   538
template <class _CharT, class _Traits, class _Alloc>
williamr@2
   539
basic_stringstream<_CharT, _Traits, _Alloc>::~basic_stringstream()
williamr@2
   540
{}
williamr@2
   541
williamr@2
   542
_STLP_END_NAMESPACE
williamr@2
   543
williamr@2
   544
# undef __BSB_int_type__
williamr@2
   545
# undef __BSB_pos_type__
williamr@2
   546
williamr@4
   547
#endif /* _STLP_SSTREAM_C */
williamr@2
   548
williamr@4
   549
// Local Variables:
williamr@4
   550
// mode:C++
williamr@4
   551
// End: