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