1.1 --- a/epoc32/include/stdapis/stlport/stl/_sstream.c Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/stlport/stl/_sstream.c Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,671 @@
1.4 -_sstream.c
1.5 +/*
1.6 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.7 + * Copyright (c) 1999
1.8 + * Silicon Graphics Computer Systems, Inc.
1.9 + *
1.10 + * Copyright (c) 1999
1.11 + * Boris Fomitchev
1.12 + *
1.13 + * This material is provided "as is", with absolutely no warranty expressed
1.14 + * or implied. Any use is at your own risk.
1.15 + *
1.16 + * Permission to use or copy this software for any purpose is hereby granted
1.17 + * without fee, provided the above notices are retained on all copies.
1.18 + * Permission to modify the code and to distribute modified code is granted,
1.19 + * provided the above notices are retained, and a notice that the code was
1.20 + * modified is included with the above copyright notice.
1.21 + *
1.22 + */
1.23 +
1.24 +#ifndef _STLP_SSTREAM_C
1.25 +#define _STLP_SSTREAM_C
1.26 +
1.27 +#ifndef _STLP_SSTREAM_H
1.28 +# include <stl/_sstream.h>
1.29 +#include <stl/_stdio_file.h>
1.30 +#endif
1.31 +
1.32 +# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
1.33 +
1.34 +# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
1.35 +// no wint_t is supported for this mode
1.36 +# define __BSB_int_type__ int
1.37 +# define __BSB_pos_type__ streampos
1.38 +# else
1.39 +# define __BSB_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
1.40 +# define __BSB_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
1.41 +# endif
1.42 +
1.43 +_STLP_BEGIN_NAMESPACE
1.44 +
1.45 +//----------------------------------------------------------------------
1.46 +// Non-inline stringbuf member functions.
1.47 +
1.48 +// Constructors. Note that the base class constructor sets all of the
1.49 +// get and area pointers to null.
1.50 +
1.51 +template <class _CharT, class _Traits, class _Alloc>
1.52 +_STLP_EXP_DECLSPEC basic_stringbuf<_CharT, _Traits, _Alloc>
1.53 + ::basic_stringbuf(ios_base::openmode __mode)
1.54 + : basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str()
1.55 +{
1.56 +#ifdef __SYMBIAN32__
1.57 +if (_M_mode & ios_base::out) {
1.58 + if (_M_mode & (ios_base::app | ios_base::ate))
1.59 + //increment the streampos to reflect the current streampos while writing
1.60 + _M_str._M_stream_pos += _M_str.size();
1.61 +}
1.62 +#endif
1.63 +}
1.64 +
1.65 +template <class _CharT, class _Traits, class _Alloc>
1.66 +_STLP_EXP_DECLSPEC basic_stringbuf<_CharT, _Traits, _Alloc>
1.67 + ::basic_stringbuf(const basic_string<_CharT, _Traits, _Alloc>& __s, ios_base::openmode __mode)
1.68 + : basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str(__s)
1.69 +{
1.70 +#ifdef __SYMBIAN32__
1.71 +if (_M_mode & ios_base::out) {
1.72 + if (_M_mode & (ios_base::app | ios_base::ate))
1.73 + //increment the streampos to reflect the current streampos while writing
1.74 + _M_str._M_stream_pos += _M_str.size();
1.75 +}
1.76 +#endif
1.77 + _M_set_ptrs();
1.78 +}
1.79 +
1.80 +template <class _CharT, class _Traits, class _Alloc>
1.81 +_STLP_EXP_DECLSPEC basic_stringbuf<_CharT, _Traits, _Alloc>::~basic_stringbuf()
1.82 +{}
1.83 +
1.84 +// Set the underlying string to a new value.
1.85 +template <class _CharT, class _Traits, class _Alloc>
1.86 +_STLP_EXP_DECLSPEC void
1.87 +basic_stringbuf<_CharT, _Traits, _Alloc>::str(const basic_string<_CharT, _Traits, _Alloc>& __s)
1.88 +{
1.89 + _M_str = __s;
1.90 + _M_set_ptrs();
1.91 +}
1.92 +
1.93 +template <class _CharT, class _Traits, class _Alloc>
1.94 +void
1.95 +basic_stringbuf<_CharT, _Traits, _Alloc>::_M_set_ptrs() {
1.96 + _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
1.97 + _CharT* __data_end = __data_ptr + _M_str.size();
1.98 + // The initial read position is the beginning of the string.
1.99 + if (_M_mode & ios_base::in) {
1.100 + if (_M_mode & ios_base::ate)
1.101 + this->setg(__data_ptr, __data_end, __data_end);
1.102 + else
1.103 + this->setg(__data_ptr, __data_ptr, __data_end);
1.104 + }
1.105 +
1.106 + // The initial write position is the beginning of the string.
1.107 + if (_M_mode & ios_base::out) {
1.108 + if (_M_mode & (ios_base::app | ios_base::ate))
1.109 + this->setp(__data_end, __data_end);
1.110 + else
1.111 + this->setp(__data_ptr, __data_end);
1.112 + }
1.113 +}
1.114 +
1.115 +// Precondition: gptr() >= egptr(). Returns a character, if one is available.
1.116 +template <class _CharT, class _Traits, class _Alloc>
1.117 +_STLP_EXP_DECLSPEC __BSB_int_type__
1.118 +basic_stringbuf<_CharT, _Traits, _Alloc>::underflow()
1.119 +{
1.120 + return this->gptr() != this->egptr()
1.121 + ? _Traits::to_int_type(*this->gptr())
1.122 + : _Traits::eof();
1.123 +}
1.124 +
1.125 +// Precondition: gptr() >= egptr().
1.126 +template <class _CharT, class _Traits, class _Alloc>
1.127 +_STLP_EXP_DECLSPEC __BSB_int_type__
1.128 +basic_stringbuf<_CharT, _Traits, _Alloc>::uflow()
1.129 +{
1.130 + if (this->gptr() != this->egptr()) {
1.131 + int_type __c = _Traits::to_int_type(*this->gptr());
1.132 + this->gbump(1);
1.133 + return __c;
1.134 + }
1.135 + else
1.136 + return _Traits::eof();
1.137 +}
1.138 +
1.139 +template <class _CharT, class _Traits, class _Alloc>
1.140 +_STLP_EXP_DECLSPEC __BSB_int_type__
1.141 +basic_stringbuf<_CharT, _Traits, _Alloc>::pbackfail(int_type __c)
1.142 +{
1.143 + if (this->gptr() != this->eback()) {
1.144 + if (!_Traits::eq_int_type(__c, _Traits::eof())) {
1.145 +
1.146 +if (_Traits::eq(_Traits::to_char_type(__c), this->gptr()[-1])
1.147 + || _M_mode == (ios_base::in | ios_base::out)) {
1.148 + this->gbump(-1);
1.149 + *this->gptr() = _Traits::to_char_type(__c);
1.150 + return _Traits::not_eof(__c);
1.151 + }
1.152 + else{
1.153 + return _Traits::eof();
1.154 + }
1.155 + }
1.156 + else {
1.157 + this->gbump(-1);
1.158 + return _Traits::not_eof(__c);
1.159 + }
1.160 + }
1.161 + else
1.162 + return _Traits::eof();
1.163 +}
1.164 +
1.165 +template <class _CharT, class _Traits, class _Alloc>
1.166 +_STLP_EXP_DECLSPEC __BSB_int_type__
1.167 +basic_stringbuf<_CharT, _Traits, _Alloc>::overflow(int_type __c)
1.168 +{
1.169 + // fbp : reverse order of "ifs" to pass Dietmar's test.
1.170 + // Apparently, standard allows overflow with eof even for read-only streams.
1.171 + if (!_Traits::eq_int_type(__c, _Traits::eof())) {
1.172 + if (_M_mode & ios_base::out) {
1.173 + if (!(_M_mode & ios_base::in)) {
1.174 + // It's a write-only streambuf, so we can use special append buffer.
1.175 + if (this->pptr() == this->epptr())
1.176 + this->_M_append_buffer();
1.177 +
1.178 + if (this->pptr() != this->epptr()) {
1.179 + *this->pptr() = _Traits::to_char_type(__c);
1.180 + this->pbump(1);
1.181 + return __c;
1.182 + }
1.183 + else
1.184 + return _Traits::eof();
1.185 + }
1.186 +
1.187 + else {
1.188 + // We're not using a special append buffer, just the string itself.
1.189 + if (this->pptr() == this->epptr()) {
1.190 + ptrdiff_t __offset = this->gptr() - this->eback();
1.191 + _M_str.push_back(_Traits::to_char_type(__c));
1.192 +
1.193 + _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
1.194 + size_t __data_size = _M_str.size();
1.195 +
1.196 + this->setg(__data_ptr, __data_ptr + __offset, __data_ptr+__data_size);
1.197 + this->setp(__data_ptr, __data_ptr + __data_size);
1.198 + this->pbump((int)__data_size);
1.199 + return __c;
1.200 + }
1.201 + else {
1.202 + *this->pptr() = _Traits::to_char_type(__c);
1.203 + this->pbump(1);
1.204 + return __c;
1.205 + }
1.206 + }
1.207 + }
1.208 + else // Overflow always fails if it's read-only
1.209 + return _Traits::eof();
1.210 + }
1.211 + else // __c is EOF, so we don't have to do anything
1.212 + return _Traits::not_eof(__c);
1.213 +}
1.214 +
1.215 +template <class _CharT, class _Traits, class _Alloc>
1.216 +_STLP_EXP_DECLSPEC streamsize
1.217 +basic_stringbuf<_CharT, _Traits, _Alloc>::xsputn(const char_type* __s,
1.218 + streamsize __n)
1.219 +{
1.220 + streamsize __nwritten = 0;
1.221 +
1.222 + if ((_M_mode & ios_base::out) && __n > 0) {
1.223 + // If the put pointer is somewhere in the middle of the string,
1.224 + // then overwrite instead of append.
1.225 + if (this->pbase() == _M_str.data() ) {
1.226 + ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
1.227 + if (__avail > __n) {
1.228 + _Traits::copy(this->pptr(), __s, __n);
1.229 + this->pbump((int)__n);
1.230 +#ifdef __SYMBIAN32__
1.231 + // _M_str._M_stream_pos += __n; //increment streampos to number of characters in stream
1.232 +#endif
1.233 + return __n;
1.234 + }
1.235 + else {
1.236 + _Traits::copy(this->pptr(), __s, __avail);
1.237 + __nwritten += __avail;
1.238 + __n -= __avail;
1.239 + __s += __avail;
1.240 +#ifdef __SYMBIAN32__
1.241 + // _M_str._M_stream_pos += __avail;//increment streampos to number of characters in stream
1.242 +#endif
1.243 + this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
1.244 + }
1.245 + }
1.246 +
1.247 + // At this point we know we're appending.
1.248 + if (_M_mode & ios_base::in) {
1.249 + ptrdiff_t __get_offset = this->gptr() - this->eback();
1.250 + _M_str.append(__s, __s + __n);
1.251 +
1.252 + _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
1.253 + size_t __data_size = _M_str.size();
1.254 +
1.255 + this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr+__data_size);
1.256 + this->setp(__data_ptr, __data_ptr + __data_size);
1.257 + this->pbump((int)__data_size);
1.258 + }
1.259 + else {
1.260 + _M_append_buffer();
1.261 +#ifdef __SYMBIAN32__
1.262 + if (_M_str._M_stream_pos >= 0
1.263 + && (_M_str._M_stream_pos < _M_str.size())) {
1.264 + if((_M_str.size() - _M_str._M_stream_pos) >= __n)
1.265 + _M_str.replace(_M_str._M_stream_pos, __n, __s);
1.266 + else
1.267 + {
1.268 + _M_str.replace(_M_str._M_stream_pos, (_M_str.size() - _M_str._M_stream_pos), __s);
1.269 + _M_str.append(__s + (__n - (_M_str.size() - _M_str._M_stream_pos)), __s + __n);
1.270 + }
1.271 + } else {
1.272 + _M_str.append(__s, __s + __n);
1.273 + }
1.274 + _M_str._M_stream_pos += __n;
1.275 +#else //__SYMBIAN32__
1.276 + _M_str.append(__s, __s + __n);
1.277 +#endif // __SYMBIAN32__
1.278 + }
1.279 + __nwritten += __n;
1.280 + }
1.281 +
1.282 + return __nwritten;
1.283 +}
1.284 +
1.285 +template <class _CharT, class _Traits, class _Alloc>
1.286 +streamsize
1.287 +basic_stringbuf<_CharT, _Traits, _Alloc>::_M_xsputnc(char_type __c,
1.288 + streamsize __n)
1.289 +{
1.290 + streamsize __nwritten = 0;
1.291 +
1.292 + if ((_M_mode & ios_base::out) && __n > 0) {
1.293 + // If the put pointer is somewhere in the middle of the string,
1.294 + // then overwrite instead of append.
1.295 + if (this->pbase() == _M_str.data()) {
1.296 + ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
1.297 + if (__avail > __n) {
1.298 + _Traits::assign(this->pptr(), __n, __c);
1.299 + this->pbump((int)__n);
1.300 + return __n;
1.301 + }
1.302 + else {
1.303 + _Traits::assign(this->pptr(), __avail, __c);
1.304 + __nwritten += __avail;
1.305 + __n -= __avail;
1.306 + this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
1.307 + }
1.308 + }
1.309 +
1.310 + // At this point we know we're appending.
1.311 + if (this->_M_mode & ios_base::in) {
1.312 + ptrdiff_t __get_offset = this->gptr() - this->eback();
1.313 + _M_str.append(__n, __c);
1.314 +
1.315 + _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
1.316 + size_t __data_size = _M_str.size();
1.317 +
1.318 + this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr+__data_size);
1.319 + this->setp(__data_ptr, __data_ptr + __data_size);
1.320 + this->pbump((int)__data_size);
1.321 +
1.322 + }
1.323 + else {
1.324 + _M_append_buffer();
1.325 +// _M_str.append(__n, __c);
1.326 +#ifdef __SYMBIAN32__
1.327 + if (_M_str._M_stream_pos >= 0
1.328 + && (_M_str._M_stream_pos < _M_str.size())) {
1.329 + if((_M_str.size() - _M_str._M_stream_pos) >= __n)
1.330 + _M_str.replace(_M_str._M_stream_pos,__n, __n, __c);
1.331 + else
1.332 + {
1.333 + _M_str.replace(_M_str._M_stream_pos, (_M_str.size() - _M_str._M_stream_pos), (_M_str.size() - _M_str._M_stream_pos), __c);
1.334 + _M_str.append(__n, __c);
1.335 + }
1.336 + } else {
1.337 + _M_str.append(__n, __c);
1.338 + }
1.339 + _M_str._M_stream_pos += __n;
1.340 +#else //__SYMBIAN32__
1.341 + _M_str.append(__n, __c);
1.342 +#endif // __SYMBIAN32__
1.343 + }
1.344 +
1.345 + __nwritten += __n;
1.346 + }
1.347 +
1.348 + return __nwritten;
1.349 +}
1.350 +
1.351 +// According to the C++ standard the effects of setbuf are implementation
1.352 +// defined, except that setbuf(0, 0) has no effect. In this implementation,
1.353 +// setbuf(<anything>, n), for n > 0, calls reserve(n) on the underlying
1.354 +// string.
1.355 +template <class _CharT, class _Traits, class _Alloc>
1.356 +_STLP_EXP_DECLSPEC basic_streambuf<_CharT, _Traits>*
1.357 +#ifdef __SYMBIAN32__
1.358 +basic_stringbuf<_CharT, _Traits, _Alloc>::setbuf(_CharT* __s, streamsize __n)
1.359 +#else
1.360 +basic_stringbuf<_CharT, _Traits, _Alloc>::setbuf(_CharT*, streamsize __n)
1.361 +#endif //__SYMBIAN32__
1.362 +{
1.363 + if (__n > 0) {
1.364 + bool __do_get_area = false;
1.365 + bool __do_put_area = false;
1.366 + ptrdiff_t __offg = 0;
1.367 + ptrdiff_t __offp = 0;
1.368 +
1.369 + if (this->pbase() == _M_str.data()) {
1.370 + __do_put_area = true;
1.371 + __offp = this->pptr() - this->pbase();
1.372 + }
1.373 +
1.374 + if (this->eback() == _M_str.data()) {
1.375 + __do_get_area = true;
1.376 + __offg = this->gptr() - this->eback();
1.377 + }
1.378 +
1.379 + if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
1.380 + _M_append_buffer();
1.381 +
1.382 + _M_str.reserve(__n);
1.383 +
1.384 + _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
1.385 +#ifdef __SYMBIAN32__
1.386 + size_t __data_size = __n;
1.387 + memmove(__data_ptr, __s, __n*sizeof(_CharT));
1.388 + _M_str._M_start = __data_ptr;
1.389 + _M_str._M_finish = __data_ptr+__n;
1.390 +#else
1.391 + size_t __data_size = _M_str.size();
1.392 +#endif //__SYMBIAN32__
1.393 +
1.394 + if (__do_get_area) {
1.395 +#ifdef __SYMBIAN32__
1.396 + this->setg(__data_ptr, __data_ptr, __data_ptr+__data_size);
1.397 +#else
1.398 + this->setg(__data_ptr, __data_ptr + __offg, __data_ptr+__data_size);
1.399 +#endif //__SYMBIAN32__
1.400 + }
1.401 +
1.402 + if (__do_put_area) {
1.403 + this->setp(__data_ptr, __data_ptr+__data_size);
1.404 +#ifndef __SYMBIAN32__
1.405 + this->pbump((int)__offp);
1.406 +#endif //__SYMBIAN32__
1.407 + }
1.408 + }
1.409 +
1.410 + return this;
1.411 +}
1.412 +
1.413 +template <class _CharT, class _Traits, class _Alloc>
1.414 +_STLP_EXP_DECLSPEC __BSB_pos_type__
1.415 +basic_stringbuf<_CharT, _Traits, _Alloc>::seekoff(off_type __off,
1.416 + ios_base::seekdir __dir,
1.417 + ios_base::openmode __mode)
1.418 +{
1.419 + bool __stl_in = false;
1.420 + bool __stl_out = false;
1.421 +
1.422 + if ((__mode & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) ) {
1.423 + if (__dir == ios_base::beg || __dir == ios_base::end)
1.424 + __stl_in = __stl_out = true;
1.425 + }
1.426 + else if (__mode & ios_base::in)
1.427 + __stl_in = true;
1.428 + else if (__mode & ios_base::out)
1.429 + __stl_out = true;
1.430 +
1.431 + if (!__stl_in && !__stl_out)
1.432 + return pos_type(off_type(-1));
1.433 + else if ((__stl_in && (!(_M_mode & ios_base::in) || this->gptr() == 0)) ||
1.434 + (__stl_out && (!(_M_mode & ios_base::out) || this->pptr() == 0)))
1.435 + return pos_type(off_type(-1));
1.436 +
1.437 +#ifdef __SYMBIAN32__
1.438 + if (_M_mode & ios_base::out)
1.439 +#else
1.440 + if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
1.441 +#endif
1.442 + _M_append_buffer();
1.443 +
1.444 + streamoff __newoff;
1.445 + switch(__dir) {
1.446 + case ios_base::beg:
1.447 + __newoff = 0;
1.448 + break;
1.449 + case ios_base::end:
1.450 + __newoff = _M_str.size();
1.451 + break;
1.452 + case ios_base::cur:
1.453 + __newoff = __stl_in ? this->gptr() - this->eback()
1.454 +#ifdef __SYMBIAN32__
1.455 + : ((this->pbase() != this->_M_str) ? _M_str._M_stream_pos
1.456 + : this->pptr() - this->pbase());
1.457 +#else
1.458 + : this->pptr() - this->pbase();
1.459 +#endif //__SYMBIAN32__
1.460 + break;
1.461 + default:
1.462 + return pos_type(off_type(-1));
1.463 + }
1.464 +
1.465 + __off += __newoff;
1.466 +
1.467 + if (__stl_in) {
1.468 + ptrdiff_t __n = this->egptr() - this->eback();
1.469 +
1.470 + if (__off < 0 || __off > __n)
1.471 + return pos_type(off_type(-1));
1.472 + else
1.473 + this->setg(this->eback(), this->eback() + __off, this->eback() + __n);
1.474 + }
1.475 +
1.476 + if (__stl_out) {
1.477 + ptrdiff_t __n;
1.478 +#ifdef __SYMBIAN32__
1.479 + //if (this->pbase() != this->_M_str) {
1.480 + void* __data_ptr1 = reinterpret_cast<void*>(this->pbase());
1.481 + _CharT* __data_ptr2 = __CONST_CAST(_CharT*,this->_M_str.data());
1.482 +
1.483 + if (__data_ptr1 != __data_ptr2) {
1.484 + __n = _M_str.size();
1.485 + } else {
1.486 +#endif // __SYMBIAN32__
1.487 + __n = this->epptr() - this->pbase();
1.488 +#ifdef __SYMBIAN32__
1.489 + }
1.490 +#endif //__SYMBIAN32__
1.491 + if (__off < 0 || __off > __n)
1.492 + return pos_type(off_type(-1));
1.493 + else {
1.494 +#ifdef __SYMBIAN32__
1.495 + void* __data_ptr1 = reinterpret_cast<void*>(this->pbase());
1.496 + _CharT* __data_ptr2 = __CONST_CAST(_CharT*,this->_M_str.data());
1.497 +
1.498 + if (__data_ptr1 != __data_ptr2) {
1.499 + _M_str._M_stream_pos = __off;
1.500 + } else {
1.501 +#endif //__SYMBIAN32__
1.502 + this->setp(this->pbase(), this->pbase() + __n);
1.503 + this->pbump((int)__off);
1.504 +#ifdef __SYMBIAN32__
1.505 + }
1.506 +#endif // __SYMBIAN32__
1.507 + }
1.508 + }
1.509 +
1.510 + return pos_type(__off);
1.511 +}
1.512 +
1.513 +template <class _CharT, class _Traits, class _Alloc>
1.514 +_STLP_EXP_DECLSPEC __BSB_pos_type__
1.515 +basic_stringbuf<_CharT, _Traits, _Alloc>
1.516 + ::seekpos(pos_type __pos, ios_base::openmode __mode)
1.517 +{
1.518 + bool __stl_in = (__mode & ios_base::in) != 0;
1.519 + bool __stl_out = (__mode & ios_base::out) != 0;
1.520 +
1.521 + if ((__stl_in && (!(_M_mode & ios_base::in) || this->gptr() == 0)) ||
1.522 + (__stl_out && (!(_M_mode & ios_base::out) || this->pptr() == 0)) ||
1.523 + (!__stl_in && !__stl_out))
1.524 + return pos_type(off_type(-1));
1.525 +
1.526 + const off_type __n = __pos - pos_type(off_type(0));
1.527 + if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
1.528 + _M_append_buffer();
1.529 +
1.530 + if (__stl_in) {
1.531 + if (__n < 0 || __n > this->egptr() - this->eback())
1.532 + return pos_type(off_type(-1));
1.533 + this->setg(this->eback(), this->eback() + __n, this->egptr());
1.534 + }
1.535 +
1.536 + if (__stl_out) {
1.537 + if (__n < 0 || size_t(__n) > _M_str.size())
1.538 + return pos_type(off_type(-1));
1.539 +
1.540 + _CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
1.541 + size_t __data_size = _M_str.size();
1.542 +
1.543 + this->setp(__data_ptr, __data_ptr+__data_size);
1.544 + this->pbump((int)__n);
1.545 + }
1.546 +
1.547 + return __pos;
1.548 +}
1.549 +
1.550 +// This is declared as a const member function because it is
1.551 +// called by basic_stringbuf<>::str(). Precondition: this is a
1.552 +// write-only stringbuf. We can't use an output buffer for read-
1.553 +// write stringbufs. Postcondition: pptr is reset to the beginning
1.554 +// of the buffer.
1.555 +template <class _CharT, class _Traits, class _Alloc>
1.556 +void basic_stringbuf<_CharT, _Traits, _Alloc>::_M_append_buffer() const
1.557 +
1.558 +{
1.559 + // Do we have a buffer to append?
1.560 + if (this->pbase() == this->_M_Buf && this->pptr() != this->_M_Buf) {
1.561 + basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
1.562 +#ifdef __SYMBIAN32__
1.563 + size_t __n = this->pptr() - this->pbase();
1.564 + if (__this->_M_str._M_stream_pos >= 0
1.565 + && (__this->_M_str._M_stream_pos != __this->_M_str.size())) {
1.566 + {
1.567 + *(this->pptr()) = (_CharT)0;
1.568 +#ifdef __SYMBIAN32__
1.569 + __this->_M_str.replace(_M_str._M_stream_pos, __n, (const _CharT*)this->pbase(), (const _CharT*)this->pptr()-(const _CharT*)this->pbase());
1.570 +#else
1.571 + __this->_M_str.replace(_M_str._M_stream_pos, __n, (const _CharT*)this->pbase());
1.572 +
1.573 +#endif
1.574 + }
1.575 + } else {
1.576 + __this->_M_str.append((const _CharT*)this->pbase(), (const _CharT*)this->pptr());
1.577 + }
1.578 + __this->_M_str._M_stream_pos += __n;
1.579 +#else // __SYMBAIN32__
1.580 + __this->_M_str.append((const _CharT*)this->pbase(), (const _CharT*)this->pptr());
1.581 +#endif // __SYMBIAN32__
1.582 + __this->setp(__CONST_CAST(_CharT*,_M_Buf),
1.583 + __CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
1.584 + }
1.585 +
1.586 + // Have we run off the end of the string?
1.587 + else if (this->pptr() == this->epptr()) {
1.588 + basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
1.589 + __this->setp(__CONST_CAST(_CharT*,_M_Buf),
1.590 + __CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
1.591 + __this->_M_str._M_stream_pos = __this->_M_str._M_finish - __this->_M_str._M_start;
1.592 + }
1.593 +}
1.594 +
1.595 +//----------------------------------------------------------------------
1.596 +// Non-inline istringstream member functions.
1.597 +
1.598 +template <class _CharT, class _Traits, class _Alloc>
1.599 +basic_istringstream<_CharT, _Traits, _Alloc>
1.600 + ::basic_istringstream(ios_base::openmode __mode)
1.601 + : basic_istream<_CharT, _Traits>(0),
1.602 + _M_buf(__mode | ios_base::in)
1.603 +{
1.604 + this->init(&_M_buf);
1.605 +}
1.606 +
1.607 +template <class _CharT, class _Traits, class _Alloc>
1.608 +basic_istringstream<_CharT, _Traits, _Alloc>
1.609 + ::basic_istringstream(const _String& __str,ios_base::openmode __mode)
1.610 + : basic_istream<_CharT, _Traits>(0),
1.611 + _M_buf(__str, __mode | ios_base::in)
1.612 +{
1.613 + this->init(&_M_buf);
1.614 +}
1.615 +
1.616 +template <class _CharT, class _Traits, class _Alloc>
1.617 +basic_istringstream<_CharT, _Traits, _Alloc>::~basic_istringstream()
1.618 +{}
1.619 +
1.620 +//----------------------------------------------------------------------
1.621 +// Non-inline ostringstream member functions.
1.622 +
1.623 +template <class _CharT, class _Traits, class _Alloc>
1.624 +basic_ostringstream<_CharT, _Traits, _Alloc>
1.625 + ::basic_ostringstream(ios_base::openmode __mode)
1.626 + : basic_ostream<_CharT, _Traits>(0),
1.627 + _M_buf(__mode | ios_base::out)
1.628 +{
1.629 + this->init(&_M_buf);
1.630 +}
1.631 +
1.632 +template <class _CharT, class _Traits, class _Alloc>
1.633 +basic_ostringstream<_CharT, _Traits, _Alloc>
1.634 + ::basic_ostringstream(const _String& __str, ios_base::openmode __mode)
1.635 + : basic_ostream<_CharT, _Traits>(0),
1.636 + _M_buf(__str, __mode | ios_base::out)
1.637 +{
1.638 + this->init(&_M_buf);
1.639 +}
1.640 +
1.641 +template <class _CharT, class _Traits, class _Alloc>
1.642 +basic_ostringstream<_CharT, _Traits, _Alloc>::~basic_ostringstream()
1.643 +{}
1.644 +
1.645 +//----------------------------------------------------------------------
1.646 +// Non-inline stringstream member functions.
1.647 +
1.648 +template <class _CharT, class _Traits, class _Alloc>
1.649 +_STLP_EXP_DECLSPEC basic_stringstream<_CharT, _Traits, _Alloc>
1.650 + ::basic_stringstream(ios_base::openmode __mode)
1.651 + : basic_iostream<_CharT, _Traits>(0), _M_buf(__mode)
1.652 +{
1.653 + this->init(&_M_buf);
1.654 +}
1.655 +
1.656 +template <class _CharT, class _Traits, class _Alloc>
1.657 +_STLP_EXP_DECLSPEC basic_stringstream<_CharT, _Traits, _Alloc>
1.658 + ::basic_stringstream(const _String& __str, ios_base::openmode __mode)
1.659 + : basic_iostream<_CharT, _Traits>(0), _M_buf(__str, __mode)
1.660 +{
1.661 + this->init(&_M_buf);
1.662 +}
1.663 +
1.664 +template <class _CharT, class _Traits, class _Alloc>
1.665 +basic_stringstream<_CharT, _Traits, _Alloc>::~basic_stringstream()
1.666 +{}
1.667 +
1.668 +_STLP_END_NAMESPACE
1.669 +
1.670 +# undef __BSB_int_type__
1.671 +# undef __BSB_pos_type__
1.672 +
1.673 +# endif /* EXPOSE */
1.674 +
1.675 +#endif /* _STLP_SSTREAM_C */