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;
88 __string_type _M_string;
101 : __streambuf_type(), _M_mode(__mode), _M_string()
115 : __streambuf_type(), _M_mode(), _M_string(__str.data(), __str.size())
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);
137 _M_mode = __rhs._M_mode;
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()));
151 std::swap(_M_mode, __rhs._M_mode);
152 std::swap(_M_string, __rhs._M_string);
173 __ret = __string_type(this->
pbase(), this->
pptr());
175 __ret = __string_type(this->
pbase(), this->
egptr());
190 str(
const __string_type& __s)
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*
const __str = __from._M_string.data();
306 const _CharT* __end =
nullptr;
309 _M_goff[0] = __from.eback() - __str;
310 _M_goff[1] = __from.gptr() - __str;
311 _M_goff[2] = __from.egptr() - __str;
312 __end = __from.egptr();
316 _M_poff[0] = __from.pbase() - __str;
317 _M_poff[1] = __from.pptr() - __from.pbase();
318 _M_poff[2] = __from.epptr() - __str;
319 if (__from.pptr() > __end)
320 __end = __from.pptr();
329 __mut_from._M_string._M_length(__end - __str);
335 char_type* __str =
const_cast<char_type*
>(_M_to->_M_string.data());
336 if (_M_goff[0] != -1)
337 _M_to->setg(__str+_M_goff[0], __str+_M_goff[1], __str+_M_goff[2]);
338 if (_M_poff[0] != -1)
339 _M_to->_M_pbump(__str+_M_poff[0], __str+_M_poff[2], _M_poff[1]);
348 struct __xfer_bufptrs
357 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
358 _M_mode(__rhs._M_mode), _M_string(std::move(__rhs._M_string))
379 template<
typename _CharT,
typename _Traits,
typename _Alloc>
384 typedef _CharT char_type;
385 typedef _Traits traits_type;
388 typedef _Alloc allocator_type;
389 typedef typename traits_type::int_type int_type;
390 typedef typename traits_type::pos_type pos_type;
391 typedef typename traits_type::off_type off_type;
399 __stringbuf_type _M_stringbuf;
417 : __istream_type(), _M_stringbuf(__mode |
ios_base::in)
418 { this->init(&_M_stringbuf); }
436 : __istream_type(), _M_stringbuf(__str, __mode |
ios_base::in)
437 { this->init(&_M_stringbuf); }
448 #if __cplusplus >= 201103L 452 : __istream_type(std::move(__rhs)),
453 _M_stringbuf(std::move(__rhs._M_stringbuf))
454 { __istream_type::set_rdbuf(&_M_stringbuf); }
464 __istream_type::operator=(std::move(__rhs));
465 _M_stringbuf = std::move(__rhs._M_stringbuf);
473 _M_stringbuf.swap(__rhs._M_stringbuf);
486 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
494 {
return _M_stringbuf.str(); }
503 str(
const __string_type& __s)
504 { _M_stringbuf.str(__s); }
523 template <
typename _CharT,
typename _Traits,
typename _Alloc>
528 typedef _CharT char_type;
529 typedef _Traits traits_type;
532 typedef _Alloc allocator_type;
533 typedef typename traits_type::int_type int_type;
534 typedef typename traits_type::pos_type pos_type;
535 typedef typename traits_type::off_type off_type;
543 __stringbuf_type _M_stringbuf;
561 : __ostream_type(), _M_stringbuf(__mode |
ios_base::out)
562 { this->init(&_M_stringbuf); }
580 : __ostream_type(), _M_stringbuf(__str, __mode |
ios_base::out)
581 { this->init(&_M_stringbuf); }
592 #if __cplusplus >= 201103L 596 : __ostream_type(std::move(__rhs)),
597 _M_stringbuf(std::move(__rhs._M_stringbuf))
598 { __ostream_type::set_rdbuf(&_M_stringbuf); }
608 __ostream_type::operator=(std::move(__rhs));
609 _M_stringbuf = std::move(__rhs._M_stringbuf);
617 _M_stringbuf.swap(__rhs._M_stringbuf);
630 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
638 {
return _M_stringbuf.str(); }
647 str(
const __string_type& __s)
648 { _M_stringbuf.str(__s); }
667 template <
typename _CharT,
typename _Traits,
typename _Alloc>
672 typedef _CharT char_type;
673 typedef _Traits traits_type;
676 typedef _Alloc allocator_type;
677 typedef typename traits_type::int_type int_type;
678 typedef typename traits_type::pos_type pos_type;
679 typedef typename traits_type::off_type off_type;
687 __stringbuf_type _M_stringbuf;
704 : __iostream_type(), _M_stringbuf(__m)
705 { this->init(&_M_stringbuf); }
721 : __iostream_type(), _M_stringbuf(__str, __m)
722 { this->init(&_M_stringbuf); }
733 #if __cplusplus >= 201103L 737 : __iostream_type(std::move(__rhs)),
738 _M_stringbuf(std::move(__rhs._M_stringbuf))
739 { __iostream_type::set_rdbuf(&_M_stringbuf); }
749 __iostream_type::operator=(std::move(__rhs));
750 _M_stringbuf = std::move(__rhs._M_stringbuf);
758 _M_stringbuf.swap(__rhs._M_stringbuf);
771 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
779 {
return _M_stringbuf.str(); }
788 str(
const __string_type& __s)
789 { _M_stringbuf.str(__s); }
792 #if __cplusplus >= 201103L 794 template <
class _CharT,
class _Traits,
class _Allocator>
801 template <
class _CharT,
class _Traits,
class _Allocator>
808 template <
class _CharT,
class _Traits,
class _Allocator>
815 template <
class _CharT,
class _Traits,
class _Allocator>
822 _GLIBCXX_END_NAMESPACE_CXX11
823 _GLIBCXX_END_NAMESPACE_VERSION
static const openmode app
Seek to end before each write.
basic_istringstream(ios_base::openmode __mode=ios_base::in)
Default constructor starts with an empty string buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
__string_type str() const
Copying out the string buffer.
void str(const __string_type &__s)
Setting a new buffer.
Controlling input for std::string.
~basic_stringstream()
The destructor does nothing.
virtual pos_type seekpos(pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current stringbuf.
Template class basic_ostream.
virtual int_type pbackfail(int_type __c=traits_type::eof())
Tries to back up the input sequence.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
basic_stringstream(const __string_type &__str, ios_base::openmode __m=ios_base::out|ios_base::in)
Starts with an existing string buffer.
basic_ostringstream(ios_base::openmode __mode=ios_base::out)
Default constructor starts with an empty string buffer.
__string_type str() const
Copying out the string buffer.
char_type * pptr() const
Access to the put area.
Controlling input and output for std::string.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
virtual int_type overflow(int_type __c=traits_type::eof())
Consumes data from the buffer; writes to the controlled sequence.
Managing sequences of characters and character-like objects.
void str(const __string_type &__s)
Setting a new buffer.
virtual int_type underflow()
Fetches more data from the controlled sequence.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
basic_stringstream(ios_base::openmode __m=ios_base::out|ios_base::in)
Default constructor starts with an empty string buffer.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
char_type * gptr() const
Access to the get area.
static const openmode ate
Open and seek to end immediately after opening.
static const openmode out
Open for output. Default for ofstream and fstream.
static const openmode in
Open for input. Default for ifstream and fstream.
char_type * eback() const
Access to the get area.
const _CharT * data() const noexcept
Return const pointer to contents.
basic_istringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::in)
Starts with an existing string buffer.
basic_stringbuf(const __string_type &__str, ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an existing string buffer.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
locale pubimbue(const locale &__loc)
Entry point for imbue().
The actual work of input and output (for std::string).
Template class basic_istream.
basic_ostringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::out)
Starts with an existing string buffer.
ISO C++ entities toplevel namespace is std.
__string_type str() const
Copying out the string buffer.
Controlling output for std::string.
basic_stringbuf(ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an empty string buffer.
__string_type str() const
Copying out the string buffer.
char_type * egptr() const
Access to the get area.
char_type * pbase() const
Access to the put area.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
void str(const __string_type &__s)
Setting a new buffer.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
~basic_istringstream()
The destructor does nothing.
Template class basic_iostream.
~basic_ostringstream()
The destructor does nothing.
void swap(basic_stringstream< _CharT, _Traits, _Allocator > &__x, basic_stringstream< _CharT, _Traits, _Allocator > &__y)
Swap specialization for stringstreams.
void str(const __string_type &__s)
Setting a new buffer.
virtual streamsize showmanyc()
Investigating the data available.
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.