33 #ifndef _GLIBCXX_SSTREAM 34 #define _GLIBCXX_SSTREAM 1 36 #ifdef _GLIBCXX_SYSHDR 37 #pragma GCC system_header 47 #define __glibcxx_want_sstream_from_string_view 50 #ifdef __cpp_lib_sstream_from_string_view 51 # include <string_view> 54 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 55 # define _GLIBCXX_LVAL_REF_QUAL & 56 # define _GLIBCXX_SSTREAM_ALWAYS_INLINE 58 # define _GLIBCXX_LVAL_REF_QUAL 60 # define _GLIBCXX_SSTREAM_ALWAYS_INLINE [[__gnu__::__always_inline__]] 63 namespace std _GLIBCXX_VISIBILITY(default)
65 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 _GLIBCXX_BEGIN_NAMESPACE_CXX11
86 template<
typename _CharT,
typename _Traits,
typename _Alloc>
87 class basic_stringbuf :
public basic_streambuf<_CharT, _Traits>
89 struct __xfer_bufptrs;
91 #if __cplusplus >= 201103L 100 typedef _CharT char_type;
101 typedef _Traits traits_type;
104 typedef _Alloc allocator_type;
105 typedef typename traits_type::int_type int_type;
106 typedef typename traits_type::pos_type pos_type;
107 typedef typename traits_type::off_type off_type;
109 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
110 typedef basic_string<char_type, _Traits, _Alloc> __string_type;
111 typedef typename __string_type::size_type __size_type;
118 __string_type _M_string;
142 : __streambuf_type(), _M_mode(__mode), _M_string()
156 : __streambuf_type(), _M_mode(),
157 _M_string(__str.
data(), __str.
size(), __str.get_allocator())
158 { _M_stringbuf_init(__mode); }
160 #if __cplusplus >= 201103L 165 { __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0); }
167 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 175 const allocator_type& __a)
176 : __streambuf_type(),
_M_mode(__mode), _M_string(__a)
184 { _M_stringbuf_init(__mode); }
186 template<
typename _SAlloc>
188 const allocator_type& __a)
192 template<
typename _SAlloc>
194 ios_base::openmode __mode,
195 const allocator_type& __a)
196 : __streambuf_type(),
_M_mode(__mode),
197 _M_string(__s.
data(), __s.
size(), __a)
198 { _M_stringbuf_init(__mode); }
200 template<
typename _SAlloc>
209 #ifdef __cpp_lib_sstream_from_string_view 210 template<
typename _Tp>
214 requires (is_convertible_v<
const _Tp&,
219 template<
typename _Tp>
221 requires (is_convertible_v<
const _Tp&,
226 template<
typename _Tp>
228 const allocator_type& __a)
229 requires (is_convertible_v<
const _Tp&,
231 : _M_string(__t, __a)
232 { _M_stringbuf_init(__mode); }
235 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 239 { __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0); }
241 allocator_type get_allocator()
const noexcept
253 __xfer_bufptrs __st{__rhs,
this};
254 const __streambuf_type&
__base = __rhs;
255 __streambuf_type::operator=(__base);
257 _M_mode = __rhs._M_mode;
259 __rhs._M_sync(const_cast<char_type*>(__rhs._M_string.data()), 0, 0);
267 __xfer_bufptrs __r_st{__rhs,
this};
268 __streambuf_type&
__base = __rhs;
270 __rhs.pubimbue(this->
pubimbue(__rhs.getloc()));
271 std::swap(_M_mode, __rhs._M_mode);
272 std::swap(_M_string, __rhs._M_string);
288 str() const _GLIBCXX_LVAL_REF_QUAL
291 if (char_type* __hi = _M_high_mark())
292 __ret.
assign(this->pbase(), __hi);
298 #if __cplusplus > 201703L 299 #if _GLIBCXX_USE_CXX11_ABI 302 template<__allocator_like _SAlloc>
305 str(
const _SAlloc& __sa)
const 308 return { __sv.data(), __sv.size(), __sa };
316 if (char_type* __hi = _M_high_mark())
318 if (_M_string.
data() == this->
pbase()) [[likely]]
320 _M_string._M_set_length(__hi - this->pbase());
326 _M_sync(_M_string.
data(), 0, 0);
331 _GLIBCXX_SSTREAM_ALWAYS_INLINE
333 view()
const noexcept
335 if (char_type* __hi = _M_high_mark())
336 return { this->
pbase(), __hi };
350 str(
const __string_type& __s)
355 _M_stringbuf_init(_M_mode);
358 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 361 template<__allocator_like _SAlloc>
362 requires (!is_same_v<_SAlloc, _Alloc>)
367 _M_stringbuf_init(_M_mode);
372 str(__string_type&& __s)
375 _M_stringbuf_init(_M_mode);
379 #ifdef __cpp_lib_sstream_from_string_view 380 template <
typename _Tp>
383 requires (is_convertible_v<
const _Tp&,
388 _M_stringbuf_init(_M_mode);
395 _M_stringbuf_init(ios_base::openmode __mode)
398 __size_type __len = 0;
400 __len = _M_string.
size();
401 _M_sync(const_cast<char_type*>(_M_string.
data()), 0, __len);
420 pbackfail(int_type __c = traits_type::eof());
423 overflow(int_type __c = traits_type::eof());
436 virtual __streambuf_type*
450 _M_sync(__s, __n, 0);
456 seekoff(off_type __off, ios_base::seekdir __way,
467 _M_sync(char_type*
__base, __size_type __i, __size_type __o);
474 if (char_type* __pptr = this->
pptr())
476 char_type* __egptr = this->
egptr();
477 if (!__egptr || __pptr > __egptr)
482 this->
setg(__pptr, __pptr, __pptr);
490 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off);
497 __attribute__((__always_inline__))
499 _M_high_mark()
const _GLIBCXX_NOEXCEPT
501 if (char_type* __pptr = this->
pptr())
503 char_type* __egptr = this->
egptr();
504 if (!__egptr || __pptr > __egptr)
512 #if __cplusplus >= 201103L 513 #if _GLIBCXX_USE_CXX11_ABI 516 struct __xfer_bufptrs
519 : _M_to{__to}, _M_goff{-1, -1, -1}, _M_poff{-1, -1, -1}
521 const _CharT*
const __str = __from._M_string.data();
522 const _CharT* __end =
nullptr;
525 _M_goff[0] = __from.eback() - __str;
526 _M_goff[1] = __from.gptr() - __str;
527 _M_goff[2] = __from.egptr() - __str;
528 __end = __from.egptr();
532 _M_poff[0] = __from.pbase() - __str;
533 _M_poff[1] = __from.pptr() - __from.pbase();
534 _M_poff[2] = __from.epptr() - __str;
535 if (!__end || __from.pptr() > __end)
536 __end = __from.pptr();
545 __mut_from._M_string._M_length(__end - __str);
551 char_type* __str =
const_cast<char_type*
>(_M_to->_M_string.data());
552 if (_M_goff[0] != -1)
553 _M_to->setg(__str+_M_goff[0], __str+_M_goff[1], __str+_M_goff[2]);
554 if (_M_poff[0] != -1)
555 _M_to->_M_pbump(__str+_M_poff[0], __str+_M_poff[2], _M_poff[1]);
564 struct __xfer_bufptrs
573 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
577 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 584 : __streambuf_type(static_cast<const __streambuf_type&>(__rhs)),
607 template<
typename _CharT,
typename _Traits,
typename _Alloc>
612 typedef _CharT char_type;
613 typedef _Traits traits_type;
616 typedef _Alloc allocator_type;
617 typedef typename traits_type::int_type int_type;
618 typedef typename traits_type::pos_type pos_type;
619 typedef typename traits_type::off_type off_type;
627 __stringbuf_type _M_stringbuf;
642 : __istream_type(), _M_stringbuf(
ios_base::in)
659 : __istream_type(), _M_stringbuf(__mode |
ios_base::in)
678 : __istream_type(), _M_stringbuf(__str, __mode |
ios_base::in)
690 #if __cplusplus >= 201103L 695 _M_stringbuf(
std::move(__rhs._M_stringbuf))
698 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 701 : __istream_type(), _M_stringbuf(__mode |
ios_base::in, __a)
710 template<
typename _SAlloc>
712 const allocator_type& __a)
716 template<
typename _SAlloc>
718 ios_base::openmode __mode,
719 const allocator_type& __a)
720 : __istream_type(), _M_stringbuf(__str, __mode |
ios_base::in, __a)
723 template<
typename _SAlloc>
731 #ifdef __cpp_lib_sstream_from_string_view 732 template <
typename _Tp>
736 requires (is_convertible_v<
const _Tp&,
741 template <
typename _Tp>
743 requires (is_convertible_v<
const _Tp&,
748 template <
typename _Tp>
750 const allocator_type& __a)
751 requires (is_convertible_v<
const _Tp&,
753 : __istream_type(), _M_stringbuf(__t, __mode |
ios_base::in, __a)
765 __istream_type::operator=(
std::move(__rhs));
766 _M_stringbuf =
std::move(__rhs._M_stringbuf);
774 _M_stringbuf.swap(__rhs._M_stringbuf);
796 str() const _GLIBCXX_LVAL_REF_QUAL
797 {
return _M_stringbuf.str(); }
799 #if __cplusplus > 201703L 800 #if _GLIBCXX_USE_CXX11_ABI 803 template<__allocator_like _SAlloc>
806 str(
const _SAlloc& __sa)
const 807 {
return _M_stringbuf.str(__sa); }
813 {
return std::move(_M_stringbuf).str(); }
816 _GLIBCXX_SSTREAM_ALWAYS_INLINE
818 view()
const noexcept
819 {
return _M_stringbuf.view(); }
829 str(
const __string_type& __s)
830 { _M_stringbuf.str(__s); }
832 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 835 template<__allocator_like _SAlloc>
836 requires (!is_same_v<_SAlloc, _Alloc>)
839 { _M_stringbuf.str(__s); }
843 str(__string_type&& __s)
847 #ifdef __cpp_lib_sstream_from_string_view 848 template<
typename _Tp>
851 requires (is_convertible_v<
const _Tp&,
853 { _M_stringbuf.str(__t); }
873 template <
typename _CharT,
typename _Traits,
typename _Alloc>
878 typedef _CharT char_type;
879 typedef _Traits traits_type;
882 typedef _Alloc allocator_type;
883 typedef typename traits_type::int_type int_type;
884 typedef typename traits_type::pos_type pos_type;
885 typedef typename traits_type::off_type off_type;
893 __stringbuf_type _M_stringbuf;
908 : __ostream_type(), _M_stringbuf(
ios_base::out)
925 : __ostream_type(), _M_stringbuf(__mode |
ios_base::out)
944 : __ostream_type(), _M_stringbuf(__str, __mode |
ios_base::out)
956 #if __cplusplus >= 201103L 961 _M_stringbuf(
std::move(__rhs._M_stringbuf))
964 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 967 : __ostream_type(), _M_stringbuf(__mode |
ios_base::out, __a)
976 template<
typename _SAlloc>
978 const allocator_type& __a)
982 template<
typename _SAlloc>
984 ios_base::openmode __mode,
985 const allocator_type& __a)
986 : __ostream_type(), _M_stringbuf(__str, __mode |
ios_base::out, __a)
989 template<
typename _SAlloc>
997 #ifdef __cpp_lib_sstream_from_string_view 998 template <
typename _Tp>
1002 requires (is_convertible_v<
const _Tp&,
1007 template <
typename _Tp>
1009 requires (is_convertible_v<
const _Tp&,
1014 template <
typename _Tp>
1016 const allocator_type& __a)
1017 requires (is_convertible_v<
const _Tp&,
1019 : __ostream_type(), _M_stringbuf(__t, __mode |
ios_base::out, __a)
1031 __ostream_type::operator=(
std::move(__rhs));
1032 _M_stringbuf =
std::move(__rhs._M_stringbuf);
1040 _M_stringbuf.swap(__rhs._M_stringbuf);
1062 str() const _GLIBCXX_LVAL_REF_QUAL
1063 {
return _M_stringbuf.str(); }
1065 #if __cplusplus > 201703L 1066 #if _GLIBCXX_USE_CXX11_ABI 1069 template<__allocator_like _SAlloc>
1072 str(
const _SAlloc& __sa)
const 1073 {
return _M_stringbuf.str(__sa); }
1079 {
return std::move(_M_stringbuf).str(); }
1082 _GLIBCXX_SSTREAM_ALWAYS_INLINE
1084 view()
const noexcept
1085 {
return _M_stringbuf.view(); }
1096 { _M_stringbuf.str(__s); }
1098 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 1101 template<__allocator_like _SAlloc>
1102 requires (!is_same_v<_SAlloc, _Alloc>)
1105 { _M_stringbuf.str(__s); }
1109 str(__string_type&& __s)
1113 #ifdef __cpp_lib_sstream_from_string_view 1114 template<
typename _Tp>
1117 requires (is_convertible_v<
const _Tp&,
1119 { _M_stringbuf.str(__t); }
1139 template <
typename _CharT,
typename _Traits,
typename _Alloc>
1144 typedef _CharT char_type;
1145 typedef _Traits traits_type;
1148 typedef _Alloc allocator_type;
1149 typedef typename traits_type::int_type int_type;
1150 typedef typename traits_type::pos_type pos_type;
1151 typedef typename traits_type::off_type off_type;
1159 __stringbuf_type _M_stringbuf;
1189 : __iostream_type(), _M_stringbuf(__m)
1206 : __iostream_type(), _M_stringbuf(__str, __m)
1218 #if __cplusplus >= 201103L 1223 _M_stringbuf(
std::move(__rhs._M_stringbuf))
1226 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 1229 : __iostream_type(), _M_stringbuf(__mode, __a)
1236 : __iostream_type(), _M_stringbuf(
std::move(__str), __mode)
1239 template<
typename _SAlloc>
1241 const allocator_type& __a)
1245 template<
typename _SAlloc>
1247 ios_base::openmode __mode,
1248 const allocator_type& __a)
1249 : __iostream_type(), _M_stringbuf(__str, __mode, __a)
1252 template<
typename _SAlloc>
1261 #ifdef __cpp_lib_sstream_from_string_view 1262 template <
typename _Tp>
1266 requires (is_convertible_v<
const _Tp&,
1271 template <
typename _Tp>
1273 requires (is_convertible_v<
const _Tp&,
1278 template <
typename _Tp>
1280 const allocator_type& __a)
1282 : __iostream_type(), _M_stringbuf(__t, __mode, __a)
1294 __iostream_type::operator=(
std::move(__rhs));
1295 _M_stringbuf =
std::move(__rhs._M_stringbuf);
1303 _M_stringbuf.swap(__rhs._M_stringbuf);
1325 str() const _GLIBCXX_LVAL_REF_QUAL
1326 {
return _M_stringbuf.str(); }
1328 #if __cplusplus > 201703L 1329 #if _GLIBCXX_USE_CXX11_ABI 1332 template<__allocator_like _SAlloc>
1335 str(
const _SAlloc& __sa)
const 1336 {
return _M_stringbuf.str(__sa); }
1342 {
return std::move(_M_stringbuf).str(); }
1345 _GLIBCXX_SSTREAM_ALWAYS_INLINE
1347 view()
const noexcept
1348 {
return _M_stringbuf.view(); }
1359 { _M_stringbuf.str(__s); }
1361 #if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI 1364 template<__allocator_like _SAlloc>
1365 requires (!is_same_v<_SAlloc, _Alloc>)
1368 { _M_stringbuf.str(__s); }
1372 str(__string_type&& __s)
1376 #ifdef __cpp_lib_sstream_from_string_view 1377 template<
typename _Tp>
1380 requires (is_convertible_v<
const _Tp&,
1382 { _M_stringbuf.str(__t); }
1386 #if __cplusplus >= 201103L 1388 template <
class _CharT,
class _Traits,
class _Allocator>
1392 noexcept(noexcept(__x.swap(__y)))
1396 template <
class _CharT,
class _Traits,
class _Allocator>
1403 template <
class _CharT,
class _Traits,
class _Allocator>
1410 template <
class _CharT,
class _Traits,
class _Allocator>
1417 _GLIBCXX_END_NAMESPACE_CXX11
1418 _GLIBCXX_END_NAMESPACE_VERSION
1421 #undef _GLIBCXX_SSTREAM_ALWAYS_INLINE 1422 #undef _GLIBCXX_LVAL_REF_QUAL constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
Uniform interface to all allocator types.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
static const openmode app
Seek to end before each write.
char_type * egptr() const
Access to the get area.
__string_type str() const
Copying out the string buffer.
~basic_ostringstream()
The destructor does nothing.
char_type * eback() const
Access to the get area.
static const openmode in
Open for input. Default for ifstream and fstream.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
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.
typename __detected_or_t< is_empty< _Alloc >, __equal, _Alloc >::type is_always_equal
Whether all instances of the allocator type compare equal.
const _CharT * data() const noexcept
Return const pointer to contents.
char_type * pbase() const
Access to the put area.
virtual int_type overflow(int_type __c=traits_type::eof())
Consumes data from the buffer; writes to the controlled sequence.
basic_ostringstream(ios_base::openmode __mode)
Starts with an empty string buffer.
basic_ostringstream()
Default constructor starts with an empty string buffer.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
static const openmode out
Open for output. Default for ofstream and fstream.
~basic_istringstream()
The destructor does nothing.
basic_stringstream()
Default constructor starts with an empty string buffer.
~basic_stringstream()
The destructor does nothing.
basic_stringstream(ios_base::openmode __m)
Starts with an empty string buffer.
basic_stringbuf(const __string_type &__str, ios_base::openmode __mode=ios_base::in|ios_base::out)
Starts with an existing string buffer.
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.
void str(const __string_type &__s)
Setting a new buffer.
virtual int_type pbackfail(int_type __c=traits_type::eof())
Tries to back up the input sequence.
Template class basic_ostream.
ISO C++ entities toplevel namespace is std.
void str(const __string_type &__s)
Setting a new buffer.
__string_type str() const
Copying out the string buffer.
virtual int_type underflow()
Fetches more data from the controlled sequence.
A non-owning reference to a string.
Controlling input and output for std::string.
basic_stringbuf()
Starts with an empty string buffer.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
static const openmode ate
Open and seek to end immediately after opening.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
virtual streamsize showmanyc()
Investigating the data available.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
__string_type str() const
Copying out the string buffer.
__detected_or_t< false_type, __pocs, _Alloc > propagate_on_container_swap
How the allocator is propagated on swap.
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.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
basic_stringstream(const __string_type &__str, ios_base::openmode __m=ios_base::out|ios_base::in)
Starts with an existing string buffer.
basic_ostringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::out)
Starts with an existing string buffer.
The actual work of input and output (for std::string).
Template class basic_istream.
allocator_type get_allocator() const noexcept
Return copy of allocator used to construct this string.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
void str(const __string_type &__s)
Setting a new buffer.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
basic_istringstream(ios_base::openmode __mode)
Starts with an empty string buffer.
__stringbuf_type * rdbuf() const
Accessing the underlying buffer.
Controlling output for std::string.
char_type * pptr() const
Access to the put area.
Template class basic_iostream.
constexpr _Iterator __base(_Iterator __it)
void swap(basic_stringstream< _CharT, _Traits, _Allocator > &__x, basic_stringstream< _CharT, _Traits, _Allocator > &__y)
Swap specialization for stringstreams.
basic_stringbuf(ios_base::openmode __mode)
Starts with an empty string buffer.
__string_type str() const
Copying out the string buffer.
basic_istringstream()
Default constructor starts with an empty string buffer.
basic_istringstream(const __string_type &__str, ios_base::openmode __mode=ios_base::in)
Starts with an existing string buffer.
Controlling input for std::string.
Managing sequences of characters and character-like objects.
char_type * gptr() const
Access to the get area.