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_string(__str.data(), __str.size(), __str.get_allocator())
117 { _M_stringbuf_init(__mode); }
119 #if __cplusplus >= 201103L
124 { __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0); }
134 __xfer_bufptrs __st{__rhs,
this};
135 const __streambuf_type& __base = __rhs;
136 __streambuf_type::operator=(__base);
139 _M_string = std::move(__rhs._M_string);
140 __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0);
148 __xfer_bufptrs __r_st{__rhs,
this};
149 __streambuf_type& __base = __rhs;
150 __streambuf_type::swap(__base);
151 __rhs.pubimbue(this->
pubimbue(__rhs.getloc()));
152 std::swap(_M_mode, __rhs._M_mode);
153 std::swap(_M_string, __rhs._M_string);
196 _M_stringbuf_init(_M_mode);
202 _M_stringbuf_init(ios_base::openmode __mode)
205 __size_type __len = 0;
207 __len = _M_string.
size();
208 _M_sync(const_cast<char_type*>(_M_string.
data()), 0, __len);
227 pbackfail(int_type __c = traits_type::eof());
230 overflow(int_type __c = traits_type::eof());
243 virtual __streambuf_type*
257 _M_sync(__s, __n, 0);
263 seekoff(off_type __off, ios_base::seekdir __way,
274 _M_sync(char_type* __base, __size_type __i, __size_type __o);
294 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off);
297 #if __cplusplus >= 201103L
298 #if _GLIBCXX_USE_CXX11_ABI
301 struct __xfer_bufptrs
304 : _M_to{__to}, _M_goff{-1, -1, -1}, _M_poff{-1, -1, -1}
306 const _CharT*
const __str = __from._M_string.data();
307 const _CharT* __end =
nullptr;
310 _M_goff[0] = __from.eback() - __str;
311 _M_goff[1] = __from.gptr() - __str;
312 _M_goff[2] = __from.egptr() - __str;
313 __end = __from.egptr();
317 _M_poff[0] = __from.pbase() - __str;
318 _M_poff[1] = __from.pptr() - __from.pbase();
319 _M_poff[2] = __from.epptr() - __str;
320 if (__from.pptr() > __end)
321 __end = __from.pptr();
330 __mut_from._M_string._M_length(__end - __str);
336 char_type* __str =
const_cast<char_type*
>(_M_to->_M_string.data());
337 if (_M_goff[0] != -1)
338 _M_to->setg(__str+_M_goff[0], __str+_M_goff[1], __str+_M_goff[2]);
339 if (_M_poff[0] != -1)
340 _M_to->_M_pbump(__str+_M_poff[0], __str+_M_poff[2], _M_poff[1]);
349 struct __xfer_bufptrs
358 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
359 _M_mode(__rhs._M_mode), _M_string(std::move(__rhs._M_string))
380 template<
typename _CharT,
typename _Traits,
typename _Alloc>
381 class basic_istringstream :
public basic_istream<_CharT, _Traits>
385 typedef _CharT char_type;
386 typedef _Traits traits_type;
389 typedef _Alloc allocator_type;
390 typedef typename traits_type::int_type int_type;
391 typedef typename traits_type::pos_type pos_type;
392 typedef typename traits_type::off_type off_type;
395 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
396 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
397 typedef basic_istream<char_type, traits_type> __istream_type;
400 __stringbuf_type _M_stringbuf;
419 { this->
init(&_M_stringbuf); }
436 ios_base::openmode __mode = ios_base::in)
438 { this->
init(&_M_stringbuf); }
449 #if __cplusplus >= 201103L
453 : __istream_type(std::move(__rhs)),
454 _M_stringbuf(std::move(__rhs._M_stringbuf))
455 { __istream_type::set_rdbuf(&_M_stringbuf); }
465 __istream_type::operator=(std::move(__rhs));
466 _M_stringbuf = std::move(__rhs._M_stringbuf);
473 __istream_type::swap(__rhs);
474 _M_stringbuf.swap(__rhs._M_stringbuf);
487 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
495 {
return _M_stringbuf.str(); }
505 { _M_stringbuf.str(__s); }
524 template <
typename _CharT,
typename _Traits,
typename _Alloc>
525 class basic_ostringstream :
public basic_ostream<_CharT, _Traits>
529 typedef _CharT char_type;
530 typedef _Traits traits_type;
533 typedef _Alloc allocator_type;
534 typedef typename traits_type::int_type int_type;
535 typedef typename traits_type::pos_type pos_type;
536 typedef typename traits_type::off_type off_type;
539 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
540 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
541 typedef basic_ostream<char_type, traits_type> __ostream_type;
544 __stringbuf_type _M_stringbuf;
563 { this->
init(&_M_stringbuf); }
582 { this->
init(&_M_stringbuf); }
593 #if __cplusplus >= 201103L
597 : __ostream_type(std::move(__rhs)),
598 _M_stringbuf(std::move(__rhs._M_stringbuf))
599 { __ostream_type::set_rdbuf(&_M_stringbuf); }
609 __ostream_type::operator=(std::move(__rhs));
610 _M_stringbuf = std::move(__rhs._M_stringbuf);
617 __ostream_type::swap(__rhs);
618 _M_stringbuf.swap(__rhs._M_stringbuf);
631 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
639 {
return _M_stringbuf.str(); }
649 { _M_stringbuf.str(__s); }
668 template <
typename _CharT,
typename _Traits,
typename _Alloc>
669 class basic_stringstream :
public basic_iostream<_CharT, _Traits>
673 typedef _CharT char_type;
674 typedef _Traits traits_type;
677 typedef _Alloc allocator_type;
678 typedef typename traits_type::int_type int_type;
679 typedef typename traits_type::pos_type pos_type;
680 typedef typename traits_type::off_type off_type;
683 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
684 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
685 typedef basic_iostream<char_type, traits_type> __iostream_type;
688 __stringbuf_type _M_stringbuf;
706 { this->
init(&_M_stringbuf); }
723 { this->
init(&_M_stringbuf); }
734 #if __cplusplus >= 201103L
738 : __iostream_type(std::move(__rhs)),
739 _M_stringbuf(std::move(__rhs._M_stringbuf))
740 { __iostream_type::set_rdbuf(&_M_stringbuf); }
750 __iostream_type::operator=(std::move(__rhs));
751 _M_stringbuf = std::move(__rhs._M_stringbuf);
758 __iostream_type::swap(__rhs);
759 _M_stringbuf.swap(__rhs._M_stringbuf);
772 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
780 {
return _M_stringbuf.str(); }
790 { _M_stringbuf.str(__s); }
793 #if __cplusplus >= 201103L
795 template <
class _CharT,
class _Traits,
class _Allocator>
802 template <
class _CharT,
class _Traits,
class _Allocator>
809 template <
class _CharT,
class _Traits,
class _Allocator>
816 template <
class _CharT,
class _Traits,
class _Allocator>
823 _GLIBCXX_END_NAMESPACE_CXX11
824 _GLIBCXX_END_NAMESPACE_VERSION
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
void str(const __string_type &__s)
Setting a new buffer.
__string_type str() const
Copying out the string buffer.
The actual work of input and output (interface).
virtual streamsize showmanyc()
Investigating the data available.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
void str(const __string_type &__s)
Setting a new buffer.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
static const openmode ate
Open and seek to end immediately after opening.
char_type * eback() const
Access to the get area.
basic_stringstream(ios_base::openmode __m=ios_base::out|ios_base::in)
Default constructor starts with an empty string buffer.
__string_type str() const
Copying out the string buffer.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
Controlling input and output for std::string.
char_type * pbase() const
Access to the put area.
basic_ostringstream(ios_base::openmode __mode=ios_base::out)
Default constructor starts with an empty string buffer.
Template class basic_ostream.
virtual int_type underflow()
Fetches more data from the controlled sequence.
basic_ostringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::out)
Starts with an existing string buffer.
virtual pos_type seekpos(pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
const _CharT * data() const noexcept
Return const pointer to contents.
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.
The actual work of input and output (for std::string).
__string_type str() const
Copying out the string buffer.
Controlling output for std::string.
__string_type str() const
Copying out the string buffer.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
Controlling input for std::string.
static const openmode app
Seek to end before each write.
void str(const __string_type &__s)
Setting a new buffer.
static const openmode out
Open for output. Default for ofstream and fstream.
basic_istringstream(ios_base::openmode __mode=ios_base::in)
Default constructor starts with an empty string buffer.
Template class basic_istream.
~basic_istringstream()
The destructor does nothing.
char_type * egptr() const
Access to the get area.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
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.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
~basic_ostringstream()
The destructor does nothing.
static const openmode in
Open for input. Default for ifstream and fstream.
basic_stringbuf(ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an empty string buffer.
char_type * gptr() const
Access to the get area.
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
Template class basic_iostream.
basic_istringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::in)
Starts with an existing string buffer.
~basic_stringstream()
The destructor does nothing.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
void str(const __string_type &__s)
Setting a new buffer.
locale pubimbue(const locale &__loc)
Entry point for imbue().
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current stringbuf.
__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.
char_type * pptr() const
Access to the put area.