10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_SSTREAM 110b57cec5SDimitry Andric#define _LIBCPP_SSTREAM 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 14bdd1243dSDimitry Andric sstream synopsis [sstream.syn] 150b57cec5SDimitry Andric 16bdd1243dSDimitry Andric// Class template basic_stringbuf [stringbuf] 170b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 180b57cec5SDimitry Andricclass basic_stringbuf 190b57cec5SDimitry Andric : public basic_streambuf<charT, traits> 200b57cec5SDimitry Andric{ 210b57cec5SDimitry Andricpublic: 220b57cec5SDimitry Andric typedef charT char_type; 230b57cec5SDimitry Andric typedef traits traits_type; 240b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 250b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 260b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 270b57cec5SDimitry Andric typedef Allocator allocator_type; 280b57cec5SDimitry Andric 29bdd1243dSDimitry Andric // [stringbuf.cons] constructors: 30e8d8bef9SDimitry Andric explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 31e8d8bef9SDimitry Andric basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20 32e8d8bef9SDimitry Andric explicit basic_stringbuf(ios_base::openmode which); // C++20 33*06c3fb27SDimitry Andric explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& s, 340b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 35*06c3fb27SDimitry Andric explicit basic_stringbuf(const allocator_type& a) 36*06c3fb27SDimitry Andric : basic_stringbuf(ios_base::in | ios_base::out, a) {} // C++20 37*06c3fb27SDimitry Andric basic_stringbuf(ios_base::openmode which, const allocator_type& a); // C++20 38*06c3fb27SDimitry Andric explicit basic_stringbuf(basic_string<char_type, traits_type, allocator_type>&& s, 39*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); // C++20 40*06c3fb27SDimitry Andric template <class SAlloc> 41*06c3fb27SDimitry Andric basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 42*06c3fb27SDimitry Andric : basic_stringbuf(s, ios_base::in | ios_base::out, a) {} // C++20 43*06c3fb27SDimitry Andric template <class SAlloc> 44*06c3fb27SDimitry Andric basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, 45*06c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 46*06c3fb27SDimitry Andric template <class SAlloc> 47*06c3fb27SDimitry Andric explicit basic_stringbuf(const basic_string<char_type, traits_type, SAlloc>& s, 48*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); // C++20 490b57cec5SDimitry Andric basic_stringbuf(basic_stringbuf&& rhs); 50*06c3fb27SDimitry Andric basic_stringbuf(basic_stringbuf&& rhs, const allocator_type& a); // C++20 510b57cec5SDimitry Andric 52bdd1243dSDimitry Andric // [stringbuf.assign] Assign and swap: 530b57cec5SDimitry Andric basic_stringbuf& operator=(basic_stringbuf&& rhs); 54*06c3fb27SDimitry Andric void swap(basic_stringbuf& rhs) noexcept(see below); // conditionally noexcept since C++20 550b57cec5SDimitry Andric 56bdd1243dSDimitry Andric // [stringbuf.members] Member functions: 57*06c3fb27SDimitry Andric allocator_type get_allocator() const noexcept; // C++20 58*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 59*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 60*06c3fb27SDimitry Andric template <class SAlloc> 61*06c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 62*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 63*06c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 640b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 65*06c3fb27SDimitry Andric template <class SAlloc> 66*06c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 67*06c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 680b57cec5SDimitry Andric 690b57cec5SDimitry Andricprotected: 70bdd1243dSDimitry Andric // [stringbuf.virtuals] Overridden virtual functions: 710b57cec5SDimitry Andric virtual int_type underflow(); 720b57cec5SDimitry Andric virtual int_type pbackfail(int_type c = traits_type::eof()); 730b57cec5SDimitry Andric virtual int_type overflow (int_type c = traits_type::eof()); 740b57cec5SDimitry Andric virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize); 750b57cec5SDimitry Andric virtual pos_type seekoff(off_type off, ios_base::seekdir way, 760b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 770b57cec5SDimitry Andric virtual pos_type seekpos(pos_type sp, 780b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 790b57cec5SDimitry Andric}; 800b57cec5SDimitry Andric 81bdd1243dSDimitry Andric// [stringbuf.assign] non member swap 820b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 830b57cec5SDimitry Andricvoid swap(basic_stringbuf<charT, traits, Allocator>& x, 84*06c3fb27SDimitry Andric basic_stringbuf<charT, traits, Allocator>& y); // conditionally noexcept since C++20 850b57cec5SDimitry Andric 860b57cec5SDimitry Andrictypedef basic_stringbuf<char> stringbuf; 870b57cec5SDimitry Andrictypedef basic_stringbuf<wchar_t> wstringbuf; 880b57cec5SDimitry Andric 89bdd1243dSDimitry Andric// Class template basic_istringstream [istringstream] 900b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 910b57cec5SDimitry Andricclass basic_istringstream 920b57cec5SDimitry Andric : public basic_istream<charT, traits> 930b57cec5SDimitry Andric{ 940b57cec5SDimitry Andricpublic: 950b57cec5SDimitry Andric typedef charT char_type; 960b57cec5SDimitry Andric typedef traits traits_type; 970b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 980b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 990b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 1000b57cec5SDimitry Andric typedef Allocator allocator_type; 1010b57cec5SDimitry Andric 102bdd1243dSDimitry Andric // [istringstream.cons] Constructors: 103e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 104e8d8bef9SDimitry Andric basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 105e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode which); // C++20 106*06c3fb27SDimitry Andric explicit basic_istringstream(const basic_string<char_type, traits_type, allocator_type>& s, 1070b57cec5SDimitry Andric ios_base::openmode which = ios_base::in); 108*06c3fb27SDimitry Andric basic_istringstream(ios_base::openmode which, const allocator_type& a); // C++20 109*06c3fb27SDimitry Andric explicit basic_istringstream(basic_string<char_type, traits_type, allocator_type>&& s, 110*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::in); // C++20 111*06c3fb27SDimitry Andric template <class SAlloc> 112*06c3fb27SDimitry Andric basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 113*06c3fb27SDimitry Andric : basic_istringstream(s, ios_base::in, a) {} // C++20 114*06c3fb27SDimitry Andric template <class SAlloc> 115*06c3fb27SDimitry Andric basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, 116*06c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 117*06c3fb27SDimitry Andric template <class SAlloc> 118*06c3fb27SDimitry Andric explicit basic_istringstream(const basic_string<char_type, traits_type, SAlloc>& s, 119*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::in); // C++20 1200b57cec5SDimitry Andric basic_istringstream(basic_istringstream&& rhs); 1210b57cec5SDimitry Andric 122bdd1243dSDimitry Andric // [istringstream.assign] Assign and swap: 1230b57cec5SDimitry Andric basic_istringstream& operator=(basic_istringstream&& rhs); 1240b57cec5SDimitry Andric void swap(basic_istringstream& rhs); 1250b57cec5SDimitry Andric 126bdd1243dSDimitry Andric // [istringstream.members] Member functions: 1270b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 128*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 129*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 130*06c3fb27SDimitry Andric template <class SAlloc> 131*06c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 132*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 133*06c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 1340b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 135*06c3fb27SDimitry Andric template <class SAlloc> 136*06c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 137*06c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 1380b57cec5SDimitry Andric}; 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 1410b57cec5SDimitry Andricvoid swap(basic_istringstream<charT, traits, Allocator>& x, 1420b57cec5SDimitry Andric basic_istringstream<charT, traits, Allocator>& y); 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andrictypedef basic_istringstream<char> istringstream; 1450b57cec5SDimitry Andrictypedef basic_istringstream<wchar_t> wistringstream; 1460b57cec5SDimitry Andric 147bdd1243dSDimitry Andric// Class template basic_ostringstream [ostringstream] 1480b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 1490b57cec5SDimitry Andricclass basic_ostringstream 1500b57cec5SDimitry Andric : public basic_ostream<charT, traits> 1510b57cec5SDimitry Andric{ 1520b57cec5SDimitry Andricpublic: 1530b57cec5SDimitry Andric // types: 1540b57cec5SDimitry Andric typedef charT char_type; 1550b57cec5SDimitry Andric typedef traits traits_type; 1560b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 1570b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 1580b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 1590b57cec5SDimitry Andric typedef Allocator allocator_type; 1600b57cec5SDimitry Andric 161bdd1243dSDimitry Andric // [ostringstream.cons] Constructors: 162e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 163e8d8bef9SDimitry Andric basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 164e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode which); // C++20 165*06c3fb27SDimitry Andric explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& s, 1660b57cec5SDimitry Andric ios_base::openmode which = ios_base::out); 167*06c3fb27SDimitry Andric basic_ostringstream(ios_base::openmode which, const allocator_type& a); // C++20 168*06c3fb27SDimitry Andric explicit basic_ostringstream(basic_string<char_type, traits_type, allocator_type>&& s, 169*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::out); // C++20 170*06c3fb27SDimitry Andric template <class SAlloc> 171*06c3fb27SDimitry Andric basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 172*06c3fb27SDimitry Andric : basic_ostringstream(s, ios_base::out, a) {} // C++20 173*06c3fb27SDimitry Andric template <class SAlloc> 174*06c3fb27SDimitry Andric basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, 175*06c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 176*06c3fb27SDimitry Andric template <class SAlloc> 177*06c3fb27SDimitry Andric explicit basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, 178*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::out); // C++20 1790b57cec5SDimitry Andric basic_ostringstream(basic_ostringstream&& rhs); 1800b57cec5SDimitry Andric 181bdd1243dSDimitry Andric // [ostringstream.assign] Assign and swap: 1820b57cec5SDimitry Andric basic_ostringstream& operator=(basic_ostringstream&& rhs); 1830b57cec5SDimitry Andric void swap(basic_ostringstream& rhs); 1840b57cec5SDimitry Andric 185bdd1243dSDimitry Andric // [ostringstream.members] Member functions: 1860b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 187*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 188*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 189*06c3fb27SDimitry Andric template <class SAlloc> 190*06c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 191*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 192*06c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 1930b57cec5SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 194*06c3fb27SDimitry Andric template <class SAlloc> 195*06c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 196*06c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 1970b57cec5SDimitry Andric}; 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 2000b57cec5SDimitry Andricvoid swap(basic_ostringstream<charT, traits, Allocator>& x, 2010b57cec5SDimitry Andric basic_ostringstream<charT, traits, Allocator>& y); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andrictypedef basic_ostringstream<char> ostringstream; 2040b57cec5SDimitry Andrictypedef basic_ostringstream<wchar_t> wostringstream; 2050b57cec5SDimitry Andric 206bdd1243dSDimitry Andric// Class template basic_stringstream [stringstream] 2070b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 2080b57cec5SDimitry Andricclass basic_stringstream 2090b57cec5SDimitry Andric : public basic_iostream<charT, traits> 2100b57cec5SDimitry Andric{ 2110b57cec5SDimitry Andricpublic: 2120b57cec5SDimitry Andric // types: 2130b57cec5SDimitry Andric typedef charT char_type; 2140b57cec5SDimitry Andric typedef traits traits_type; 2150b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 2160b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 2170b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 2180b57cec5SDimitry Andric typedef Allocator allocator_type; 2190b57cec5SDimitry Andric 220bdd1243dSDimitry Andric // [stringstream.cons] constructors 221e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 222e8d8bef9SDimitry Andric basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 223e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode which); // C++20 224*06c3fb27SDimitry Andric explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& s, 2250b57cec5SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); 226*06c3fb27SDimitry Andric basic_stringstream(ios_base::openmode which, const allocator_type& a); // C++20 227*06c3fb27SDimitry Andric explicit basic_stringstream(basic_string<char_type, traits_type, allocator_type>&& s, 228*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); // C++20 229*06c3fb27SDimitry Andric template <class SAlloc> 230*06c3fb27SDimitry Andric basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, const allocator_type& a) 231*06c3fb27SDimitry Andric : basic_stringstream(s, ios_base::out | ios_base::in, a) {} // C++20 232*06c3fb27SDimitry Andric template <class SAlloc> 233*06c3fb27SDimitry Andric basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, 234*06c3fb27SDimitry Andric ios_base::openmode which, const allocator_type& a); // C++20 235*06c3fb27SDimitry Andric template <class SAlloc> 236*06c3fb27SDimitry Andric explicit basic_stringstream(const basic_string<char_type, traits_type, SAlloc>& s, 237*06c3fb27SDimitry Andric ios_base::openmode which = ios_base::out | ios_base::in); // C++20 2380b57cec5SDimitry Andric basic_stringstream(basic_stringstream&& rhs); 2390b57cec5SDimitry Andric 240bdd1243dSDimitry Andric // [stringstream.assign] Assign and swap: 2410b57cec5SDimitry Andric basic_stringstream& operator=(basic_stringstream&& rhs); 2420b57cec5SDimitry Andric void swap(basic_stringstream& rhs); 2430b57cec5SDimitry Andric 244bdd1243dSDimitry Andric // [stringstream.members] Member functions: 2450b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 246*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const; // before C++20 247*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() const &; // C++20 248*06c3fb27SDimitry Andric template <class SAlloc> 249*06c3fb27SDimitry Andric basic_string<char_type, traits_type, SAlloc> str(const SAlloc& sa) const; // C++20 250*06c3fb27SDimitry Andric basic_string<char_type, traits_type, allocator_type> str() &&; // C++20 251*06c3fb27SDimitry Andric basic_string_view<char_type, traits_type> view() const noexcept; // C++20 252*06c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, allocator_type>& s); 253*06c3fb27SDimitry Andric template <class SAlloc> 254*06c3fb27SDimitry Andric void str(const basic_string<char_type, traits_type, SAlloc>& s); // C++20 255*06c3fb27SDimitry Andric void str(basic_string<char_type, traits_type, allocator_type>&& s); // C++20 2560b57cec5SDimitry Andric}; 2570b57cec5SDimitry Andric 2580b57cec5SDimitry Andrictemplate <class charT, class traits, class Allocator> 2590b57cec5SDimitry Andricvoid swap(basic_stringstream<charT, traits, Allocator>& x, 2600b57cec5SDimitry Andric basic_stringstream<charT, traits, Allocator>& y); 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andrictypedef basic_stringstream<char> stringstream; 2630b57cec5SDimitry Andrictypedef basic_stringstream<wchar_t> wstringstream; 2640b57cec5SDimitry Andric 2650b57cec5SDimitry Andric} // std 2660b57cec5SDimitry Andric 2670b57cec5SDimitry Andric*/ 2680b57cec5SDimitry Andric 26981ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 2700b57cec5SDimitry Andric#include <__config> 271*06c3fb27SDimitry Andric#include <__fwd/sstream.h> 27281ad6265SDimitry Andric#include <__utility/swap.h> 2730b57cec5SDimitry Andric#include <istream> 274fe6060f1SDimitry Andric#include <ostream> 2750b57cec5SDimitry Andric#include <string> 27604eeddc0SDimitry Andric#include <version> 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2790b57cec5SDimitry Andric# pragma GCC system_header 2800b57cec5SDimitry Andric#endif 2810b57cec5SDimitry Andric 2820b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 2830b57cec5SDimitry Andric#include <__undef_macros> 2840b57cec5SDimitry Andric 2850b57cec5SDimitry Andric 286*06c3fb27SDimitry Andric// TODO(LLVM-19): Remove this once we drop support for Clang 16, 287*06c3fb27SDimitry Andric// which had this bug: https://github.com/llvm/llvm-project/issues/40363 288*06c3fb27SDimitry Andric#ifdef _WIN32 289*06c3fb27SDimitry Andric#define _LIBCPP_HIDE_FROM_ABI_SSTREAM _LIBCPP_ALWAYS_INLINE 290*06c3fb27SDimitry Andric#else 291*06c3fb27SDimitry Andric#define _LIBCPP_HIDE_FROM_ABI_SSTREAM _LIBCPP_HIDE_FROM_ABI 292*06c3fb27SDimitry Andric#endif 293*06c3fb27SDimitry Andric 2940b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 2950b57cec5SDimitry Andric 296bdd1243dSDimitry Andric// Class template basic_stringbuf [stringbuf] 2970b57cec5SDimitry Andric 2980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2990b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_stringbuf 3000b57cec5SDimitry Andric : public basic_streambuf<_CharT, _Traits> 3010b57cec5SDimitry Andric{ 3020b57cec5SDimitry Andricpublic: 3030b57cec5SDimitry Andric typedef _CharT char_type; 3040b57cec5SDimitry Andric typedef _Traits traits_type; 3050b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 3060b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 3070b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 3080b57cec5SDimitry Andric typedef _Allocator allocator_type; 3090b57cec5SDimitry Andric 3100b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 3110b57cec5SDimitry Andric 3120b57cec5SDimitry Andricprivate: 3130b57cec5SDimitry Andric 3140b57cec5SDimitry Andric string_type __str_; 3150b57cec5SDimitry Andric mutable char_type* __hm_; 3160b57cec5SDimitry Andric ios_base::openmode __mode_; 317*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __init_buf_ptrs(); 318*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void __move_init(basic_stringbuf&& __rhs); 3190b57cec5SDimitry Andric 3200b57cec5SDimitry Andricpublic: 321bdd1243dSDimitry Andric // [stringbuf.cons] constructors: 322e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 323fe6060f1SDimitry Andric basic_stringbuf() 324fe6060f1SDimitry Andric : __hm_(nullptr), __mode_(ios_base::in | ios_base::out) {} 325e8d8bef9SDimitry Andric 326e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 327e8d8bef9SDimitry Andric explicit basic_stringbuf(ios_base::openmode __wch) 328e8d8bef9SDimitry Andric : __hm_(nullptr), __mode_(__wch) {} 329e8d8bef9SDimitry Andric 330e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 331e8d8bef9SDimitry Andric explicit basic_stringbuf(const string_type& __s, 332e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 333e8d8bef9SDimitry Andric : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) 334e8d8bef9SDimitry Andric { 335e8d8bef9SDimitry Andric str(__s); 336e8d8bef9SDimitry Andric } 337e8d8bef9SDimitry Andric 338*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 339*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const allocator_type& __a) 340*06c3fb27SDimitry Andric : basic_stringbuf(ios_base::in | ios_base::out, __a) {} 341*06c3fb27SDimitry Andric 342*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(ios_base::openmode __wch, const allocator_type& __a) 343*06c3fb27SDimitry Andric : __str_(__a), __hm_(nullptr), __mode_(__wch) {} 344*06c3fb27SDimitry Andric 345*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(string_type&& __s, 346*06c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 347*06c3fb27SDimitry Andric : __str_(std::move(__s)), __hm_(nullptr), __mode_(__wch) { 348*06c3fb27SDimitry Andric __init_buf_ptrs(); 349*06c3fb27SDimitry Andric } 350*06c3fb27SDimitry Andric 351*06c3fb27SDimitry Andric template <class _SAlloc> 352*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 353*06c3fb27SDimitry Andric basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, const allocator_type& __a) 354*06c3fb27SDimitry Andric : basic_stringbuf(__s, ios_base::in | ios_base::out, __a) {} 355*06c3fb27SDimitry Andric 356*06c3fb27SDimitry Andric template <class _SAlloc> 357*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf( 358*06c3fb27SDimitry Andric const basic_string<char_type, traits_type, _SAlloc>& __s, ios_base::openmode __wch, const allocator_type& __a) 359*06c3fb27SDimitry Andric : __str_(__s, __a), __hm_(nullptr), __mode_(__wch) { 360*06c3fb27SDimitry Andric __init_buf_ptrs(); 361*06c3fb27SDimitry Andric } 362*06c3fb27SDimitry Andric 363*06c3fb27SDimitry Andric template <class _SAlloc> 364*06c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 365*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringbuf(const basic_string<char_type, traits_type, _SAlloc>& __s, 366*06c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 367*06c3fb27SDimitry Andric : __str_(__s), __hm_(nullptr), __mode_(__wch) { 368*06c3fb27SDimitry Andric __init_buf_ptrs(); 369*06c3fb27SDimitry Andric } 370*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 371*06c3fb27SDimitry Andric 372*06c3fb27SDimitry Andric basic_stringbuf(basic_stringbuf&& __rhs) : __mode_(__rhs.__mode_) { __move_init(std::move(__rhs)); } 373*06c3fb27SDimitry Andric 374*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 375*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringbuf(basic_stringbuf&& __rhs, const allocator_type& __a) 376*06c3fb27SDimitry Andric : basic_stringbuf(__rhs.__mode_, __a) { 377*06c3fb27SDimitry Andric __move_init(std::move(__rhs)); 378*06c3fb27SDimitry Andric } 379*06c3fb27SDimitry Andric#endif 3800b57cec5SDimitry Andric 381bdd1243dSDimitry Andric // [stringbuf.assign] Assign and swap: 3820b57cec5SDimitry Andric basic_stringbuf& operator=(basic_stringbuf&& __rhs); 383*06c3fb27SDimitry Andric void swap(basic_stringbuf& __rhs) 384*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 385*06c3fb27SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 386*06c3fb27SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value) 387*06c3fb27SDimitry Andric#endif 388*06c3fb27SDimitry Andric ; 3890b57cec5SDimitry Andric 390bdd1243dSDimitry Andric // [stringbuf.members] Member functions: 391*06c3fb27SDimitry Andric 392*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 393*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const noexcept { return __str_.get_allocator(); } 394*06c3fb27SDimitry Andric#endif 395*06c3fb27SDimitry Andric 396*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 3970b57cec5SDimitry Andric string_type str() const; 398*06c3fb27SDimitry Andric#else 399*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() const & { return str(__str_.get_allocator()); } 400*06c3fb27SDimitry Andric 401*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI_SSTREAM string_type str() && { 402*06c3fb27SDimitry Andric const basic_string_view<_CharT, _Traits> __view = view(); 403*06c3fb27SDimitry Andric string_type __result(std::move(__str_), __view.data() - __str_.data(), __view.size()); 404*06c3fb27SDimitry Andric __str_.clear(); 405*06c3fb27SDimitry Andric __init_buf_ptrs(); 406*06c3fb27SDimitry Andric return __result; 407*06c3fb27SDimitry Andric } 408*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 409*06c3fb27SDimitry Andric 410*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 411*06c3fb27SDimitry Andric template <class _SAlloc> 412*06c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 413*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 414*06c3fb27SDimitry Andric return basic_string<_CharT, _Traits, _SAlloc>(view(), __sa); 415*06c3fb27SDimitry Andric } 416*06c3fb27SDimitry Andric 417*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept; 418*06c3fb27SDimitry Andric#endif 419*06c3fb27SDimitry Andric 420*06c3fb27SDimitry Andric void str(const string_type& __s) { 421*06c3fb27SDimitry Andric __str_ = __s; 422*06c3fb27SDimitry Andric __init_buf_ptrs(); 423*06c3fb27SDimitry Andric } 424*06c3fb27SDimitry Andric 425*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 426*06c3fb27SDimitry Andric template <class _SAlloc> 427*06c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 428*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 429*06c3fb27SDimitry Andric __str_ = __s; 430*06c3fb27SDimitry Andric __init_buf_ptrs(); 431*06c3fb27SDimitry Andric } 432*06c3fb27SDimitry Andric 433*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { 434*06c3fb27SDimitry Andric __str_ = std::move(__s); 435*06c3fb27SDimitry Andric __init_buf_ptrs(); 436*06c3fb27SDimitry Andric } 437*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 4380b57cec5SDimitry Andric 4390b57cec5SDimitry Andricprotected: 440bdd1243dSDimitry Andric // [stringbuf.virtuals] Overridden virtual functions: 441bdd1243dSDimitry Andric int_type underflow() override; 442bdd1243dSDimitry Andric int_type pbackfail(int_type __c = traits_type::eof()) override; 443bdd1243dSDimitry Andric int_type overflow (int_type __c = traits_type::eof()) override; 444bdd1243dSDimitry Andric pos_type seekoff(off_type __off, ios_base::seekdir __way, 445bdd1243dSDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) override; 446bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI_VIRTUAL 447bdd1243dSDimitry Andric pos_type seekpos(pos_type __sp, 448bdd1243dSDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) override { 449e8d8bef9SDimitry Andric return seekoff(__sp, ios_base::beg, __wch); 450e8d8bef9SDimitry Andric } 4510b57cec5SDimitry Andric}; 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 454*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__move_init(basic_stringbuf&& __rhs) { 4550b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 4560b57cec5SDimitry Andric ptrdiff_t __binp = -1; 4570b57cec5SDimitry Andric ptrdiff_t __ninp = -1; 4580b57cec5SDimitry Andric ptrdiff_t __einp = -1; 4590b57cec5SDimitry Andric if (__rhs.eback() != nullptr) 4600b57cec5SDimitry Andric { 4610b57cec5SDimitry Andric __binp = __rhs.eback() - __p; 4620b57cec5SDimitry Andric __ninp = __rhs.gptr() - __p; 4630b57cec5SDimitry Andric __einp = __rhs.egptr() - __p; 4640b57cec5SDimitry Andric } 4650b57cec5SDimitry Andric ptrdiff_t __bout = -1; 4660b57cec5SDimitry Andric ptrdiff_t __nout = -1; 4670b57cec5SDimitry Andric ptrdiff_t __eout = -1; 4680b57cec5SDimitry Andric if (__rhs.pbase() != nullptr) 4690b57cec5SDimitry Andric { 4700b57cec5SDimitry Andric __bout = __rhs.pbase() - __p; 4710b57cec5SDimitry Andric __nout = __rhs.pptr() - __p; 4720b57cec5SDimitry Andric __eout = __rhs.epptr() - __p; 4730b57cec5SDimitry Andric } 4740b57cec5SDimitry Andric ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 4750b57cec5SDimitry Andric __str_ = _VSTD::move(__rhs.__str_); 4760b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 4770b57cec5SDimitry Andric if (__binp != -1) 4780b57cec5SDimitry Andric this->setg(__p + __binp, __p + __ninp, __p + __einp); 4790b57cec5SDimitry Andric if (__bout != -1) 4800b57cec5SDimitry Andric { 4810b57cec5SDimitry Andric this->setp(__p + __bout, __p + __eout); 4820b57cec5SDimitry Andric this->__pbump(__nout); 4830b57cec5SDimitry Andric } 4840b57cec5SDimitry Andric __hm_ = __hm == -1 ? nullptr : __p + __hm; 4850b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 4860b57cec5SDimitry Andric __rhs.setg(__p, __p, __p); 4870b57cec5SDimitry Andric __rhs.setp(__p, __p); 4880b57cec5SDimitry Andric __rhs.__hm_ = __p; 4890b57cec5SDimitry Andric this->pubimbue(__rhs.getloc()); 4900b57cec5SDimitry Andric} 4910b57cec5SDimitry Andric 4920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 4930b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>& 4940b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) 4950b57cec5SDimitry Andric{ 4960b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 4970b57cec5SDimitry Andric ptrdiff_t __binp = -1; 4980b57cec5SDimitry Andric ptrdiff_t __ninp = -1; 4990b57cec5SDimitry Andric ptrdiff_t __einp = -1; 5000b57cec5SDimitry Andric if (__rhs.eback() != nullptr) 5010b57cec5SDimitry Andric { 5020b57cec5SDimitry Andric __binp = __rhs.eback() - __p; 5030b57cec5SDimitry Andric __ninp = __rhs.gptr() - __p; 5040b57cec5SDimitry Andric __einp = __rhs.egptr() - __p; 5050b57cec5SDimitry Andric } 5060b57cec5SDimitry Andric ptrdiff_t __bout = -1; 5070b57cec5SDimitry Andric ptrdiff_t __nout = -1; 5080b57cec5SDimitry Andric ptrdiff_t __eout = -1; 5090b57cec5SDimitry Andric if (__rhs.pbase() != nullptr) 5100b57cec5SDimitry Andric { 5110b57cec5SDimitry Andric __bout = __rhs.pbase() - __p; 5120b57cec5SDimitry Andric __nout = __rhs.pptr() - __p; 5130b57cec5SDimitry Andric __eout = __rhs.epptr() - __p; 5140b57cec5SDimitry Andric } 5150b57cec5SDimitry Andric ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 5160b57cec5SDimitry Andric __str_ = _VSTD::move(__rhs.__str_); 5170b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 5180b57cec5SDimitry Andric if (__binp != -1) 5190b57cec5SDimitry Andric this->setg(__p + __binp, __p + __ninp, __p + __einp); 5200b57cec5SDimitry Andric else 5210b57cec5SDimitry Andric this->setg(nullptr, nullptr, nullptr); 5220b57cec5SDimitry Andric if (__bout != -1) 5230b57cec5SDimitry Andric { 5240b57cec5SDimitry Andric this->setp(__p + __bout, __p + __eout); 5250b57cec5SDimitry Andric this->__pbump(__nout); 5260b57cec5SDimitry Andric } 5270b57cec5SDimitry Andric else 5280b57cec5SDimitry Andric this->setp(nullptr, nullptr); 5290b57cec5SDimitry Andric 5300b57cec5SDimitry Andric __hm_ = __hm == -1 ? nullptr : __p + __hm; 5310b57cec5SDimitry Andric __mode_ = __rhs.__mode_; 5320b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 5330b57cec5SDimitry Andric __rhs.setg(__p, __p, __p); 5340b57cec5SDimitry Andric __rhs.setp(__p, __p); 5350b57cec5SDimitry Andric __rhs.__hm_ = __p; 5360b57cec5SDimitry Andric this->pubimbue(__rhs.getloc()); 5370b57cec5SDimitry Andric return *this; 5380b57cec5SDimitry Andric} 5390b57cec5SDimitry Andric 5400b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 5410b57cec5SDimitry Andricvoid 5420b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) 543*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 544*06c3fb27SDimitry Andric noexcept(allocator_traits<_Allocator>::propagate_on_container_swap::value || 545*06c3fb27SDimitry Andric allocator_traits<_Allocator>::is_always_equal::value) 546*06c3fb27SDimitry Andric#endif 5470b57cec5SDimitry Andric{ 5480b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 5490b57cec5SDimitry Andric ptrdiff_t __rbinp = -1; 5500b57cec5SDimitry Andric ptrdiff_t __rninp = -1; 5510b57cec5SDimitry Andric ptrdiff_t __reinp = -1; 5520b57cec5SDimitry Andric if (__rhs.eback() != nullptr) 5530b57cec5SDimitry Andric { 5540b57cec5SDimitry Andric __rbinp = __rhs.eback() - __p; 5550b57cec5SDimitry Andric __rninp = __rhs.gptr() - __p; 5560b57cec5SDimitry Andric __reinp = __rhs.egptr() - __p; 5570b57cec5SDimitry Andric } 5580b57cec5SDimitry Andric ptrdiff_t __rbout = -1; 5590b57cec5SDimitry Andric ptrdiff_t __rnout = -1; 5600b57cec5SDimitry Andric ptrdiff_t __reout = -1; 5610b57cec5SDimitry Andric if (__rhs.pbase() != nullptr) 5620b57cec5SDimitry Andric { 5630b57cec5SDimitry Andric __rbout = __rhs.pbase() - __p; 5640b57cec5SDimitry Andric __rnout = __rhs.pptr() - __p; 5650b57cec5SDimitry Andric __reout = __rhs.epptr() - __p; 5660b57cec5SDimitry Andric } 5670b57cec5SDimitry Andric ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 5680b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 5690b57cec5SDimitry Andric ptrdiff_t __lbinp = -1; 5700b57cec5SDimitry Andric ptrdiff_t __lninp = -1; 5710b57cec5SDimitry Andric ptrdiff_t __leinp = -1; 5720b57cec5SDimitry Andric if (this->eback() != nullptr) 5730b57cec5SDimitry Andric { 5740b57cec5SDimitry Andric __lbinp = this->eback() - __p; 5750b57cec5SDimitry Andric __lninp = this->gptr() - __p; 5760b57cec5SDimitry Andric __leinp = this->egptr() - __p; 5770b57cec5SDimitry Andric } 5780b57cec5SDimitry Andric ptrdiff_t __lbout = -1; 5790b57cec5SDimitry Andric ptrdiff_t __lnout = -1; 5800b57cec5SDimitry Andric ptrdiff_t __leout = -1; 5810b57cec5SDimitry Andric if (this->pbase() != nullptr) 5820b57cec5SDimitry Andric { 5830b57cec5SDimitry Andric __lbout = this->pbase() - __p; 5840b57cec5SDimitry Andric __lnout = this->pptr() - __p; 5850b57cec5SDimitry Andric __leout = this->epptr() - __p; 5860b57cec5SDimitry Andric } 5870b57cec5SDimitry Andric ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; 5880b57cec5SDimitry Andric _VSTD::swap(__mode_, __rhs.__mode_); 5890b57cec5SDimitry Andric __str_.swap(__rhs.__str_); 5900b57cec5SDimitry Andric __p = const_cast<char_type*>(__str_.data()); 5910b57cec5SDimitry Andric if (__rbinp != -1) 5920b57cec5SDimitry Andric this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); 5930b57cec5SDimitry Andric else 5940b57cec5SDimitry Andric this->setg(nullptr, nullptr, nullptr); 5950b57cec5SDimitry Andric if (__rbout != -1) 5960b57cec5SDimitry Andric { 5970b57cec5SDimitry Andric this->setp(__p + __rbout, __p + __reout); 5980b57cec5SDimitry Andric this->__pbump(__rnout); 5990b57cec5SDimitry Andric } 6000b57cec5SDimitry Andric else 6010b57cec5SDimitry Andric this->setp(nullptr, nullptr); 6020b57cec5SDimitry Andric __hm_ = __rhm == -1 ? nullptr : __p + __rhm; 6030b57cec5SDimitry Andric __p = const_cast<char_type*>(__rhs.__str_.data()); 6040b57cec5SDimitry Andric if (__lbinp != -1) 6050b57cec5SDimitry Andric __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); 6060b57cec5SDimitry Andric else 6070b57cec5SDimitry Andric __rhs.setg(nullptr, nullptr, nullptr); 6080b57cec5SDimitry Andric if (__lbout != -1) 6090b57cec5SDimitry Andric { 6100b57cec5SDimitry Andric __rhs.setp(__p + __lbout, __p + __leout); 6110b57cec5SDimitry Andric __rhs.__pbump(__lnout); 6120b57cec5SDimitry Andric } 6130b57cec5SDimitry Andric else 6140b57cec5SDimitry Andric __rhs.setp(nullptr, nullptr); 6150b57cec5SDimitry Andric __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; 6160b57cec5SDimitry Andric locale __tl = __rhs.getloc(); 6170b57cec5SDimitry Andric __rhs.pubimbue(this->getloc()); 6180b57cec5SDimitry Andric this->pubimbue(__tl); 6190b57cec5SDimitry Andric} 6200b57cec5SDimitry Andric 6210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 6220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 6230b57cec5SDimitry Andricvoid 6240b57cec5SDimitry Andricswap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, 6250b57cec5SDimitry Andric basic_stringbuf<_CharT, _Traits, _Allocator>& __y) 626*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 627*06c3fb27SDimitry Andric noexcept(noexcept(__x.swap(__y))) 628*06c3fb27SDimitry Andric#endif 6290b57cec5SDimitry Andric{ 6300b57cec5SDimitry Andric __x.swap(__y); 6310b57cec5SDimitry Andric} 6320b57cec5SDimitry Andric 633*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 6340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 6350b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 636*06c3fb27SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::str() const { 637*06c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 6380b57cec5SDimitry Andric if (__hm_ < this->pptr()) 6390b57cec5SDimitry Andric __hm_ = this->pptr(); 6400b57cec5SDimitry Andric return string_type(this->pbase(), __hm_, __str_.get_allocator()); 641*06c3fb27SDimitry Andric } else if (__mode_ & ios_base::in) 6420b57cec5SDimitry Andric return string_type(this->eback(), this->egptr(), __str_.get_allocator()); 6430b57cec5SDimitry Andric return string_type(__str_.get_allocator()); 6440b57cec5SDimitry Andric} 645*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_BUILDING_LIBRARY) 6460b57cec5SDimitry Andric 6470b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 648*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI void basic_stringbuf<_CharT, _Traits, _Allocator>::__init_buf_ptrs() { 649e8d8bef9SDimitry Andric __hm_ = nullptr; 650*06c3fb27SDimitry Andric char_type* __data = const_cast<char_type*>(__str_.data()); 6510b57cec5SDimitry Andric typename string_type::size_type __sz = __str_.size(); 652*06c3fb27SDimitry Andric if (__mode_ & ios_base::in) { 653*06c3fb27SDimitry Andric __hm_ = __data + __sz; 654*06c3fb27SDimitry Andric this->setg(__data, __data, __hm_); 655*06c3fb27SDimitry Andric } 656*06c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 657*06c3fb27SDimitry Andric __hm_ = __data + __sz; 6580b57cec5SDimitry Andric __str_.resize(__str_.capacity()); 659*06c3fb27SDimitry Andric this->setp(__data, __data + __str_.size()); 660*06c3fb27SDimitry Andric if (__mode_ & (ios_base::app | ios_base::ate)) { 661*06c3fb27SDimitry Andric while (__sz > INT_MAX) { 6620b57cec5SDimitry Andric this->pbump(INT_MAX); 6630b57cec5SDimitry Andric __sz -= INT_MAX; 6640b57cec5SDimitry Andric } 6650b57cec5SDimitry Andric if (__sz > 0) 6660b57cec5SDimitry Andric this->pbump(__sz); 6670b57cec5SDimitry Andric } 6680b57cec5SDimitry Andric } 6690b57cec5SDimitry Andric} 6700b57cec5SDimitry Andric 671*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 672*06c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 673*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT, _Traits> 674*06c3fb27SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::view() const noexcept { 675*06c3fb27SDimitry Andric if (__mode_ & ios_base::out) { 676*06c3fb27SDimitry Andric if (__hm_ < this->pptr()) 677*06c3fb27SDimitry Andric __hm_ = this->pptr(); 678*06c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(this->pbase(), __hm_); 679*06c3fb27SDimitry Andric } else if (__mode_ & ios_base::in) 680*06c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(this->eback(), this->egptr()); 681*06c3fb27SDimitry Andric return basic_string_view<_CharT, _Traits>(); 682*06c3fb27SDimitry Andric} 683*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 684*06c3fb27SDimitry Andric 6850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 6860b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 6870b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::underflow() 6880b57cec5SDimitry Andric{ 6890b57cec5SDimitry Andric if (__hm_ < this->pptr()) 6900b57cec5SDimitry Andric __hm_ = this->pptr(); 6910b57cec5SDimitry Andric if (__mode_ & ios_base::in) 6920b57cec5SDimitry Andric { 6930b57cec5SDimitry Andric if (this->egptr() < __hm_) 6940b57cec5SDimitry Andric this->setg(this->eback(), this->gptr(), __hm_); 6950b57cec5SDimitry Andric if (this->gptr() < this->egptr()) 6960b57cec5SDimitry Andric return traits_type::to_int_type(*this->gptr()); 6970b57cec5SDimitry Andric } 6980b57cec5SDimitry Andric return traits_type::eof(); 6990b57cec5SDimitry Andric} 7000b57cec5SDimitry Andric 7010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7020b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 7030b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) 7040b57cec5SDimitry Andric{ 7050b57cec5SDimitry Andric if (__hm_ < this->pptr()) 7060b57cec5SDimitry Andric __hm_ = this->pptr(); 7070b57cec5SDimitry Andric if (this->eback() < this->gptr()) 7080b57cec5SDimitry Andric { 7090b57cec5SDimitry Andric if (traits_type::eq_int_type(__c, traits_type::eof())) 7100b57cec5SDimitry Andric { 7110b57cec5SDimitry Andric this->setg(this->eback(), this->gptr()-1, __hm_); 7120b57cec5SDimitry Andric return traits_type::not_eof(__c); 7130b57cec5SDimitry Andric } 7140b57cec5SDimitry Andric if ((__mode_ & ios_base::out) || 7150b57cec5SDimitry Andric traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) 7160b57cec5SDimitry Andric { 7170b57cec5SDimitry Andric this->setg(this->eback(), this->gptr()-1, __hm_); 7180b57cec5SDimitry Andric *this->gptr() = traits_type::to_char_type(__c); 7190b57cec5SDimitry Andric return __c; 7200b57cec5SDimitry Andric } 7210b57cec5SDimitry Andric } 7220b57cec5SDimitry Andric return traits_type::eof(); 7230b57cec5SDimitry Andric} 7240b57cec5SDimitry Andric 7250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7260b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 7270b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) 7280b57cec5SDimitry Andric{ 7290b57cec5SDimitry Andric if (!traits_type::eq_int_type(__c, traits_type::eof())) 7300b57cec5SDimitry Andric { 7310b57cec5SDimitry Andric ptrdiff_t __ninp = this->gptr() - this->eback(); 7320b57cec5SDimitry Andric if (this->pptr() == this->epptr()) 7330b57cec5SDimitry Andric { 7340b57cec5SDimitry Andric if (!(__mode_ & ios_base::out)) 7350b57cec5SDimitry Andric return traits_type::eof(); 736*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 7370b57cec5SDimitry Andric try 7380b57cec5SDimitry Andric { 739*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 7400b57cec5SDimitry Andric ptrdiff_t __nout = this->pptr() - this->pbase(); 7410b57cec5SDimitry Andric ptrdiff_t __hm = __hm_ - this->pbase(); 7420b57cec5SDimitry Andric __str_.push_back(char_type()); 7430b57cec5SDimitry Andric __str_.resize(__str_.capacity()); 7440b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__str_.data()); 7450b57cec5SDimitry Andric this->setp(__p, __p + __str_.size()); 7460b57cec5SDimitry Andric this->__pbump(__nout); 7470b57cec5SDimitry Andric __hm_ = this->pbase() + __hm; 748*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 7490b57cec5SDimitry Andric } 7500b57cec5SDimitry Andric catch (...) 7510b57cec5SDimitry Andric { 7520b57cec5SDimitry Andric return traits_type::eof(); 7530b57cec5SDimitry Andric } 754*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 7550b57cec5SDimitry Andric } 7560b57cec5SDimitry Andric __hm_ = _VSTD::max(this->pptr() + 1, __hm_); 7570b57cec5SDimitry Andric if (__mode_ & ios_base::in) 7580b57cec5SDimitry Andric { 7590b57cec5SDimitry Andric char_type* __p = const_cast<char_type*>(__str_.data()); 7600b57cec5SDimitry Andric this->setg(__p, __p + __ninp, __hm_); 7610b57cec5SDimitry Andric } 7620b57cec5SDimitry Andric return this->sputc(traits_type::to_char_type(__c)); 7630b57cec5SDimitry Andric } 7640b57cec5SDimitry Andric return traits_type::not_eof(__c); 7650b57cec5SDimitry Andric} 7660b57cec5SDimitry Andric 7670b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 7680b57cec5SDimitry Andrictypename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type 7690b57cec5SDimitry Andricbasic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, 7700b57cec5SDimitry Andric ios_base::seekdir __way, 7710b57cec5SDimitry Andric ios_base::openmode __wch) 7720b57cec5SDimitry Andric{ 7730b57cec5SDimitry Andric if (__hm_ < this->pptr()) 7740b57cec5SDimitry Andric __hm_ = this->pptr(); 7750b57cec5SDimitry Andric if ((__wch & (ios_base::in | ios_base::out)) == 0) 7760b57cec5SDimitry Andric return pos_type(-1); 7770b57cec5SDimitry Andric if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) 7780b57cec5SDimitry Andric && __way == ios_base::cur) 7790b57cec5SDimitry Andric return pos_type(-1); 7800b57cec5SDimitry Andric const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); 7810b57cec5SDimitry Andric off_type __noff; 7820b57cec5SDimitry Andric switch (__way) 7830b57cec5SDimitry Andric { 7840b57cec5SDimitry Andric case ios_base::beg: 7850b57cec5SDimitry Andric __noff = 0; 7860b57cec5SDimitry Andric break; 7870b57cec5SDimitry Andric case ios_base::cur: 7880b57cec5SDimitry Andric if (__wch & ios_base::in) 7890b57cec5SDimitry Andric __noff = this->gptr() - this->eback(); 7900b57cec5SDimitry Andric else 7910b57cec5SDimitry Andric __noff = this->pptr() - this->pbase(); 7920b57cec5SDimitry Andric break; 7930b57cec5SDimitry Andric case ios_base::end: 7940b57cec5SDimitry Andric __noff = __hm; 7950b57cec5SDimitry Andric break; 7960b57cec5SDimitry Andric default: 7970b57cec5SDimitry Andric return pos_type(-1); 7980b57cec5SDimitry Andric } 7990b57cec5SDimitry Andric __noff += __off; 8000b57cec5SDimitry Andric if (__noff < 0 || __hm < __noff) 8010b57cec5SDimitry Andric return pos_type(-1); 8020b57cec5SDimitry Andric if (__noff != 0) 8030b57cec5SDimitry Andric { 804e8d8bef9SDimitry Andric if ((__wch & ios_base::in) && this->gptr() == nullptr) 8050b57cec5SDimitry Andric return pos_type(-1); 806e8d8bef9SDimitry Andric if ((__wch & ios_base::out) && this->pptr() == nullptr) 8070b57cec5SDimitry Andric return pos_type(-1); 8080b57cec5SDimitry Andric } 8090b57cec5SDimitry Andric if (__wch & ios_base::in) 8100b57cec5SDimitry Andric this->setg(this->eback(), this->eback() + __noff, __hm_); 8110b57cec5SDimitry Andric if (__wch & ios_base::out) 8120b57cec5SDimitry Andric { 8130b57cec5SDimitry Andric this->setp(this->pbase(), this->epptr()); 814*06c3fb27SDimitry Andric this->__pbump(__noff); 8150b57cec5SDimitry Andric } 8160b57cec5SDimitry Andric return pos_type(__noff); 8170b57cec5SDimitry Andric} 8180b57cec5SDimitry Andric 819bdd1243dSDimitry Andric// Class template basic_istringstream [istringstream] 8200b57cec5SDimitry Andric 8210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 8220b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_istringstream 8230b57cec5SDimitry Andric : public basic_istream<_CharT, _Traits> 8240b57cec5SDimitry Andric{ 8250b57cec5SDimitry Andricpublic: 8260b57cec5SDimitry Andric typedef _CharT char_type; 8270b57cec5SDimitry Andric typedef _Traits traits_type; 8280b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 8290b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 8300b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 8310b57cec5SDimitry Andric typedef _Allocator allocator_type; 8320b57cec5SDimitry Andric 8330b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 8340b57cec5SDimitry Andric 8350b57cec5SDimitry Andricprivate: 8360b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 8370b57cec5SDimitry Andric 8380b57cec5SDimitry Andricpublic: 839bdd1243dSDimitry Andric // [istringstream.cons] Constructors: 840e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 841fe6060f1SDimitry Andric basic_istringstream() 842fe6060f1SDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in) {} 843e8d8bef9SDimitry Andric 844e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 845e8d8bef9SDimitry Andric explicit basic_istringstream(ios_base::openmode __wch) 846e8d8bef9SDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) {} 847e8d8bef9SDimitry Andric 848e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8490b57cec5SDimitry Andric explicit basic_istringstream(const string_type& __s, 850e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in) 851e8d8bef9SDimitry Andric : basic_istream<_CharT, _Traits>(&__sb_) 852e8d8bef9SDimitry Andric , __sb_(__s, __wch | ios_base::in) 853e8d8bef9SDimitry Andric { } 8540b57cec5SDimitry Andric 855*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 856*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(ios_base::openmode __wch, const _Allocator& __a) 857*06c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::in, __a) {} 858*06c3fb27SDimitry Andric 859*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(string_type&& __s, ios_base::openmode __wch = ios_base::in) 860*06c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::in) {} 861*06c3fb27SDimitry Andric 862*06c3fb27SDimitry Andric template <class _SAlloc> 863*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 864*06c3fb27SDimitry Andric : basic_istringstream(__s, ios_base::in, __a) {} 865*06c3fb27SDimitry Andric 866*06c3fb27SDimitry Andric template <class _SAlloc> 867*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_istringstream( 868*06c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 869*06c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in, __a) {} 870*06c3fb27SDimitry Andric 871*06c3fb27SDimitry Andric template <class _SAlloc> 872*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 873*06c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::in) 874*06c3fb27SDimitry Andric : basic_istream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::in) {} 875*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 876*06c3fb27SDimitry Andric 877e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 878e8d8bef9SDimitry Andric basic_istringstream(basic_istringstream&& __rhs) 879e8d8bef9SDimitry Andric : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) 880e8d8bef9SDimitry Andric , __sb_(_VSTD::move(__rhs.__sb_)) 8810b57cec5SDimitry Andric { 8820b57cec5SDimitry Andric basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 8830b57cec5SDimitry Andric } 8840b57cec5SDimitry Andric 885bdd1243dSDimitry Andric // [istringstream.assign] Assign and swap: 886e8d8bef9SDimitry Andric basic_istringstream& operator=(basic_istringstream&& __rhs) { 8870b57cec5SDimitry Andric basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 8880b57cec5SDimitry Andric __sb_ = _VSTD::move(__rhs.__sb_); 8890b57cec5SDimitry Andric return *this; 8900b57cec5SDimitry Andric } 891e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 892e8d8bef9SDimitry Andric void swap(basic_istringstream& __rhs) { 8930b57cec5SDimitry Andric basic_istream<char_type, traits_type>::swap(__rhs); 8940b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 8950b57cec5SDimitry Andric } 8960b57cec5SDimitry Andric 897bdd1243dSDimitry Andric // [istringstream.members] Member functions: 898e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 899e8d8bef9SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 900e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 901e8d8bef9SDimitry Andric } 902*06c3fb27SDimitry Andric 903*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 904*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } 905*06c3fb27SDimitry Andric 906*06c3fb27SDimitry Andric template <class _SAlloc> 907*06c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 908*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 909*06c3fb27SDimitry Andric return __sb_.str(__sa); 910e8d8bef9SDimitry Andric } 911*06c3fb27SDimitry Andric 912*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } 913*06c3fb27SDimitry Andric 914*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 915*06c3fb27SDimitry Andric#else // _LIBCPP_STD_VER >= 20 916*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 917*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 918*06c3fb27SDimitry Andric 919*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 920*06c3fb27SDimitry Andric 921*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 922*06c3fb27SDimitry Andric template <class _SAlloc> 923*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 924e8d8bef9SDimitry Andric __sb_.str(__s); 925e8d8bef9SDimitry Andric } 926*06c3fb27SDimitry Andric 927*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 928*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 929e8d8bef9SDimitry Andric}; 930e8d8bef9SDimitry Andric 9310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 9320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9330b57cec5SDimitry Andricvoid 9340b57cec5SDimitry Andricswap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, 9350b57cec5SDimitry Andric basic_istringstream<_CharT, _Traits, _Allocator>& __y) 9360b57cec5SDimitry Andric{ 9370b57cec5SDimitry Andric __x.swap(__y); 9380b57cec5SDimitry Andric} 9390b57cec5SDimitry Andric 940bdd1243dSDimitry Andric// Class template basic_ostringstream [ostringstream] 9410b57cec5SDimitry Andric 9420b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 9430b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_ostringstream 9440b57cec5SDimitry Andric : public basic_ostream<_CharT, _Traits> 9450b57cec5SDimitry Andric{ 9460b57cec5SDimitry Andricpublic: 9470b57cec5SDimitry Andric typedef _CharT char_type; 9480b57cec5SDimitry Andric typedef _Traits traits_type; 9490b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 9500b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 9510b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 9520b57cec5SDimitry Andric typedef _Allocator allocator_type; 9530b57cec5SDimitry Andric 9540b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 9550b57cec5SDimitry Andric 9560b57cec5SDimitry Andricprivate: 9570b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 9580b57cec5SDimitry Andric 9590b57cec5SDimitry Andricpublic: 960bdd1243dSDimitry Andric // [ostringstream.cons] Constructors: 961e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 962fe6060f1SDimitry Andric basic_ostringstream() 963fe6060f1SDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::out) {} 964e8d8bef9SDimitry Andric 965e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 966e8d8bef9SDimitry Andric explicit basic_ostringstream(ios_base::openmode __wch) 967fe6060f1SDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::out) {} 968e8d8bef9SDimitry Andric 969e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9700b57cec5SDimitry Andric explicit basic_ostringstream(const string_type& __s, 971e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::out) 972e8d8bef9SDimitry Andric : basic_ostream<_CharT, _Traits>(&__sb_) 973e8d8bef9SDimitry Andric , __sb_(__s, __wch | ios_base::out) 974e8d8bef9SDimitry Andric { } 9750b57cec5SDimitry Andric 976*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 977*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(ios_base::openmode __wch, const _Allocator& __a) 978*06c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch | ios_base::out, __a) {} 979*06c3fb27SDimitry Andric 980*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out) 981*06c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch | ios_base::out) {} 982*06c3fb27SDimitry Andric 983*06c3fb27SDimitry Andric template <class _SAlloc> 984*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 985*06c3fb27SDimitry Andric : basic_ostringstream(__s, ios_base::out, __a) {} 986*06c3fb27SDimitry Andric 987*06c3fb27SDimitry Andric template <class _SAlloc> 988*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostringstream( 989*06c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 990*06c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out, __a) {} 991*06c3fb27SDimitry Andric 992*06c3fb27SDimitry Andric template <class _SAlloc> 993*06c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 994*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_ostringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 995*06c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::out) 996*06c3fb27SDimitry Andric : basic_ostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch | ios_base::out) {} 997*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 998*06c3fb27SDimitry Andric 999e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1000e8d8bef9SDimitry Andric basic_ostringstream(basic_ostringstream&& __rhs) 1001e8d8bef9SDimitry Andric : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)) 1002e8d8bef9SDimitry Andric , __sb_(_VSTD::move(__rhs.__sb_)) 10030b57cec5SDimitry Andric { 10040b57cec5SDimitry Andric basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); 10050b57cec5SDimitry Andric } 10060b57cec5SDimitry Andric 1007bdd1243dSDimitry Andric // [ostringstream.assign] Assign and swap: 1008e8d8bef9SDimitry Andric basic_ostringstream& operator=(basic_ostringstream&& __rhs) { 10090b57cec5SDimitry Andric basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 10100b57cec5SDimitry Andric __sb_ = _VSTD::move(__rhs.__sb_); 10110b57cec5SDimitry Andric return *this; 10120b57cec5SDimitry Andric } 10130b57cec5SDimitry Andric 1014e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1015e8d8bef9SDimitry Andric void swap(basic_ostringstream& __rhs) { 10160b57cec5SDimitry Andric basic_ostream<char_type, traits_type>::swap(__rhs); 10170b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 10180b57cec5SDimitry Andric } 10190b57cec5SDimitry Andric 1020bdd1243dSDimitry Andric // [ostringstream.members] Member functions: 1021e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1022e8d8bef9SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 1023e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 1024e8d8bef9SDimitry Andric } 1025*06c3fb27SDimitry Andric 1026*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 1027*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } 1028*06c3fb27SDimitry Andric 1029*06c3fb27SDimitry Andric template <class _SAlloc> 1030*06c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 1031*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 1032*06c3fb27SDimitry Andric return __sb_.str(__sa); 1033e8d8bef9SDimitry Andric } 1034*06c3fb27SDimitry Andric 1035*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } 1036*06c3fb27SDimitry Andric 1037*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 1038*06c3fb27SDimitry Andric#else // _LIBCPP_STD_VER >= 20 1039*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 1040*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1041*06c3fb27SDimitry Andric 1042*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 1043*06c3fb27SDimitry Andric 1044*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 1045*06c3fb27SDimitry Andric template <class _SAlloc> 1046*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 1047e8d8bef9SDimitry Andric __sb_.str(__s); 1048e8d8bef9SDimitry Andric } 1049*06c3fb27SDimitry Andric 1050*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 1051*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1052e8d8bef9SDimitry Andric}; 1053e8d8bef9SDimitry Andric 10540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 10550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10560b57cec5SDimitry Andricvoid 10570b57cec5SDimitry Andricswap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, 10580b57cec5SDimitry Andric basic_ostringstream<_CharT, _Traits, _Allocator>& __y) 10590b57cec5SDimitry Andric{ 10600b57cec5SDimitry Andric __x.swap(__y); 10610b57cec5SDimitry Andric} 10620b57cec5SDimitry Andric 1063bdd1243dSDimitry Andric// Class template basic_stringstream [stringstream] 10640b57cec5SDimitry Andric 10650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 10660b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_stringstream 10670b57cec5SDimitry Andric : public basic_iostream<_CharT, _Traits> 10680b57cec5SDimitry Andric{ 10690b57cec5SDimitry Andricpublic: 10700b57cec5SDimitry Andric typedef _CharT char_type; 10710b57cec5SDimitry Andric typedef _Traits traits_type; 10720b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 10730b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 10740b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 10750b57cec5SDimitry Andric typedef _Allocator allocator_type; 10760b57cec5SDimitry Andric 10770b57cec5SDimitry Andric typedef basic_string<char_type, traits_type, allocator_type> string_type; 10780b57cec5SDimitry Andric 10790b57cec5SDimitry Andricprivate: 10800b57cec5SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 10810b57cec5SDimitry Andric 10820b57cec5SDimitry Andricpublic: 1083bdd1243dSDimitry Andric // [stringstream.cons] constructors 1084e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1085fe6060f1SDimitry Andric basic_stringstream() 1086fe6060f1SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(ios_base::in | ios_base::out) {} 1087e8d8bef9SDimitry Andric 1088e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1089e8d8bef9SDimitry Andric explicit basic_stringstream(ios_base::openmode __wch) 1090e8d8bef9SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) {} 1091e8d8bef9SDimitry Andric 1092e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10930b57cec5SDimitry Andric explicit basic_stringstream(const string_type& __s, 1094e8d8bef9SDimitry Andric ios_base::openmode __wch = ios_base::in | ios_base::out) 1095e8d8bef9SDimitry Andric : basic_iostream<_CharT, _Traits>(&__sb_) 1096e8d8bef9SDimitry Andric , __sb_(__s, __wch) 1097e8d8bef9SDimitry Andric { } 10980b57cec5SDimitry Andric 1099*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 1100*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(ios_base::openmode __wch, const _Allocator& __a) 1101*06c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__wch, __a) {} 1102*06c3fb27SDimitry Andric 1103*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(string_type&& __s, ios_base::openmode __wch = ios_base::out | ios_base::in) 1104*06c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(std::move(__s), __wch) {} 1105*06c3fb27SDimitry Andric 1106*06c3fb27SDimitry Andric template <class _SAlloc> 1107*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, const _Allocator& __a) 1108*06c3fb27SDimitry Andric : basic_stringstream(__s, ios_base::out | ios_base::in, __a) {} 1109*06c3fb27SDimitry Andric 1110*06c3fb27SDimitry Andric template <class _SAlloc> 1111*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_stringstream( 1112*06c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _SAlloc>& __s, ios_base::openmode __wch, const _Allocator& __a) 1113*06c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch, __a) {} 1114*06c3fb27SDimitry Andric 1115*06c3fb27SDimitry Andric template <class _SAlloc> 1116*06c3fb27SDimitry Andric requires (!is_same_v<_SAlloc, allocator_type>) 1117*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit basic_stringstream(const basic_string<_CharT, _Traits, _SAlloc>& __s, 1118*06c3fb27SDimitry Andric ios_base::openmode __wch = ios_base::out | ios_base::in) 1119*06c3fb27SDimitry Andric : basic_iostream<_CharT, _Traits>(std::addressof(__sb_)), __sb_(__s, __wch) {} 1120*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1121*06c3fb27SDimitry Andric 1122e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1123e8d8bef9SDimitry Andric basic_stringstream(basic_stringstream&& __rhs) 1124e8d8bef9SDimitry Andric : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)) 1125e8d8bef9SDimitry Andric , __sb_(_VSTD::move(__rhs.__sb_)) 11260b57cec5SDimitry Andric { 11270b57cec5SDimitry Andric basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 11280b57cec5SDimitry Andric } 11290b57cec5SDimitry Andric 1130bdd1243dSDimitry Andric // [stringstream.assign] Assign and swap: 1131e8d8bef9SDimitry Andric basic_stringstream& operator=(basic_stringstream&& __rhs) { 11320b57cec5SDimitry Andric basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 11330b57cec5SDimitry Andric __sb_ = _VSTD::move(__rhs.__sb_); 11340b57cec5SDimitry Andric return *this; 11350b57cec5SDimitry Andric } 1136e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1137e8d8bef9SDimitry Andric void swap(basic_stringstream& __rhs) { 11380b57cec5SDimitry Andric basic_iostream<char_type, traits_type>::swap(__rhs); 11390b57cec5SDimitry Andric __sb_.swap(__rhs.__sb_); 11400b57cec5SDimitry Andric } 11410b57cec5SDimitry Andric 1142bdd1243dSDimitry Andric // [stringstream.members] Member functions: 1143e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1144e8d8bef9SDimitry Andric basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 1145e8d8bef9SDimitry Andric return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 1146e8d8bef9SDimitry Andric } 1147*06c3fb27SDimitry Andric 1148*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 1149*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const & { return __sb_.str(); } 1150*06c3fb27SDimitry Andric 1151*06c3fb27SDimitry Andric template <class _SAlloc> 1152*06c3fb27SDimitry Andric requires __is_allocator<_SAlloc>::value 1153*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string<char_type, traits_type, _SAlloc> str(const _SAlloc& __sa) const { 1154*06c3fb27SDimitry Andric return __sb_.str(__sa); 1155e8d8bef9SDimitry Andric } 1156*06c3fb27SDimitry Andric 1157*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() && { return std::move(__sb_).str(); } 1158*06c3fb27SDimitry Andric 1159*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_string_view<char_type, traits_type> view() const noexcept { return __sb_.view(); } 1160*06c3fb27SDimitry Andric#else // _LIBCPP_STD_VER >= 20 1161*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type str() const { return __sb_.str(); } 1162*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1163*06c3fb27SDimitry Andric 1164*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const string_type& __s) { __sb_.str(__s); } 1165*06c3fb27SDimitry Andric 1166*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 1167*06c3fb27SDimitry Andric template <class _SAlloc> 1168*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(const basic_string<char_type, traits_type, _SAlloc>& __s) { 1169e8d8bef9SDimitry Andric __sb_.str(__s); 1170e8d8bef9SDimitry Andric } 1171*06c3fb27SDimitry Andric 1172*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI void str(string_type&& __s) { __sb_.str(std::move(__s)); } 1173*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1174e8d8bef9SDimitry Andric}; 1175e8d8bef9SDimitry Andric 11760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 11770b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 11780b57cec5SDimitry Andricvoid 11790b57cec5SDimitry Andricswap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, 11800b57cec5SDimitry Andric basic_stringstream<_CharT, _Traits, _Allocator>& __y) 11810b57cec5SDimitry Andric{ 11820b57cec5SDimitry Andric __x.swap(__y); 11830b57cec5SDimitry Andric} 11840b57cec5SDimitry Andric 1185e8d8bef9SDimitry Andric#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1) 118681ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>; 118781ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>; 118881ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>; 118981ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>; 1190e8d8bef9SDimitry Andric#endif 11910b57cec5SDimitry Andric 11920b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 11930b57cec5SDimitry Andric 11940b57cec5SDimitry Andric_LIBCPP_POP_MACROS 11950b57cec5SDimitry Andric 1196bdd1243dSDimitry Andric#if _LIBCPP_STD_VER <= 20 && !defined(_LIPCPP_REMOVE_TRANSITIVE_INCLUDES) 1197bdd1243dSDimitry Andric# include <type_traits> 1198bdd1243dSDimitry Andric#endif 1199bdd1243dSDimitry Andric 12000b57cec5SDimitry Andric#endif // _LIBCPP_SSTREAM 1201