33 #ifndef _GLIBCXX_SSTREAM
34 #define _GLIBCXX_SSTREAM 1
36 #pragma GCC system_header
42 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
43 # define _GLIBCXX_LVAL_REF_QUAL &
45 # define _GLIBCXX_LVAL_REF_QUAL
48 namespace std _GLIBCXX_VISIBILITY(default)
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 _GLIBCXX_BEGIN_NAMESPACE_CXX11
71 template<
typename _CharT,
typename _Traits,
typename _Alloc>
72 class basic_stringbuf :
public basic_streambuf<_CharT, _Traits>
74 struct __xfer_bufptrs;
76 #if __cplusplus >= 201103L
85 typedef _CharT char_type;
86 typedef _Traits traits_type;
89 typedef _Alloc allocator_type;
90 typedef typename traits_type::int_type int_type;
91 typedef typename traits_type::pos_type pos_type;
92 typedef typename traits_type::off_type off_type;
94 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
95 typedef basic_string<char_type, _Traits, _Alloc> __string_type;
96 typedef typename __string_type::size_type __size_type;
142 _M_string(__str.
data(), __str.
size(), __str.get_allocator())
143 { _M_stringbuf_init(__mode); }
145 #if __cplusplus >= 201103L
150 { __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0); }
152 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
159 const allocator_type& __a)
160 : __streambuf_type(),
_M_mode(__mode), _M_string(__a)
167 : __streambuf_type(),
_M_mode(__mode), _M_string(std::
move(__s))
168 { _M_stringbuf_init(__mode); }
170 template<
typename _SAlloc>
172 const allocator_type& __a)
176 template<
typename _SAlloc>
179 const allocator_type& __a)
180 : __streambuf_type(),
_M_mode(__mode),
181 _M_string(__s.
data(), __s.
size(), __a)
182 { _M_stringbuf_init(__mode); }
184 template<
typename _SAlloc>
194 { __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0); }
196 allocator_type get_allocator() const noexcept
208 __xfer_bufptrs __st{__rhs,
this};
209 const __streambuf_type&
__base = __rhs;
210 __streambuf_type::operator=(__base);
214 __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0);
222 __xfer_bufptrs __r_st{__rhs,
this};
223 __streambuf_type& __base = __rhs;
224 __streambuf_type::swap(__base);
225 __rhs.pubimbue(this->
pubimbue(__rhs.getloc()));
226 std::swap(_M_mode, __rhs._M_mode);
227 std::swap(_M_string, __rhs._M_string);
242 str() const _GLIBCXX_LVAL_REF_QUAL
245 if (char_type* __hi = _M_high_mark())
246 __ret.
assign(this->pbase(), __hi);
252 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
254 template<__allocator_like _SAlloc>
256 str(
const _SAlloc& __sa)
const
259 return { __sv.data(), __sv.size(), __sa };
266 if (char_type* __hi = _M_high_mark())
269 _M_string._M_set_length(_M_high_mark() - this->
pbase());
273 _M_sync(_M_string.
data(), 0, 0);
277 basic_string_view<char_type, traits_type>
278 view() const noexcept
280 if (char_type* __hi = _M_high_mark())
281 return { this->
pbase(), __hi };
300 _M_stringbuf_init(_M_mode);
303 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
305 template<__allocator_like _SAlloc>
306 requires (!is_same_v<_SAlloc, _Alloc>)
310 _M_string.
assign(__s.data(), __s.size());
311 _M_stringbuf_init(_M_mode);
316 str(__string_type&& __s)
319 _M_stringbuf_init(_M_mode);
329 __size_type __len = 0;
331 __len = _M_string.size();
332 _M_sync(const_cast<char_type*>(_M_string.
data()), 0, __len);
351 pbackfail(int_type __c = traits_type::eof());
354 overflow(int_type __c = traits_type::eof());
367 virtual __streambuf_type*
381 _M_sync(__s, __n, 0);
387 seekoff(off_type __off, ios_base::seekdir __way,
398 _M_sync(char_type* __base, __size_type __i, __size_type __o);
405 if (char_type* __pptr = this->
pptr())
407 char_type* __egptr = this->
egptr();
408 if (!__egptr || __pptr > __egptr)
413 this->
setg(__pptr, __pptr, __pptr);
421 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off);
428 __attribute__((__always_inline__))
430 _M_high_mark() const _GLIBCXX_NOEXCEPT
432 if (char_type* __pptr = this->
pptr())
434 char_type* __egptr = this->
egptr();
435 if (!__egptr || __pptr > __egptr)
443 #if __cplusplus >= 201103L
444 #if _GLIBCXX_USE_CXX11_ABI
447 struct __xfer_bufptrs
450 : _M_to{__to}, _M_goff{-1, -1, -1}, _M_poff{-1, -1, -1}
452 const _CharT*
const __str = __from._M_string.data();
453 const _CharT* __end =
nullptr;
456 _M_goff[0] = __from.eback() - __str;
457 _M_goff[1] = __from.gptr() - __str;
458 _M_goff[2] = __from.egptr() - __str;
459 __end = __from.egptr();
463 _M_poff[0] = __from.pbase() - __str;
464 _M_poff[1] = __from.pptr() - __from.pbase();
465 _M_poff[2] = __from.epptr() - __str;
466 if (!__end || __from.pptr() > __end)
467 __end = __from.pptr();
476 __mut_from._M_string._M_length(__end - __str);
482 char_type* __str =
const_cast<char_type*
>(_M_to->_M_string.data());
483 if (_M_goff[0] != -1)
484 _M_to->setg(__str+_M_goff[0], __str+_M_goff[1], __str+_M_goff[2]);
485 if (_M_poff[0] != -1)
486 _M_to->_M_pbump(__str+_M_poff[0], __str+_M_poff[2], _M_poff[1]);
495 struct __xfer_bufptrs
504 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
505 _M_mode(__rhs._M_mode), _M_string(std::
move(__rhs._M_string))
508 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
513 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
514 _M_mode(__rhs._M_mode), _M_string(std::
move(__rhs._M_string), __a)
536 template<
typename _CharT,
typename _Traits,
typename _Alloc>
537 class basic_istringstream :
public basic_istream<_CharT, _Traits>
541 typedef _CharT char_type;
542 typedef _Traits traits_type;
545 typedef _Alloc allocator_type;
546 typedef typename traits_type::int_type int_type;
547 typedef typename traits_type::pos_type pos_type;
548 typedef typename traits_type::off_type off_type;
551 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
552 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
553 typedef basic_istream<char_type, traits_type> __istream_type;
556 __stringbuf_type _M_stringbuf;
572 { this->
init(&_M_stringbuf); }
589 { this->
init(&_M_stringbuf); }
608 { this->
init(&_M_stringbuf); }
619 #if __cplusplus >= 201103L
623 : __istream_type(std::move(__rhs)),
624 _M_stringbuf(std::move(__rhs._M_stringbuf))
625 { __istream_type::set_rdbuf(&_M_stringbuf); }
627 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
629 : __istream_type(), _M_stringbuf(__mode | ios_base::
in, __a)
635 : __istream_type(), _M_stringbuf(std::move(__str), __mode | ios_base::
in)
638 template<
typename _SAlloc>
640 const allocator_type& __a)
644 template<
typename _SAlloc>
647 const allocator_type& __a)
648 : __istream_type(), _M_stringbuf(__str, __mode | ios_base::
in, __a)
651 template<
typename _SAlloc>
667 __istream_type::operator=(
std::move(__rhs));
668 _M_stringbuf =
std::move(__rhs._M_stringbuf);
675 __istream_type::swap(__rhs);
676 _M_stringbuf.swap(__rhs._M_stringbuf);
689 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
696 str() const _GLIBCXX_LVAL_REF_QUAL
697 {
return _M_stringbuf.str(); }
699 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
701 template<__allocator_like _SAlloc>
703 str(
const _SAlloc& __sa)
const
704 {
return _M_stringbuf.str(__sa); }
709 {
return std::move(_M_stringbuf).str(); }
711 basic_string_view<char_type, traits_type>
712 view() const noexcept
713 {
return _M_stringbuf.view(); }
724 { _M_stringbuf.str(__s); }
726 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
728 template<__allocator_like _SAlloc>
729 requires (!is_same_v<_SAlloc, _Alloc>)
732 { _M_stringbuf.str(__s); }
736 str(__string_type&& __s)
757 template <
typename _CharT,
typename _Traits,
typename _Alloc>
758 class basic_ostringstream :
public basic_ostream<_CharT, _Traits>
762 typedef _CharT char_type;
763 typedef _Traits traits_type;
766 typedef _Alloc allocator_type;
767 typedef typename traits_type::int_type int_type;
768 typedef typename traits_type::pos_type pos_type;
769 typedef typename traits_type::off_type off_type;
772 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
773 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
774 typedef basic_ostream<char_type, traits_type> __ostream_type;
777 __stringbuf_type _M_stringbuf;
793 { this->
init(&_M_stringbuf); }
810 { this->
init(&_M_stringbuf); }
829 { this->
init(&_M_stringbuf); }
840 #if __cplusplus >= 201103L
844 : __ostream_type(std::move(__rhs)),
845 _M_stringbuf(std::move(__rhs._M_stringbuf))
846 { __ostream_type::set_rdbuf(&_M_stringbuf); }
848 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
850 : __ostream_type(), _M_stringbuf(__mode | ios_base::
out, __a)
856 : __ostream_type(), _M_stringbuf(std::move(__str), __mode | ios_base::
out)
859 template<
typename _SAlloc>
861 const allocator_type& __a)
865 template<
typename _SAlloc>
868 const allocator_type& __a)
869 : __ostream_type(), _M_stringbuf(__str, __mode | ios_base::
out, __a)
872 template<
typename _SAlloc>
888 __ostream_type::operator=(
std::move(__rhs));
889 _M_stringbuf =
std::move(__rhs._M_stringbuf);
896 __ostream_type::swap(__rhs);
897 _M_stringbuf.swap(__rhs._M_stringbuf);
910 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
917 str() const _GLIBCXX_LVAL_REF_QUAL
918 {
return _M_stringbuf.str(); }
920 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
922 template<__allocator_like _SAlloc>
924 str(
const _SAlloc& __sa)
const
925 {
return _M_stringbuf.str(__sa); }
930 {
return std::move(_M_stringbuf).str(); }
932 basic_string_view<char_type, traits_type>
933 view() const noexcept
934 {
return _M_stringbuf.view(); }
945 { _M_stringbuf.str(__s); }
947 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
949 template<__allocator_like _SAlloc>
950 requires (!is_same_v<_SAlloc, _Alloc>)
953 { _M_stringbuf.str(__s); }
957 str(__string_type&& __s)
978 template <
typename _CharT,
typename _Traits,
typename _Alloc>
979 class basic_stringstream :
public basic_iostream<_CharT, _Traits>
983 typedef _CharT char_type;
984 typedef _Traits traits_type;
987 typedef _Alloc allocator_type;
988 typedef typename traits_type::int_type int_type;
989 typedef typename traits_type::pos_type pos_type;
990 typedef typename traits_type::off_type off_type;
993 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
994 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
995 typedef basic_iostream<char_type, traits_type> __iostream_type;
998 __stringbuf_type _M_stringbuf;
1014 { this->
init(&_M_stringbuf); }
1029 { this->
init(&_M_stringbuf); }
1046 { this->
init(&_M_stringbuf); }
1057 #if __cplusplus >= 201103L
1061 : __iostream_type(std::move(__rhs)),
1062 _M_stringbuf(std::move(__rhs._M_stringbuf))
1063 { __iostream_type::set_rdbuf(&_M_stringbuf); }
1065 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
1067 : __iostream_type(), _M_stringbuf(__mode, __a)
1068 { this->
init(&_M_stringbuf); }
1074 : __iostream_type(), _M_stringbuf(std::move(__str), __mode)
1077 template<
typename _SAlloc>
1079 const allocator_type& __a)
1083 template<
typename _SAlloc>
1086 const allocator_type& __a)
1087 : __iostream_type(), _M_stringbuf(__str, __mode, __a)
1090 template<
typename _SAlloc>
1107 __iostream_type::operator=(
std::move(__rhs));
1108 _M_stringbuf =
std::move(__rhs._M_stringbuf);
1115 __iostream_type::swap(__rhs);
1116 _M_stringbuf.swap(__rhs._M_stringbuf);
1129 {
return const_cast<__stringbuf_type*
>(&_M_stringbuf); }
1136 str() const _GLIBCXX_LVAL_REF_QUAL
1137 {
return _M_stringbuf.str(); }
1139 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
1141 template<__allocator_like _SAlloc>
1143 str(
const _SAlloc& __sa)
const
1144 {
return _M_stringbuf.str(__sa); }
1149 {
return std::move(_M_stringbuf).str(); }
1151 basic_string_view<char_type, traits_type>
1152 view() const noexcept
1153 {
return _M_stringbuf.view(); }
1164 { _M_stringbuf.str(__s); }
1166 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
1168 template<__allocator_like _SAlloc>
1169 requires (!is_same_v<_SAlloc, _Alloc>)
1172 { _M_stringbuf.str(__s); }
1176 str(__string_type&& __s)
1181 #if __cplusplus >= 201103L
1183 template <
class _CharT,
class _Traits,
class _Allocator>
1187 noexcept(noexcept(__x.swap(__y)))
1191 template <
class _CharT,
class _Traits,
class _Allocator>
1198 template <
class _CharT,
class _Traits,
class _Allocator>
1205 template <
class _CharT,
class _Traits,
class _Allocator>
1212 _GLIBCXX_END_NAMESPACE_CXX11
1213 _GLIBCXX_END_NAMESPACE_VERSION
1216 #undef _GLIBCXX_LVAL_REF_QUAL
__string_type str() const
Copying out the string buffer.
basic_stringstream(ios_base::openmode __m)
Starts with an empty string buffer.
~basic_istringstream()
The destructor does nothing.
char_type * pbase() const
Access to the put area.
The actual work of input and output (for std::string).
Template class basic_iostream.
basic_ostringstream()
Default constructor starts with an empty string buffer.
char_type * eback() const
Access to the get area.
basic_stringbuf()
Starts with an empty string buffer.
basic_stringbuf(ios_base::openmode __mode)
Starts with an empty string buffer.
virtual int_type underflow()
Fetches more data from the controlled sequence.
Uniform interface to all allocator types.
void str(const __string_type &__s)
Setting a new buffer.
const _CharT * data() const noexcept
Return const pointer to contents.
__detected_or_t< false_type, __pocs, _Alloc > propagate_on_container_swap
How the allocator is propagated on swap.
basic_stringstream()
Default constructor starts with an empty string buffer.
~basic_stringstream()
The destructor does nothing.
virtual streamsize showmanyc()
Investigating the data available.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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.
basic_stringbuf(const __string_type &__str, ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an existing string buffer.
_Ios_Openmode openmode
This is a bitmask type.
The actual work of input and output (interface).
basic_stringstream(const __string_type &__str, ios_base::openmode __m=ios_base::out|ios_base::in)
Starts with an existing string buffer.
Controlling output for std::string.
basic_istringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::in)
Starts with an existing string buffer.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
basic_ostringstream(ios_base::openmode __mode)
Starts with an empty string buffer.
char_type * egptr() const
Access to the get area.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
Controlling input for std::string.
basic_istringstream(ios_base::openmode __mode)
Starts with an empty string buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
__detected_or_t< typename is_empty< _Alloc >::type, __equal, _Alloc > is_always_equal
Whether all instances of the allocator type compare equal.
__string_type str() const
Copying out the string 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 init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
char_type * pptr() const
Access to the put area.
basic_istringstream()
Default constructor starts with an empty string buffer.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
static const openmode out
Open for output. Default for ofstream and fstream.
Controlling input and output for std::string.
void str(const __string_type &__s)
Setting a new buffer.
char_type * gptr() const
Access to the get area.
void str(const __string_type &__s)
Setting a new buffer.
virtual pos_type seekpos(pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
Template class basic_istream.
constexpr _Iterator __base(_Iterator __it)
basic_ostringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::out)
Starts with an existing string buffer.
Template class basic_ostream.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
static const openmode app
Seek to end before each write.
~basic_ostringstream()
The destructor does nothing.
static const openmode in
Open for input. Default for ifstream and fstream.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
__string_type str() const
Copying out the string buffer.
locale pubimbue(const locale &__loc)
Entry point for imbue().
void str(const __string_type &__s)
Setting a new buffer.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current stringbuf.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.