34 #ifndef _GLIBCXX_SSTREAM
35 #define _GLIBCXX_SSTREAM 1
37 #pragma GCC system_header
42 _GLIBCXX_BEGIN_NAMESPACE(std)
57 template<typename _CharT, typename _Traits, typename _Alloc>
58 class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
62 typedef _CharT char_type;
63 typedef _Traits traits_type;
66 typedef _Alloc allocator_type;
67 typedef typename traits_type::int_type int_type;
68 typedef typename traits_type::pos_type pos_type;
69 typedef typename traits_type::off_type off_type;
71 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
72 typedef basic_string<char_type, _Traits, _Alloc> __string_type;
73 typedef typename __string_type::size_type __size_type;
80 __string_type _M_string;
93 : __streambuf_type(), _M_mode(__mode), _M_string()
106 ios_base::openmode __mode = ios_base::in | ios_base::out)
107 : __streambuf_type(), _M_mode(), _M_string(__str.data(), __str.size())
108 { _M_stringbuf_init(__mode); }
126 if (this->pptr() > this->egptr())
127 __ret = __string_type(this->pbase(), this->pptr());
129 __ret = __string_type(this->pbase(), this->egptr());
144 str(
const __string_type& __s)
148 _M_stringbuf_init(_M_mode);
154 _M_stringbuf_init(ios_base::openmode __mode)
157 __size_type __len = 0;
158 if (_M_mode & (ios_base::ate | ios_base::app))
159 __len = _M_string.
size();
160 _M_sync(const_cast<char_type*>(_M_string.
data()), 0, __len);
167 if (_M_mode & ios_base::in)
170 __ret = this->egptr() - this->gptr();
179 pbackfail(int_type __c = traits_type::eof());
182 overflow(int_type __c = traits_type::eof());
195 virtual __streambuf_type*
209 _M_sync(__s, __n, 0);
215 seekoff(off_type __off, ios_base::seekdir __way,
216 ios_base::openmode __mode = ios_base::in | ios_base::out);
219 seekpos(pos_type __sp,
220 ios_base::openmode __mode = ios_base::in | ios_base::out);
226 _M_sync(char_type* __base, __size_type __i, __size_type __o);
233 const bool __testin = _M_mode & ios_base::in;
234 if (this->pptr() && this->pptr() > this->egptr())
237 this->setg(this->eback(), this->gptr(), this->pptr());
239 this->setg(this->pptr(), this->pptr(), this->pptr());
255 template<
typename _CharT,
typename _Traits,
typename _Alloc>
256 class basic_istringstream :
public basic_istream<_CharT, _Traits>
260 typedef _CharT char_type;
261 typedef _Traits traits_type;
264 typedef _Alloc allocator_type;
265 typedef typename traits_type::int_type int_type;
266 typedef typename traits_type::pos_type pos_type;
267 typedef typename traits_type::off_type off_type;
270 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
271 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
272 typedef basic_istream<char_type, traits_type> __istream_type;
275 __stringbuf_type _M_stringbuf;
294 { this->init(&_M_stringbuf); }
311 ios_base::openmode __mode = ios_base::in)
313 { this->init(&_M_stringbuf); }
333 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
341 {
return _M_stringbuf.str(); }
350 str(
const __string_type& __s)
351 { _M_stringbuf.str(__s); }
365 template <
typename _CharT,
typename _Traits,
typename _Alloc>
366 class basic_ostringstream :
public basic_ostream<_CharT, _Traits>
370 typedef _CharT char_type;
371 typedef _Traits traits_type;
374 typedef _Alloc allocator_type;
375 typedef typename traits_type::int_type int_type;
376 typedef typename traits_type::pos_type pos_type;
377 typedef typename traits_type::off_type off_type;
380 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
381 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
382 typedef basic_ostream<char_type, traits_type> __ostream_type;
385 __stringbuf_type _M_stringbuf;
404 { this->init(&_M_stringbuf); }
421 ios_base::openmode __mode = ios_base::out)
423 { this->init(&_M_stringbuf); }
443 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
451 {
return _M_stringbuf.str(); }
460 str(
const __string_type& __s)
461 { _M_stringbuf.str(__s); }
475 template <
typename _CharT,
typename _Traits,
typename _Alloc>
476 class basic_stringstream :
public basic_iostream<_CharT, _Traits>
480 typedef _CharT char_type;
481 typedef _Traits traits_type;
484 typedef _Alloc allocator_type;
485 typedef typename traits_type::int_type int_type;
486 typedef typename traits_type::pos_type pos_type;
487 typedef typename traits_type::off_type off_type;
490 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
491 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
492 typedef basic_iostream<char_type, traits_type> __iostream_type;
495 __stringbuf_type _M_stringbuf;
512 { this->init(&_M_stringbuf); }
527 ios_base::openmode __m = ios_base::out | ios_base::in)
529 { this->init(&_M_stringbuf); }
549 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
557 {
return _M_stringbuf.str(); }
566 str(
const __string_type& __s)
567 { _M_stringbuf.str(__s); }
570 _GLIBCXX_END_NAMESPACE
572 #ifndef _GLIBCXX_EXPORT_TEMPLATE
basic_ostringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::out)
Starts with an existing string buffer.
__string_type str() const
Copying out the string buffer.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
basic_stringbuf(const __string_type &__str, ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an existing string buffer.
basic_stringbuf(ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an empty string buffer.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
Merging istream and ostream capabilities.This class multiply inherits from the input and output strea...
basic_istringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::in)
Starts with an existing string buffer.
basic_istringstream(ios_base::openmode __mode=ios_base::in)
Default constructor starts with an empty string buffer.
basic_stringstream(const __string_type &__str, ios_base::openmode __m=ios_base::out|ios_base::in)
Starts with an existing string buffer.
basic_stringstream(ios_base::openmode __m=ios_base::out|ios_base::in)
Default constructor starts with an empty string buffer.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current stringbuf.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
const _CharT * data() const
Return const pointer to contents.
void str(const __string_type &__s)
Setting a new buffer.
void str(const __string_type &__s)
Setting a new buffer.
~basic_istringstream()
The destructor does nothing.
size_type size() const
Returns the number of characters in the string, not including any null-termination.
__string_type str() const
Copying out the string buffer.
virtual streamsize showmanyc()
Investigating the data available.
__string_type str() const
Copying out the string buffer.
Controlling output.This is the base class for all output streams. It provides text formatting of all ...
~basic_stringstream()
The destructor does nothing.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
__string_type str() const
Copying out the string buffer.
basic_ostringstream(ios_base::openmode __mode=ios_base::out)
Default constructor starts with an empty string buffer.
void str(const __string_type &__s)
Setting a new buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
~basic_ostringstream()
The destructor does nothing.
Controlling input.This is the base class for all input streams. It provides text formatting of all bu...
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
void str(const __string_type &__s)
Setting a new buffer.