33 #ifndef _GLIBCXX_SSTREAM
34 #define _GLIBCXX_SSTREAM 1
36 #pragma GCC system_header
41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 _GLIBCXX_BEGIN_NAMESPACE_CXX11
64 template<
typename _CharT,
typename _Traits,
typename _Alloc>
65 class basic_stringbuf :
public basic_streambuf<_CharT, _Traits>
67 struct __xfer_bufptrs;
70 typedef _CharT char_type;
71 typedef _Traits traits_type;
74 typedef _Alloc allocator_type;
75 typedef typename traits_type::int_type int_type;
76 typedef typename traits_type::pos_type pos_type;
77 typedef typename traits_type::off_type off_type;
79 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
80 typedef basic_string<char_type, _Traits, _Alloc> __string_type;
81 typedef typename __string_type::size_type __size_type;
116 { _M_stringbuf_init(__mode); }
118 #if __cplusplus >= 201103L
123 { __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0); }
133 __xfer_bufptrs __st{__rhs,
this};
134 const __streambuf_type&
__base = __rhs;
135 __streambuf_type::operator=(__base);
138 _M_string = std::move(__rhs._M_string);
139 __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0);
147 __xfer_bufptrs __r_st{__rhs,
this};
148 __streambuf_type& __base = __rhs;
150 __rhs.pubimbue(this->
pubimbue(__rhs.getloc()));
195 _M_stringbuf_init(_M_mode);
201 _M_stringbuf_init(ios_base::openmode __mode)
204 __size_type __len = 0;
206 __len = _M_string.
size();
207 _M_sync(const_cast<char_type*>(_M_string.
data()), 0, __len);
226 pbackfail(int_type __c = traits_type::eof());
229 overflow(int_type __c = traits_type::eof());
242 virtual __streambuf_type*
256 _M_sync(__s, __n, 0);
262 seekoff(off_type __off, ios_base::seekdir __way,
273 _M_sync(char_type* __base, __size_type __i, __size_type __o);
293 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off);
296 #if __cplusplus >= 201103L
297 #if _GLIBCXX_USE_CXX11_ABI
300 struct __xfer_bufptrs
303 : _M_to{__to}, _M_goff{-1, -1, -1}, _M_poff{-1, -1, -1}
305 const _CharT* __str = __from._M_string.data();
308 _M_goff[0] = __from.eback() - __str;
309 _M_goff[1] = __from.gptr() - __str;
310 _M_goff[2] = __from.egptr() - __str;
314 _M_poff[0] = __from.pbase() - __str;
315 _M_poff[1] = __from.pptr() - __from.pbase();
316 _M_poff[2] = __from.epptr() - __str;
322 char_type* __str =
const_cast<char_type*
>(_M_to->_M_string.data());
323 if (_M_goff[0] != -1)
324 _M_to->setg(__str+_M_goff[0], __str+_M_goff[1], __str+_M_goff[2]);
325 if (_M_poff[0] != -1)
326 _M_to->_M_pbump(__str+_M_poff[0], __str+_M_poff[2], _M_poff[1]);
335 struct __xfer_bufptrs
344 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
345 _M_mode(__rhs._M_mode), _M_string(std::move(__rhs._M_string))
366 template<
typename _CharT,
typename _Traits,
typename _Alloc>
367 class basic_istringstream :
public basic_istream<_CharT, _Traits>
371 typedef _CharT char_type;
372 typedef _Traits traits_type;
375 typedef _Alloc allocator_type;
376 typedef typename traits_type::int_type int_type;
377 typedef typename traits_type::pos_type pos_type;
378 typedef typename traits_type::off_type off_type;
381 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
382 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
383 typedef basic_istream<char_type, traits_type> __istream_type;
386 __stringbuf_type _M_stringbuf;
405 { this->
init(&_M_stringbuf); }
422 ios_base::openmode __mode = ios_base::in)
424 { this->
init(&_M_stringbuf); }
435 #if __cplusplus >= 201103L
439 : __istream_type(std::move(__rhs)),
440 _M_stringbuf(std::move(__rhs._M_stringbuf))
441 { __istream_type::set_rdbuf(&_M_stringbuf); }
451 __istream_type::operator=(std::move(__rhs));
452 _M_stringbuf = std::move(__rhs._M_stringbuf);
459 __istream_type::swap(__rhs);
460 _M_stringbuf.swap(__rhs._M_stringbuf);
473 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
481 {
return _M_stringbuf.str(); }
491 { _M_stringbuf.str(__s); }
510 template <
typename _CharT,
typename _Traits,
typename _Alloc>
511 class basic_ostringstream :
public basic_ostream<_CharT, _Traits>
515 typedef _CharT char_type;
516 typedef _Traits traits_type;
519 typedef _Alloc allocator_type;
520 typedef typename traits_type::int_type int_type;
521 typedef typename traits_type::pos_type pos_type;
522 typedef typename traits_type::off_type off_type;
525 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
526 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
527 typedef basic_ostream<char_type, traits_type> __ostream_type;
530 __stringbuf_type _M_stringbuf;
549 { this->
init(&_M_stringbuf); }
568 { this->
init(&_M_stringbuf); }
579 #if __cplusplus >= 201103L
583 : __ostream_type(std::move(__rhs)),
584 _M_stringbuf(std::move(__rhs._M_stringbuf))
585 { __ostream_type::set_rdbuf(&_M_stringbuf); }
595 __ostream_type::operator=(std::move(__rhs));
596 _M_stringbuf = std::move(__rhs._M_stringbuf);
603 __ostream_type::swap(__rhs);
604 _M_stringbuf.swap(__rhs._M_stringbuf);
617 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
625 {
return _M_stringbuf.str(); }
635 { _M_stringbuf.str(__s); }
654 template <
typename _CharT,
typename _Traits,
typename _Alloc>
655 class basic_stringstream :
public basic_iostream<_CharT, _Traits>
659 typedef _CharT char_type;
660 typedef _Traits traits_type;
663 typedef _Alloc allocator_type;
664 typedef typename traits_type::int_type int_type;
665 typedef typename traits_type::pos_type pos_type;
666 typedef typename traits_type::off_type off_type;
669 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
670 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
671 typedef basic_iostream<char_type, traits_type> __iostream_type;
674 __stringbuf_type _M_stringbuf;
692 { this->
init(&_M_stringbuf); }
709 { this->
init(&_M_stringbuf); }
720 #if __cplusplus >= 201103L
724 : __iostream_type(std::move(__rhs)),
725 _M_stringbuf(std::move(__rhs._M_stringbuf))
726 { __iostream_type::set_rdbuf(&_M_stringbuf); }
736 __iostream_type::operator=(std::move(__rhs));
737 _M_stringbuf = std::move(__rhs._M_stringbuf);
744 __iostream_type::swap(__rhs);
745 _M_stringbuf.swap(__rhs._M_stringbuf);
758 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
766 {
return _M_stringbuf.str(); }
776 { _M_stringbuf.str(__s); }
779 #if __cplusplus >= 201103L
781 template <
class _CharT,
class _Traits,
class _Allocator>
788 template <
class _CharT,
class _Traits,
class _Allocator>
795 template <
class _CharT,
class _Traits,
class _Allocator>
802 template <
class _CharT,
class _Traits,
class _Allocator>
809 _GLIBCXX_END_NAMESPACE_CXX11
810 _GLIBCXX_END_NAMESPACE_VERSION
Controlling input and output for std::string.
char_type * pbase() const
Access to the put area.
basic_stringbuf(const __string_type &__str, ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an existing string buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
Controlling input for std::string.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
The actual work of input and output (for std::string).
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_istringstream()
The destructor does nothing.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
char_type * eback() const
Access to the get area.
void str(const __string_type &__s)
Setting a new buffer.
static const openmode app
Seek to end before each write.
The actual work of input and output (interface).
__string_type str() const
Copying out the string buffer.
void str(const __string_type &__s)
Setting a new buffer.
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
__string_type str() const
Copying out the string buffer.
void str(const __string_type &__s)
Setting a new buffer.
static const openmode ate
Open and seek to end immediately after opening.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current stringbuf.
__string_type str() const
Copying out the string buffer.
const _CharT * data() const noexcept
Return const pointer to contents.
basic_ostringstream(ios_base::openmode __mode=ios_base::out)
Default constructor starts with an empty string buffer.
virtual pos_type seekpos(pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
void str(const __string_type &__s)
Setting a new buffer.
Template class basic_ostream.
Template class basic_iostream.
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
virtual int_type underflow()
Fetches more data from the controlled sequence.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
basic_stringstream(ios_base::openmode __m=ios_base::out|ios_base::in)
Default constructor starts with an empty string buffer.
basic_ostringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::out)
Starts with an existing string buffer.
static const openmode in
Open for input. Default for ifstream and fstream.
static const openmode out
Open for output. Default for ofstream and fstream.
Controlling output for std::string.
char_type * gptr() const
Access to the get area.
__string_type str() const
Copying out the string buffer.
virtual streamsize showmanyc()
Investigating the data available.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
Template class basic_istream.
void swap(basic_filebuf< _CharT, _Traits > &__x, basic_filebuf< _CharT, _Traits > &__y)
Swap specialization for filebufs.
char_type * egptr() const
Access to the get area.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
char_type * pptr() const
Access to the put area.
locale pubimbue(const locale &__loc)
Entry point for imbue().
~basic_ostringstream()
The destructor does nothing.
basic_stringstream(const __string_type &__str, ios_base::openmode __m=ios_base::out|ios_base::in)
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_stringstream()
The destructor does nothing.