33template<
class _CharT,
class _Traits,
class _Allocator>
34basic_stringbuf<_CharT, _Traits, _Allocator>::
35basic_stringbuf (
const _C_string_type& __str, ios_base::openmode __mode)
36 : basic_streambuf<_CharT, _Traits>(__mode)
43template<
class _CharT,
class _Traits,
class _Allocator>
44basic_stringbuf<_CharT, _Traits, _Allocator>::
45basic_stringbuf (
const char_type *__s, ios_base::openmode __mode)
46 : basic_streambuf<_CharT, _Traits>(__mode)
50 str (__s, traits_type::length (__s));
54template <
class _CharT,
class _Traits,
class _Allocator>
56basic_stringbuf<_CharT, _Traits, _Allocator>::
61 if (this->_C_own_buf ())
62 _ValueAlloc ().deallocate (this->_C_buffer, this->_C_bufsize);
67template<
class _CharT,
class _Traits,
class _Allocator>
69basic_stringbuf<_CharT, _Traits, _Allocator>::
70str (
const char_type *__s, _RWSTD_SIZE_T __slen)
79 if (_RWSTD_SIZE_MAX == __slen)
80 __slen = traits_type::length (__s);
86 _RWSTD_SIZE_T __bufsize = __slen;
90 if (__s == this->_C_buffer) {
94 _C_catchup (this->eback ());
98 __slen = this->egptr () - this->pbase ();
100 __off = this->pptr () - this->pbase ();
103 if (this->_C_bufsize < __bufsize) {
110 const _RWSTD_SIZE_T __cap =
112 (this->_C_bufsize >> 10) * __ratio
113 + (((this->_C_bufsize & 0x3ff) * __ratio) >> 10)
116 __bufsize = __cap < __bufsize ? __bufsize : __cap;
118 if (__s != this->_C_buffer && this->_C_own_buf ()) {
123 __alloc.deallocate (this->_C_buffer, this->_C_bufsize);
127 __buf = __alloc.allocate (__bufsize);
129 else if (0 < __bufsize) {
131 __buf = this->_C_buffer;
132 __bufsize = this->_C_bufsize;
143 char_type*
const __egptr = __buf + __slen;
147 traits_type::copy (__buf, __s, __slen);
149 if (this->_C_buffer != __buf) {
150 if (this->_C_buffer && this->_C_own_buf ())
151 __alloc.deallocate (this->_C_buffer, this->_C_bufsize);
154 this->_C_own_buf (
true);
156 this->_C_buffer = __buf;
157 this->_C_bufsize = __bufsize;
161 if (this->_C_is_in ())
162 this->setg (this->_C_buffer, this->_C_buffer, __egptr);
167 this->setg (__egptr, __egptr, __egptr);
170 if (this->_C_is_out ()) {
171 this->setp (this->_C_buffer, this->_C_buffer + this->_C_bufsize);
177 else if ( this->_C_state & ios_base::in
178 || this->_C_state & (ios_base::app | ios_base::ate)) {
181 this->pbump (__slen);
189template <
class _CharT,
class _Traits,
class _Allocator>
191basic_stringbuf<_CharT, _Traits, _Allocator>::
192xsputn (
const char_type* __s, streamsize __n)
197 if (__n <= 0 || !this->_C_is_out ())
200 if (this->epptr () - this->pptr () < __n) {
203 const _RWSTD_SIZE_T __bufsize =
204 __n + (this->pptr () - this->pbase ());
206 _RWSTD_PTRDIFF_T __off = -1;
208 if (this->pbase () <= __s && this->pptr () > __s) {
212 __off = this->pbase () - __s;
217 str (this->_C_buffer, __bufsize);
223 __s = this->pbase () + __off;
228 traits_type::copy (this->pptr (), __s, __n);
232 _C_catchup (this->eback ());
238template <
class _CharT,
class _Traits,
class _Allocator>
240basic_stringbuf<_CharT, _Traits, _Allocator>::
246 _C_catchup (this->eback ());
248 return streamsize (this->egptr () - this->gptr ());
252template <
class _CharT,
class _Traits,
class _Allocator>
253 typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
254basic_stringbuf<_CharT, _Traits, _Allocator>::
259 if (this->gptr () < this->egptr ()) {
263 return traits_type::to_int_type (*this->gptr ());
265 else if (this->gptr () < this->pptr ()) {
268 _C_catchup (this->eback ());
270 if (this->gptr () < this->egptr ())
271 return traits_type::to_int_type (*this->gptr ());
274 return traits_type::eof ();
278template<
class _CharT,
class _Traits,
class _Allocator>
279typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
280basic_stringbuf<_CharT, _Traits, _Allocator>::
281overflow (int_type __c)
287 if (this->_C_is_eof (__c))
288 return traits_type::not_eof (__c);
290 if (!this->_C_is_out ())
291 return traits_type::eof ();
293 char_type*
const __bufend = this->_C_buffer + this->_C_bufsize;
295 if (this->pptr () == this->epptr ()) {
297 str (this->_C_buffer, this->_C_bufsize + 1);
299 else if (this->epptr () < __bufend) {
303 this->setp (this->pbase (), __bufend);
307 const int_type __retval = this->sputc (traits_type::to_char_type (__c));
310 _C_catchup (this->_C_buffer);
316template<
class _CharT,
class _Traits,
class _Allocator>
317 typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
318basic_stringbuf<_CharT, _Traits, _Allocator>::
319pbackfail (int_type __c)
323 if (!this->_C_putback_avail ())
324 return traits_type::eof ();
328 const char_type __ch = traits_type::to_char_type (__c);
330 if (traits_type::eq (__ch, *(this->gptr () - 1)) || this->_C_is_eof (__c)) {
333 __retval = traits_type::not_eof (__c);
335 else if (this->_C_is_out ()) {
338 traits_type::assign (*this->gptr (), __ch);
342 __retval = traits_type::eof ();
348template<
class _CharT,
class _Traits,
class _Allocator>
349 basic_streambuf<_CharT, _Traits>*
350basic_stringbuf<_CharT, _Traits, _Allocator>::
359 this->pptr () : this->egptr ()) - this->pbase ();
361 if (__n < __slen || !this->_C_is_out())
368 const bool __own_old_buf = this->_C_own_buf ();
374 __buf = _ValueAlloc ().allocate (__n);
375 this->_C_own_buf (
true);
378 this->_C_own_buf (
false);
381 traits_type::copy (__buf, this->_C_buffer, __slen);
384 _ValueAlloc ().deallocate (this->_C_buffer, this->_C_bufsize);
386 this->_C_buffer = __buf;
387 this->_C_bufsize = __n;
390 this->setp (this->_C_buffer, this->_C_buffer + this->_C_bufsize);
391 this->pbump (__poff);
393 char_type*
const __egptr = this->_C_buffer + __slen;
395 if (this->_C_is_in ())
396 this->setg (this->_C_buffer, this->_C_buffer + __goff, __egptr);
399 this->setg (__egptr, __egptr, __egptr);
406template<
class _CharT,
class _Traits,
class _Allocator>
407 typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
408basic_stringbuf<_CharT, _Traits, _Allocator>::
409seekoff (off_type __off, ios_base::seekdir __way, ios_base::openmode __which)
415 || ios_base::cur == __way
416 || ios_base::end == __way);
421 _C_catchup (this->eback ());
423 if (__which & ios_base::in) {
427 if (!this->_C_is_in () || __off && !this->gptr ())
428 return pos_type (off_type (-1));
431 if ( __which & ios_base::out
432 && (ios_base::cur == __way || !this->_C_is_out ()))
433 return pos_type (off_type (-1));
436 case ios_base::beg: __newoff = 0;
break;
437 case ios_base::cur: __newoff = this->gptr () - this->eback ();
break;
438 case ios_base::end: __newoff = this->egptr () - this->eback ();
break;
443 if (__newoff < 0 || this->egptr () - this->eback () < __newoff)
444 return pos_type (off_type (-1));
446 this->setg (this->eback (), this->eback () + __newoff, this->egptr ());
449 if (__which & ios_base::out) {
453 if (!this->_C_is_out () || __off && !this->pptr ())
454 return pos_type (off_type (-1));
465 case ios_base::beg: __newoff = 0;
break;
466 case ios_base::cur: __newoff = __cur;
break;
467 case ios_base::end: __newoff = __high;
break;
472 if (__newoff < 0 || __high < __newoff)
473 return pos_type (off_type (-1));
476 this->pbump (__newoff - __cur);
481 return __newoff < 0 ? pos_type (off_type (-1)) : pos_type (__newoff);
485template<
class _CharT,
class _Traits,
class _Allocator>
486 typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
487basic_stringbuf<_CharT, _Traits, _Allocator>::
488seekpos (pos_type __pos, ios_base::openmode __which)
493 typedef basic_stringbuf _StringBuf;
495 return pos_type (_StringBuf::seekoff (__pos, ios_base::beg, __which));
#define _RWSTD_MINIMUM_STRINGBUF_CAPACITY
#define _RWSTD_ALLOC_TYPE(Allocator, ignore)
#define _RWSTD_NEW_CAPACITY_RATIO
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_STREAMSIZE
#define _RWSTD_ASSERT(ignore)
#define _RWSTD_RATIO_DIVIDER