1*4d6fc14bSjoerg// -*- C++ -*- 2*4d6fc14bSjoerg//===--------------------------- sstream ----------------------------------===// 3*4d6fc14bSjoerg// 4*4d6fc14bSjoerg// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*4d6fc14bSjoerg// See https://llvm.org/LICENSE.txt for license information. 6*4d6fc14bSjoerg// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*4d6fc14bSjoerg// 8*4d6fc14bSjoerg//===----------------------------------------------------------------------===// 9*4d6fc14bSjoerg 10*4d6fc14bSjoerg#ifndef _LIBCPP_SSTREAM 11*4d6fc14bSjoerg#define _LIBCPP_SSTREAM 12*4d6fc14bSjoerg 13*4d6fc14bSjoerg/* 14*4d6fc14bSjoerg sstream synopsis 15*4d6fc14bSjoerg 16*4d6fc14bSjoergtemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 17*4d6fc14bSjoergclass basic_stringbuf 18*4d6fc14bSjoerg : public basic_streambuf<charT, traits> 19*4d6fc14bSjoerg{ 20*4d6fc14bSjoergpublic: 21*4d6fc14bSjoerg typedef charT char_type; 22*4d6fc14bSjoerg typedef traits traits_type; 23*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 24*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 25*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 26*4d6fc14bSjoerg typedef Allocator allocator_type; 27*4d6fc14bSjoerg 28*4d6fc14bSjoerg // 27.8.1.1 [stringbuf.cons], constructors: 29*4d6fc14bSjoerg explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20 30*4d6fc14bSjoerg basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20 31*4d6fc14bSjoerg explicit basic_stringbuf(ios_base::openmode which); // C++20 32*4d6fc14bSjoerg explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& str, 33*4d6fc14bSjoerg ios_base::openmode which = ios_base::in | ios_base::out); 34*4d6fc14bSjoerg basic_stringbuf(basic_stringbuf&& rhs); 35*4d6fc14bSjoerg 36*4d6fc14bSjoerg // 27.8.1.2 Assign and swap: 37*4d6fc14bSjoerg basic_stringbuf& operator=(basic_stringbuf&& rhs); 38*4d6fc14bSjoerg void swap(basic_stringbuf& rhs); 39*4d6fc14bSjoerg 40*4d6fc14bSjoerg // 27.8.1.3 Get and set: 41*4d6fc14bSjoerg basic_string<char_type, traits_type, allocator_type> str() const; 42*4d6fc14bSjoerg void str(const basic_string<char_type, traits_type, allocator_type>& s); 43*4d6fc14bSjoerg 44*4d6fc14bSjoergprotected: 45*4d6fc14bSjoerg // 27.8.1.4 Overridden virtual functions: 46*4d6fc14bSjoerg virtual int_type underflow(); 47*4d6fc14bSjoerg virtual int_type pbackfail(int_type c = traits_type::eof()); 48*4d6fc14bSjoerg virtual int_type overflow (int_type c = traits_type::eof()); 49*4d6fc14bSjoerg virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize); 50*4d6fc14bSjoerg virtual pos_type seekoff(off_type off, ios_base::seekdir way, 51*4d6fc14bSjoerg ios_base::openmode which = ios_base::in | ios_base::out); 52*4d6fc14bSjoerg virtual pos_type seekpos(pos_type sp, 53*4d6fc14bSjoerg ios_base::openmode which = ios_base::in | ios_base::out); 54*4d6fc14bSjoerg}; 55*4d6fc14bSjoerg 56*4d6fc14bSjoergtemplate <class charT, class traits, class Allocator> 57*4d6fc14bSjoerg void swap(basic_stringbuf<charT, traits, Allocator>& x, 58*4d6fc14bSjoerg basic_stringbuf<charT, traits, Allocator>& y); 59*4d6fc14bSjoerg 60*4d6fc14bSjoergtypedef basic_stringbuf<char> stringbuf; 61*4d6fc14bSjoergtypedef basic_stringbuf<wchar_t> wstringbuf; 62*4d6fc14bSjoerg 63*4d6fc14bSjoergtemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 64*4d6fc14bSjoergclass basic_istringstream 65*4d6fc14bSjoerg : public basic_istream<charT, traits> 66*4d6fc14bSjoerg{ 67*4d6fc14bSjoergpublic: 68*4d6fc14bSjoerg typedef charT char_type; 69*4d6fc14bSjoerg typedef traits traits_type; 70*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 71*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 72*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 73*4d6fc14bSjoerg typedef Allocator allocator_type; 74*4d6fc14bSjoerg 75*4d6fc14bSjoerg // 27.8.2.1 Constructors: 76*4d6fc14bSjoerg explicit basic_istringstream(ios_base::openmode which = ios_base::in); // before C++20 77*4d6fc14bSjoerg basic_istringstream() : basic_istringstream(ios_base::in) {} // C++20 78*4d6fc14bSjoerg explicit basic_istringstream(ios_base::openmode which); // C++20 79*4d6fc14bSjoerg 80*4d6fc14bSjoerg explicit basic_istringstream(const basic_string<char_type, traits_type,allocator_type>& str, 81*4d6fc14bSjoerg ios_base::openmode which = ios_base::in); 82*4d6fc14bSjoerg basic_istringstream(basic_istringstream&& rhs); 83*4d6fc14bSjoerg 84*4d6fc14bSjoerg // 27.8.2.2 Assign and swap: 85*4d6fc14bSjoerg basic_istringstream& operator=(basic_istringstream&& rhs); 86*4d6fc14bSjoerg void swap(basic_istringstream& rhs); 87*4d6fc14bSjoerg 88*4d6fc14bSjoerg // 27.8.2.3 Members: 89*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 90*4d6fc14bSjoerg basic_string<char_type, traits_type, allocator_type> str() const; 91*4d6fc14bSjoerg void str(const basic_string<char_type, traits_type, allocator_type>& s); 92*4d6fc14bSjoerg}; 93*4d6fc14bSjoerg 94*4d6fc14bSjoergtemplate <class charT, class traits, class Allocator> 95*4d6fc14bSjoerg void swap(basic_istringstream<charT, traits, Allocator>& x, 96*4d6fc14bSjoerg basic_istringstream<charT, traits, Allocator>& y); 97*4d6fc14bSjoerg 98*4d6fc14bSjoergtypedef basic_istringstream<char> istringstream; 99*4d6fc14bSjoergtypedef basic_istringstream<wchar_t> wistringstream; 100*4d6fc14bSjoerg 101*4d6fc14bSjoergtemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 102*4d6fc14bSjoergclass basic_ostringstream 103*4d6fc14bSjoerg : public basic_ostream<charT, traits> 104*4d6fc14bSjoerg{ 105*4d6fc14bSjoergpublic: 106*4d6fc14bSjoerg // types: 107*4d6fc14bSjoerg typedef charT char_type; 108*4d6fc14bSjoerg typedef traits traits_type; 109*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 110*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 111*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 112*4d6fc14bSjoerg typedef Allocator allocator_type; 113*4d6fc14bSjoerg 114*4d6fc14bSjoerg // 27.8.3.1 Constructors/destructor: 115*4d6fc14bSjoerg explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20 116*4d6fc14bSjoerg basic_ostringstream() : basic_ostringstream(ios_base::out) {} // C++20 117*4d6fc14bSjoerg explicit basic_ostringstream(ios_base::openmode which); // C++20 118*4d6fc14bSjoerg 119*4d6fc14bSjoerg explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& str, 120*4d6fc14bSjoerg ios_base::openmode which = ios_base::out); 121*4d6fc14bSjoerg basic_ostringstream(basic_ostringstream&& rhs); 122*4d6fc14bSjoerg 123*4d6fc14bSjoerg // 27.8.3.2 Assign/swap: 124*4d6fc14bSjoerg basic_ostringstream& operator=(basic_ostringstream&& rhs); 125*4d6fc14bSjoerg void swap(basic_ostringstream& rhs); 126*4d6fc14bSjoerg 127*4d6fc14bSjoerg // 27.8.3.3 Members: 128*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 129*4d6fc14bSjoerg basic_string<char_type, traits_type, allocator_type> str() const; 130*4d6fc14bSjoerg void str(const basic_string<char_type, traits_type, allocator_type>& s); 131*4d6fc14bSjoerg}; 132*4d6fc14bSjoerg 133*4d6fc14bSjoergtemplate <class charT, class traits, class Allocator> 134*4d6fc14bSjoerg void swap(basic_ostringstream<charT, traits, Allocator>& x, 135*4d6fc14bSjoerg basic_ostringstream<charT, traits, Allocator>& y); 136*4d6fc14bSjoerg 137*4d6fc14bSjoergtypedef basic_ostringstream<char> ostringstream; 138*4d6fc14bSjoergtypedef basic_ostringstream<wchar_t> wostringstream; 139*4d6fc14bSjoerg 140*4d6fc14bSjoergtemplate <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 141*4d6fc14bSjoergclass basic_stringstream 142*4d6fc14bSjoerg : public basic_iostream<charT, traits> 143*4d6fc14bSjoerg{ 144*4d6fc14bSjoergpublic: 145*4d6fc14bSjoerg // types: 146*4d6fc14bSjoerg typedef charT char_type; 147*4d6fc14bSjoerg typedef traits traits_type; 148*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 149*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 150*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 151*4d6fc14bSjoerg typedef Allocator allocator_type; 152*4d6fc14bSjoerg 153*4d6fc14bSjoerg // constructors/destructor 154*4d6fc14bSjoerg explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 155*4d6fc14bSjoerg basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 156*4d6fc14bSjoerg explicit basic_stringstream(ios_base::openmode which); // C++20 157*4d6fc14bSjoerg 158*4d6fc14bSjoerg explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str, 159*4d6fc14bSjoerg ios_base::openmode which = ios_base::out|ios_base::in); 160*4d6fc14bSjoerg basic_stringstream(basic_stringstream&& rhs); 161*4d6fc14bSjoerg 162*4d6fc14bSjoerg // 27.8.5.1 Assign/swap: 163*4d6fc14bSjoerg basic_stringstream& operator=(basic_stringstream&& rhs); 164*4d6fc14bSjoerg void swap(basic_stringstream& rhs); 165*4d6fc14bSjoerg 166*4d6fc14bSjoerg // Members: 167*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const; 168*4d6fc14bSjoerg basic_string<char_type, traits_type, allocator_type> str() const; 169*4d6fc14bSjoerg void str(const basic_string<char_type, traits_type, allocator_type>& str); 170*4d6fc14bSjoerg}; 171*4d6fc14bSjoerg 172*4d6fc14bSjoergtemplate <class charT, class traits, class Allocator> 173*4d6fc14bSjoerg void swap(basic_stringstream<charT, traits, Allocator>& x, 174*4d6fc14bSjoerg basic_stringstream<charT, traits, Allocator>& y); 175*4d6fc14bSjoerg 176*4d6fc14bSjoergtypedef basic_stringstream<char> stringstream; 177*4d6fc14bSjoergtypedef basic_stringstream<wchar_t> wstringstream; 178*4d6fc14bSjoerg 179*4d6fc14bSjoerg} // std 180*4d6fc14bSjoerg 181*4d6fc14bSjoerg*/ 182*4d6fc14bSjoerg 183*4d6fc14bSjoerg#include <__config> 184*4d6fc14bSjoerg#include <ostream> 185*4d6fc14bSjoerg#include <istream> 186*4d6fc14bSjoerg#include <string> 187*4d6fc14bSjoerg 188*4d6fc14bSjoerg#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 189*4d6fc14bSjoerg#pragma GCC system_header 190*4d6fc14bSjoerg#endif 191*4d6fc14bSjoerg 192*4d6fc14bSjoerg_LIBCPP_PUSH_MACROS 193*4d6fc14bSjoerg#include <__undef_macros> 194*4d6fc14bSjoerg 195*4d6fc14bSjoerg 196*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_STD 197*4d6fc14bSjoerg 198*4d6fc14bSjoerg// basic_stringbuf 199*4d6fc14bSjoerg 200*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 201*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS basic_stringbuf 202*4d6fc14bSjoerg : public basic_streambuf<_CharT, _Traits> 203*4d6fc14bSjoerg{ 204*4d6fc14bSjoergpublic: 205*4d6fc14bSjoerg typedef _CharT char_type; 206*4d6fc14bSjoerg typedef _Traits traits_type; 207*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 208*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 209*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 210*4d6fc14bSjoerg typedef _Allocator allocator_type; 211*4d6fc14bSjoerg 212*4d6fc14bSjoerg typedef basic_string<char_type, traits_type, allocator_type> string_type; 213*4d6fc14bSjoerg 214*4d6fc14bSjoergprivate: 215*4d6fc14bSjoerg 216*4d6fc14bSjoerg string_type __str_; 217*4d6fc14bSjoerg mutable char_type* __hm_; 218*4d6fc14bSjoerg ios_base::openmode __mode_; 219*4d6fc14bSjoerg 220*4d6fc14bSjoergpublic: 221*4d6fc14bSjoerg // 30.8.2.1 [stringbuf.cons], constructors 222*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 223*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 224*4d6fc14bSjoerg basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} 225*4d6fc14bSjoerg 226*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 227*4d6fc14bSjoerg explicit basic_stringbuf(ios_base::openmode __wch) 228*4d6fc14bSjoerg : __hm_(nullptr), __mode_(__wch) {} 229*4d6fc14bSjoerg#else 230*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 231*4d6fc14bSjoerg explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | 232*4d6fc14bSjoerg ios_base::out) 233*4d6fc14bSjoerg : __hm_(nullptr), __mode_(__wch) {} 234*4d6fc14bSjoerg#endif 235*4d6fc14bSjoerg 236*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 237*4d6fc14bSjoerg explicit basic_stringbuf(const string_type& __s, 238*4d6fc14bSjoerg ios_base::openmode __wch = ios_base::in | ios_base::out) 239*4d6fc14bSjoerg : __str_(__s.get_allocator()), __hm_(nullptr), __mode_(__wch) 240*4d6fc14bSjoerg { 241*4d6fc14bSjoerg str(__s); 242*4d6fc14bSjoerg } 243*4d6fc14bSjoerg 244*4d6fc14bSjoerg basic_stringbuf(basic_stringbuf&& __rhs); 245*4d6fc14bSjoerg 246*4d6fc14bSjoerg // 27.8.1.2 Assign and swap: 247*4d6fc14bSjoerg basic_stringbuf& operator=(basic_stringbuf&& __rhs); 248*4d6fc14bSjoerg void swap(basic_stringbuf& __rhs); 249*4d6fc14bSjoerg 250*4d6fc14bSjoerg // 27.8.1.3 Get and set: 251*4d6fc14bSjoerg string_type str() const; 252*4d6fc14bSjoerg void str(const string_type& __s); 253*4d6fc14bSjoerg 254*4d6fc14bSjoergprotected: 255*4d6fc14bSjoerg // 27.8.1.4 Overridden virtual functions: 256*4d6fc14bSjoerg virtual int_type underflow(); 257*4d6fc14bSjoerg virtual int_type pbackfail(int_type __c = traits_type::eof()); 258*4d6fc14bSjoerg virtual int_type overflow (int_type __c = traits_type::eof()); 259*4d6fc14bSjoerg virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, 260*4d6fc14bSjoerg ios_base::openmode __wch = ios_base::in | ios_base::out); 261*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 262*4d6fc14bSjoerg virtual pos_type seekpos(pos_type __sp, 263*4d6fc14bSjoerg ios_base::openmode __wch = ios_base::in | ios_base::out) { 264*4d6fc14bSjoerg return seekoff(__sp, ios_base::beg, __wch); 265*4d6fc14bSjoerg } 266*4d6fc14bSjoerg}; 267*4d6fc14bSjoerg 268*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 269*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs) 270*4d6fc14bSjoerg : __mode_(__rhs.__mode_) 271*4d6fc14bSjoerg{ 272*4d6fc14bSjoerg char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 273*4d6fc14bSjoerg ptrdiff_t __binp = -1; 274*4d6fc14bSjoerg ptrdiff_t __ninp = -1; 275*4d6fc14bSjoerg ptrdiff_t __einp = -1; 276*4d6fc14bSjoerg if (__rhs.eback() != nullptr) 277*4d6fc14bSjoerg { 278*4d6fc14bSjoerg __binp = __rhs.eback() - __p; 279*4d6fc14bSjoerg __ninp = __rhs.gptr() - __p; 280*4d6fc14bSjoerg __einp = __rhs.egptr() - __p; 281*4d6fc14bSjoerg } 282*4d6fc14bSjoerg ptrdiff_t __bout = -1; 283*4d6fc14bSjoerg ptrdiff_t __nout = -1; 284*4d6fc14bSjoerg ptrdiff_t __eout = -1; 285*4d6fc14bSjoerg if (__rhs.pbase() != nullptr) 286*4d6fc14bSjoerg { 287*4d6fc14bSjoerg __bout = __rhs.pbase() - __p; 288*4d6fc14bSjoerg __nout = __rhs.pptr() - __p; 289*4d6fc14bSjoerg __eout = __rhs.epptr() - __p; 290*4d6fc14bSjoerg } 291*4d6fc14bSjoerg ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 292*4d6fc14bSjoerg __str_ = _VSTD::move(__rhs.__str_); 293*4d6fc14bSjoerg __p = const_cast<char_type*>(__str_.data()); 294*4d6fc14bSjoerg if (__binp != -1) 295*4d6fc14bSjoerg this->setg(__p + __binp, __p + __ninp, __p + __einp); 296*4d6fc14bSjoerg if (__bout != -1) 297*4d6fc14bSjoerg { 298*4d6fc14bSjoerg this->setp(__p + __bout, __p + __eout); 299*4d6fc14bSjoerg this->__pbump(__nout); 300*4d6fc14bSjoerg } 301*4d6fc14bSjoerg __hm_ = __hm == -1 ? nullptr : __p + __hm; 302*4d6fc14bSjoerg __p = const_cast<char_type*>(__rhs.__str_.data()); 303*4d6fc14bSjoerg __rhs.setg(__p, __p, __p); 304*4d6fc14bSjoerg __rhs.setp(__p, __p); 305*4d6fc14bSjoerg __rhs.__hm_ = __p; 306*4d6fc14bSjoerg this->pubimbue(__rhs.getloc()); 307*4d6fc14bSjoerg} 308*4d6fc14bSjoerg 309*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 310*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>& 311*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) 312*4d6fc14bSjoerg{ 313*4d6fc14bSjoerg char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 314*4d6fc14bSjoerg ptrdiff_t __binp = -1; 315*4d6fc14bSjoerg ptrdiff_t __ninp = -1; 316*4d6fc14bSjoerg ptrdiff_t __einp = -1; 317*4d6fc14bSjoerg if (__rhs.eback() != nullptr) 318*4d6fc14bSjoerg { 319*4d6fc14bSjoerg __binp = __rhs.eback() - __p; 320*4d6fc14bSjoerg __ninp = __rhs.gptr() - __p; 321*4d6fc14bSjoerg __einp = __rhs.egptr() - __p; 322*4d6fc14bSjoerg } 323*4d6fc14bSjoerg ptrdiff_t __bout = -1; 324*4d6fc14bSjoerg ptrdiff_t __nout = -1; 325*4d6fc14bSjoerg ptrdiff_t __eout = -1; 326*4d6fc14bSjoerg if (__rhs.pbase() != nullptr) 327*4d6fc14bSjoerg { 328*4d6fc14bSjoerg __bout = __rhs.pbase() - __p; 329*4d6fc14bSjoerg __nout = __rhs.pptr() - __p; 330*4d6fc14bSjoerg __eout = __rhs.epptr() - __p; 331*4d6fc14bSjoerg } 332*4d6fc14bSjoerg ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 333*4d6fc14bSjoerg __str_ = _VSTD::move(__rhs.__str_); 334*4d6fc14bSjoerg __p = const_cast<char_type*>(__str_.data()); 335*4d6fc14bSjoerg if (__binp != -1) 336*4d6fc14bSjoerg this->setg(__p + __binp, __p + __ninp, __p + __einp); 337*4d6fc14bSjoerg else 338*4d6fc14bSjoerg this->setg(nullptr, nullptr, nullptr); 339*4d6fc14bSjoerg if (__bout != -1) 340*4d6fc14bSjoerg { 341*4d6fc14bSjoerg this->setp(__p + __bout, __p + __eout); 342*4d6fc14bSjoerg this->__pbump(__nout); 343*4d6fc14bSjoerg } 344*4d6fc14bSjoerg else 345*4d6fc14bSjoerg this->setp(nullptr, nullptr); 346*4d6fc14bSjoerg 347*4d6fc14bSjoerg __hm_ = __hm == -1 ? nullptr : __p + __hm; 348*4d6fc14bSjoerg __mode_ = __rhs.__mode_; 349*4d6fc14bSjoerg __p = const_cast<char_type*>(__rhs.__str_.data()); 350*4d6fc14bSjoerg __rhs.setg(__p, __p, __p); 351*4d6fc14bSjoerg __rhs.setp(__p, __p); 352*4d6fc14bSjoerg __rhs.__hm_ = __p; 353*4d6fc14bSjoerg this->pubimbue(__rhs.getloc()); 354*4d6fc14bSjoerg return *this; 355*4d6fc14bSjoerg} 356*4d6fc14bSjoerg 357*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 358*4d6fc14bSjoergvoid 359*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) 360*4d6fc14bSjoerg{ 361*4d6fc14bSjoerg char_type* __p = const_cast<char_type*>(__rhs.__str_.data()); 362*4d6fc14bSjoerg ptrdiff_t __rbinp = -1; 363*4d6fc14bSjoerg ptrdiff_t __rninp = -1; 364*4d6fc14bSjoerg ptrdiff_t __reinp = -1; 365*4d6fc14bSjoerg if (__rhs.eback() != nullptr) 366*4d6fc14bSjoerg { 367*4d6fc14bSjoerg __rbinp = __rhs.eback() - __p; 368*4d6fc14bSjoerg __rninp = __rhs.gptr() - __p; 369*4d6fc14bSjoerg __reinp = __rhs.egptr() - __p; 370*4d6fc14bSjoerg } 371*4d6fc14bSjoerg ptrdiff_t __rbout = -1; 372*4d6fc14bSjoerg ptrdiff_t __rnout = -1; 373*4d6fc14bSjoerg ptrdiff_t __reout = -1; 374*4d6fc14bSjoerg if (__rhs.pbase() != nullptr) 375*4d6fc14bSjoerg { 376*4d6fc14bSjoerg __rbout = __rhs.pbase() - __p; 377*4d6fc14bSjoerg __rnout = __rhs.pptr() - __p; 378*4d6fc14bSjoerg __reout = __rhs.epptr() - __p; 379*4d6fc14bSjoerg } 380*4d6fc14bSjoerg ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p; 381*4d6fc14bSjoerg __p = const_cast<char_type*>(__str_.data()); 382*4d6fc14bSjoerg ptrdiff_t __lbinp = -1; 383*4d6fc14bSjoerg ptrdiff_t __lninp = -1; 384*4d6fc14bSjoerg ptrdiff_t __leinp = -1; 385*4d6fc14bSjoerg if (this->eback() != nullptr) 386*4d6fc14bSjoerg { 387*4d6fc14bSjoerg __lbinp = this->eback() - __p; 388*4d6fc14bSjoerg __lninp = this->gptr() - __p; 389*4d6fc14bSjoerg __leinp = this->egptr() - __p; 390*4d6fc14bSjoerg } 391*4d6fc14bSjoerg ptrdiff_t __lbout = -1; 392*4d6fc14bSjoerg ptrdiff_t __lnout = -1; 393*4d6fc14bSjoerg ptrdiff_t __leout = -1; 394*4d6fc14bSjoerg if (this->pbase() != nullptr) 395*4d6fc14bSjoerg { 396*4d6fc14bSjoerg __lbout = this->pbase() - __p; 397*4d6fc14bSjoerg __lnout = this->pptr() - __p; 398*4d6fc14bSjoerg __leout = this->epptr() - __p; 399*4d6fc14bSjoerg } 400*4d6fc14bSjoerg ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p; 401*4d6fc14bSjoerg _VSTD::swap(__mode_, __rhs.__mode_); 402*4d6fc14bSjoerg __str_.swap(__rhs.__str_); 403*4d6fc14bSjoerg __p = const_cast<char_type*>(__str_.data()); 404*4d6fc14bSjoerg if (__rbinp != -1) 405*4d6fc14bSjoerg this->setg(__p + __rbinp, __p + __rninp, __p + __reinp); 406*4d6fc14bSjoerg else 407*4d6fc14bSjoerg this->setg(nullptr, nullptr, nullptr); 408*4d6fc14bSjoerg if (__rbout != -1) 409*4d6fc14bSjoerg { 410*4d6fc14bSjoerg this->setp(__p + __rbout, __p + __reout); 411*4d6fc14bSjoerg this->__pbump(__rnout); 412*4d6fc14bSjoerg } 413*4d6fc14bSjoerg else 414*4d6fc14bSjoerg this->setp(nullptr, nullptr); 415*4d6fc14bSjoerg __hm_ = __rhm == -1 ? nullptr : __p + __rhm; 416*4d6fc14bSjoerg __p = const_cast<char_type*>(__rhs.__str_.data()); 417*4d6fc14bSjoerg if (__lbinp != -1) 418*4d6fc14bSjoerg __rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp); 419*4d6fc14bSjoerg else 420*4d6fc14bSjoerg __rhs.setg(nullptr, nullptr, nullptr); 421*4d6fc14bSjoerg if (__lbout != -1) 422*4d6fc14bSjoerg { 423*4d6fc14bSjoerg __rhs.setp(__p + __lbout, __p + __leout); 424*4d6fc14bSjoerg __rhs.__pbump(__lnout); 425*4d6fc14bSjoerg } 426*4d6fc14bSjoerg else 427*4d6fc14bSjoerg __rhs.setp(nullptr, nullptr); 428*4d6fc14bSjoerg __rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm; 429*4d6fc14bSjoerg locale __tl = __rhs.getloc(); 430*4d6fc14bSjoerg __rhs.pubimbue(this->getloc()); 431*4d6fc14bSjoerg this->pubimbue(__tl); 432*4d6fc14bSjoerg} 433*4d6fc14bSjoerg 434*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 435*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 436*4d6fc14bSjoergvoid 437*4d6fc14bSjoergswap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x, 438*4d6fc14bSjoerg basic_stringbuf<_CharT, _Traits, _Allocator>& __y) 439*4d6fc14bSjoerg{ 440*4d6fc14bSjoerg __x.swap(__y); 441*4d6fc14bSjoerg} 442*4d6fc14bSjoerg 443*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 444*4d6fc14bSjoergbasic_string<_CharT, _Traits, _Allocator> 445*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::str() const 446*4d6fc14bSjoerg{ 447*4d6fc14bSjoerg if (__mode_ & ios_base::out) 448*4d6fc14bSjoerg { 449*4d6fc14bSjoerg if (__hm_ < this->pptr()) 450*4d6fc14bSjoerg __hm_ = this->pptr(); 451*4d6fc14bSjoerg return string_type(this->pbase(), __hm_, __str_.get_allocator()); 452*4d6fc14bSjoerg } 453*4d6fc14bSjoerg else if (__mode_ & ios_base::in) 454*4d6fc14bSjoerg return string_type(this->eback(), this->egptr(), __str_.get_allocator()); 455*4d6fc14bSjoerg return string_type(__str_.get_allocator()); 456*4d6fc14bSjoerg} 457*4d6fc14bSjoerg 458*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 459*4d6fc14bSjoergvoid 460*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s) 461*4d6fc14bSjoerg{ 462*4d6fc14bSjoerg __str_ = __s; 463*4d6fc14bSjoerg __hm_ = nullptr; 464*4d6fc14bSjoerg if (__mode_ & ios_base::in) 465*4d6fc14bSjoerg { 466*4d6fc14bSjoerg __hm_ = const_cast<char_type*>(__str_.data()) + __str_.size(); 467*4d6fc14bSjoerg this->setg(const_cast<char_type*>(__str_.data()), 468*4d6fc14bSjoerg const_cast<char_type*>(__str_.data()), 469*4d6fc14bSjoerg __hm_); 470*4d6fc14bSjoerg } 471*4d6fc14bSjoerg if (__mode_ & ios_base::out) 472*4d6fc14bSjoerg { 473*4d6fc14bSjoerg typename string_type::size_type __sz = __str_.size(); 474*4d6fc14bSjoerg __hm_ = const_cast<char_type*>(__str_.data()) + __sz; 475*4d6fc14bSjoerg __str_.resize(__str_.capacity()); 476*4d6fc14bSjoerg this->setp(const_cast<char_type*>(__str_.data()), 477*4d6fc14bSjoerg const_cast<char_type*>(__str_.data()) + __str_.size()); 478*4d6fc14bSjoerg if (__mode_ & (ios_base::app | ios_base::ate)) 479*4d6fc14bSjoerg { 480*4d6fc14bSjoerg while (__sz > INT_MAX) 481*4d6fc14bSjoerg { 482*4d6fc14bSjoerg this->pbump(INT_MAX); 483*4d6fc14bSjoerg __sz -= INT_MAX; 484*4d6fc14bSjoerg } 485*4d6fc14bSjoerg if (__sz > 0) 486*4d6fc14bSjoerg this->pbump(__sz); 487*4d6fc14bSjoerg } 488*4d6fc14bSjoerg } 489*4d6fc14bSjoerg} 490*4d6fc14bSjoerg 491*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 492*4d6fc14bSjoergtypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 493*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::underflow() 494*4d6fc14bSjoerg{ 495*4d6fc14bSjoerg if (__hm_ < this->pptr()) 496*4d6fc14bSjoerg __hm_ = this->pptr(); 497*4d6fc14bSjoerg if (__mode_ & ios_base::in) 498*4d6fc14bSjoerg { 499*4d6fc14bSjoerg if (this->egptr() < __hm_) 500*4d6fc14bSjoerg this->setg(this->eback(), this->gptr(), __hm_); 501*4d6fc14bSjoerg if (this->gptr() < this->egptr()) 502*4d6fc14bSjoerg return traits_type::to_int_type(*this->gptr()); 503*4d6fc14bSjoerg } 504*4d6fc14bSjoerg return traits_type::eof(); 505*4d6fc14bSjoerg} 506*4d6fc14bSjoerg 507*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 508*4d6fc14bSjoergtypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 509*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c) 510*4d6fc14bSjoerg{ 511*4d6fc14bSjoerg if (__hm_ < this->pptr()) 512*4d6fc14bSjoerg __hm_ = this->pptr(); 513*4d6fc14bSjoerg if (this->eback() < this->gptr()) 514*4d6fc14bSjoerg { 515*4d6fc14bSjoerg if (traits_type::eq_int_type(__c, traits_type::eof())) 516*4d6fc14bSjoerg { 517*4d6fc14bSjoerg this->setg(this->eback(), this->gptr()-1, __hm_); 518*4d6fc14bSjoerg return traits_type::not_eof(__c); 519*4d6fc14bSjoerg } 520*4d6fc14bSjoerg if ((__mode_ & ios_base::out) || 521*4d6fc14bSjoerg traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) 522*4d6fc14bSjoerg { 523*4d6fc14bSjoerg this->setg(this->eback(), this->gptr()-1, __hm_); 524*4d6fc14bSjoerg *this->gptr() = traits_type::to_char_type(__c); 525*4d6fc14bSjoerg return __c; 526*4d6fc14bSjoerg } 527*4d6fc14bSjoerg } 528*4d6fc14bSjoerg return traits_type::eof(); 529*4d6fc14bSjoerg} 530*4d6fc14bSjoerg 531*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 532*4d6fc14bSjoergtypename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type 533*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) 534*4d6fc14bSjoerg{ 535*4d6fc14bSjoerg if (!traits_type::eq_int_type(__c, traits_type::eof())) 536*4d6fc14bSjoerg { 537*4d6fc14bSjoerg ptrdiff_t __ninp = this->gptr() - this->eback(); 538*4d6fc14bSjoerg if (this->pptr() == this->epptr()) 539*4d6fc14bSjoerg { 540*4d6fc14bSjoerg if (!(__mode_ & ios_base::out)) 541*4d6fc14bSjoerg return traits_type::eof(); 542*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 543*4d6fc14bSjoerg try 544*4d6fc14bSjoerg { 545*4d6fc14bSjoerg#endif // _LIBCPP_NO_EXCEPTIONS 546*4d6fc14bSjoerg ptrdiff_t __nout = this->pptr() - this->pbase(); 547*4d6fc14bSjoerg ptrdiff_t __hm = __hm_ - this->pbase(); 548*4d6fc14bSjoerg __str_.push_back(char_type()); 549*4d6fc14bSjoerg __str_.resize(__str_.capacity()); 550*4d6fc14bSjoerg char_type* __p = const_cast<char_type*>(__str_.data()); 551*4d6fc14bSjoerg this->setp(__p, __p + __str_.size()); 552*4d6fc14bSjoerg this->__pbump(__nout); 553*4d6fc14bSjoerg __hm_ = this->pbase() + __hm; 554*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 555*4d6fc14bSjoerg } 556*4d6fc14bSjoerg catch (...) 557*4d6fc14bSjoerg { 558*4d6fc14bSjoerg return traits_type::eof(); 559*4d6fc14bSjoerg } 560*4d6fc14bSjoerg#endif // _LIBCPP_NO_EXCEPTIONS 561*4d6fc14bSjoerg } 562*4d6fc14bSjoerg __hm_ = _VSTD::max(this->pptr() + 1, __hm_); 563*4d6fc14bSjoerg if (__mode_ & ios_base::in) 564*4d6fc14bSjoerg { 565*4d6fc14bSjoerg char_type* __p = const_cast<char_type*>(__str_.data()); 566*4d6fc14bSjoerg this->setg(__p, __p + __ninp, __hm_); 567*4d6fc14bSjoerg } 568*4d6fc14bSjoerg return this->sputc(traits_type::to_char_type(__c)); 569*4d6fc14bSjoerg } 570*4d6fc14bSjoerg return traits_type::not_eof(__c); 571*4d6fc14bSjoerg} 572*4d6fc14bSjoerg 573*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 574*4d6fc14bSjoergtypename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type 575*4d6fc14bSjoergbasic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, 576*4d6fc14bSjoerg ios_base::seekdir __way, 577*4d6fc14bSjoerg ios_base::openmode __wch) 578*4d6fc14bSjoerg{ 579*4d6fc14bSjoerg if (__hm_ < this->pptr()) 580*4d6fc14bSjoerg __hm_ = this->pptr(); 581*4d6fc14bSjoerg if ((__wch & (ios_base::in | ios_base::out)) == 0) 582*4d6fc14bSjoerg return pos_type(-1); 583*4d6fc14bSjoerg if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) 584*4d6fc14bSjoerg && __way == ios_base::cur) 585*4d6fc14bSjoerg return pos_type(-1); 586*4d6fc14bSjoerg const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); 587*4d6fc14bSjoerg off_type __noff; 588*4d6fc14bSjoerg switch (__way) 589*4d6fc14bSjoerg { 590*4d6fc14bSjoerg case ios_base::beg: 591*4d6fc14bSjoerg __noff = 0; 592*4d6fc14bSjoerg break; 593*4d6fc14bSjoerg case ios_base::cur: 594*4d6fc14bSjoerg if (__wch & ios_base::in) 595*4d6fc14bSjoerg __noff = this->gptr() - this->eback(); 596*4d6fc14bSjoerg else 597*4d6fc14bSjoerg __noff = this->pptr() - this->pbase(); 598*4d6fc14bSjoerg break; 599*4d6fc14bSjoerg case ios_base::end: 600*4d6fc14bSjoerg __noff = __hm; 601*4d6fc14bSjoerg break; 602*4d6fc14bSjoerg default: 603*4d6fc14bSjoerg return pos_type(-1); 604*4d6fc14bSjoerg } 605*4d6fc14bSjoerg __noff += __off; 606*4d6fc14bSjoerg if (__noff < 0 || __hm < __noff) 607*4d6fc14bSjoerg return pos_type(-1); 608*4d6fc14bSjoerg if (__noff != 0) 609*4d6fc14bSjoerg { 610*4d6fc14bSjoerg if ((__wch & ios_base::in) && this->gptr() == nullptr) 611*4d6fc14bSjoerg return pos_type(-1); 612*4d6fc14bSjoerg if ((__wch & ios_base::out) && this->pptr() == nullptr) 613*4d6fc14bSjoerg return pos_type(-1); 614*4d6fc14bSjoerg } 615*4d6fc14bSjoerg if (__wch & ios_base::in) 616*4d6fc14bSjoerg this->setg(this->eback(), this->eback() + __noff, __hm_); 617*4d6fc14bSjoerg if (__wch & ios_base::out) 618*4d6fc14bSjoerg { 619*4d6fc14bSjoerg this->setp(this->pbase(), this->epptr()); 620*4d6fc14bSjoerg this->pbump(__noff); 621*4d6fc14bSjoerg } 622*4d6fc14bSjoerg return pos_type(__noff); 623*4d6fc14bSjoerg} 624*4d6fc14bSjoerg 625*4d6fc14bSjoerg// basic_istringstream 626*4d6fc14bSjoerg 627*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 628*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS basic_istringstream 629*4d6fc14bSjoerg : public basic_istream<_CharT, _Traits> 630*4d6fc14bSjoerg{ 631*4d6fc14bSjoergpublic: 632*4d6fc14bSjoerg typedef _CharT char_type; 633*4d6fc14bSjoerg typedef _Traits traits_type; 634*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 635*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 636*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 637*4d6fc14bSjoerg typedef _Allocator allocator_type; 638*4d6fc14bSjoerg 639*4d6fc14bSjoerg typedef basic_string<char_type, traits_type, allocator_type> string_type; 640*4d6fc14bSjoerg 641*4d6fc14bSjoergprivate: 642*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 643*4d6fc14bSjoerg 644*4d6fc14bSjoergpublic: 645*4d6fc14bSjoerg // 30.8.3.1 [istringstream.cons], constructors 646*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 647*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 648*4d6fc14bSjoerg basic_istringstream() : basic_istringstream(ios_base::in) {} 649*4d6fc14bSjoerg 650*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 651*4d6fc14bSjoerg explicit basic_istringstream(ios_base::openmode __wch) 652*4d6fc14bSjoerg : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) {} 653*4d6fc14bSjoerg#else 654*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 655*4d6fc14bSjoerg explicit basic_istringstream(ios_base::openmode __wch = ios_base::in) 656*4d6fc14bSjoerg : basic_istream<_CharT, _Traits>(&__sb_), __sb_(__wch | ios_base::in) {} 657*4d6fc14bSjoerg#endif 658*4d6fc14bSjoerg 659*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 660*4d6fc14bSjoerg explicit basic_istringstream(const string_type& __s, 661*4d6fc14bSjoerg ios_base::openmode __wch = ios_base::in) 662*4d6fc14bSjoerg : basic_istream<_CharT, _Traits>(&__sb_) 663*4d6fc14bSjoerg , __sb_(__s, __wch | ios_base::in) 664*4d6fc14bSjoerg { } 665*4d6fc14bSjoerg 666*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 667*4d6fc14bSjoerg basic_istringstream(basic_istringstream&& __rhs) 668*4d6fc14bSjoerg : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)) 669*4d6fc14bSjoerg , __sb_(_VSTD::move(__rhs.__sb_)) 670*4d6fc14bSjoerg { 671*4d6fc14bSjoerg basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 672*4d6fc14bSjoerg } 673*4d6fc14bSjoerg 674*4d6fc14bSjoerg // 27.8.2.2 Assign and swap: 675*4d6fc14bSjoerg basic_istringstream& operator=(basic_istringstream&& __rhs) { 676*4d6fc14bSjoerg basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 677*4d6fc14bSjoerg __sb_ = _VSTD::move(__rhs.__sb_); 678*4d6fc14bSjoerg return *this; 679*4d6fc14bSjoerg } 680*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 681*4d6fc14bSjoerg void swap(basic_istringstream& __rhs) { 682*4d6fc14bSjoerg basic_istream<char_type, traits_type>::swap(__rhs); 683*4d6fc14bSjoerg __sb_.swap(__rhs.__sb_); 684*4d6fc14bSjoerg } 685*4d6fc14bSjoerg 686*4d6fc14bSjoerg // 27.8.2.3 Members: 687*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 688*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 689*4d6fc14bSjoerg return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 690*4d6fc14bSjoerg } 691*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 692*4d6fc14bSjoerg string_type str() const { 693*4d6fc14bSjoerg return __sb_.str(); 694*4d6fc14bSjoerg } 695*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 696*4d6fc14bSjoerg void str(const string_type& __s) { 697*4d6fc14bSjoerg __sb_.str(__s); 698*4d6fc14bSjoerg } 699*4d6fc14bSjoerg}; 700*4d6fc14bSjoerg 701*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 702*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 703*4d6fc14bSjoergvoid 704*4d6fc14bSjoergswap(basic_istringstream<_CharT, _Traits, _Allocator>& __x, 705*4d6fc14bSjoerg basic_istringstream<_CharT, _Traits, _Allocator>& __y) 706*4d6fc14bSjoerg{ 707*4d6fc14bSjoerg __x.swap(__y); 708*4d6fc14bSjoerg} 709*4d6fc14bSjoerg 710*4d6fc14bSjoerg// basic_ostringstream 711*4d6fc14bSjoerg 712*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 713*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS basic_ostringstream 714*4d6fc14bSjoerg : public basic_ostream<_CharT, _Traits> 715*4d6fc14bSjoerg{ 716*4d6fc14bSjoergpublic: 717*4d6fc14bSjoerg typedef _CharT char_type; 718*4d6fc14bSjoerg typedef _Traits traits_type; 719*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 720*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 721*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 722*4d6fc14bSjoerg typedef _Allocator allocator_type; 723*4d6fc14bSjoerg 724*4d6fc14bSjoerg typedef basic_string<char_type, traits_type, allocator_type> string_type; 725*4d6fc14bSjoerg 726*4d6fc14bSjoergprivate: 727*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 728*4d6fc14bSjoerg 729*4d6fc14bSjoergpublic: 730*4d6fc14bSjoerg // 30.8.4.1 [ostringstream.cons], constructors 731*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 732*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 733*4d6fc14bSjoerg basic_ostringstream() : basic_ostringstream(ios_base::out) {} 734*4d6fc14bSjoerg 735*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 736*4d6fc14bSjoerg explicit basic_ostringstream(ios_base::openmode __wch) 737*4d6fc14bSjoerg : basic_ostream<_CharT, _Traits>(&__sb_), 738*4d6fc14bSjoerg __sb_(__wch | ios_base::out) {} 739*4d6fc14bSjoerg#else 740*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 741*4d6fc14bSjoerg explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out) 742*4d6fc14bSjoerg : basic_ostream<_CharT, _Traits>(&__sb_), 743*4d6fc14bSjoerg __sb_(__wch | ios_base::out) {} 744*4d6fc14bSjoerg#endif 745*4d6fc14bSjoerg 746*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 747*4d6fc14bSjoerg explicit basic_ostringstream(const string_type& __s, 748*4d6fc14bSjoerg ios_base::openmode __wch = ios_base::out) 749*4d6fc14bSjoerg : basic_ostream<_CharT, _Traits>(&__sb_) 750*4d6fc14bSjoerg , __sb_(__s, __wch | ios_base::out) 751*4d6fc14bSjoerg { } 752*4d6fc14bSjoerg 753*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 754*4d6fc14bSjoerg basic_ostringstream(basic_ostringstream&& __rhs) 755*4d6fc14bSjoerg : basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)) 756*4d6fc14bSjoerg , __sb_(_VSTD::move(__rhs.__sb_)) 757*4d6fc14bSjoerg { 758*4d6fc14bSjoerg basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_); 759*4d6fc14bSjoerg } 760*4d6fc14bSjoerg 761*4d6fc14bSjoerg // 27.8.2.2 Assign and swap: 762*4d6fc14bSjoerg basic_ostringstream& operator=(basic_ostringstream&& __rhs) { 763*4d6fc14bSjoerg basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 764*4d6fc14bSjoerg __sb_ = _VSTD::move(__rhs.__sb_); 765*4d6fc14bSjoerg return *this; 766*4d6fc14bSjoerg } 767*4d6fc14bSjoerg 768*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 769*4d6fc14bSjoerg void swap(basic_ostringstream& __rhs) { 770*4d6fc14bSjoerg basic_ostream<char_type, traits_type>::swap(__rhs); 771*4d6fc14bSjoerg __sb_.swap(__rhs.__sb_); 772*4d6fc14bSjoerg } 773*4d6fc14bSjoerg 774*4d6fc14bSjoerg // 27.8.2.3 Members: 775*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 776*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 777*4d6fc14bSjoerg return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 778*4d6fc14bSjoerg } 779*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 780*4d6fc14bSjoerg string_type str() const { 781*4d6fc14bSjoerg return __sb_.str(); 782*4d6fc14bSjoerg } 783*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 784*4d6fc14bSjoerg void str(const string_type& __s) { 785*4d6fc14bSjoerg __sb_.str(__s); 786*4d6fc14bSjoerg } 787*4d6fc14bSjoerg}; 788*4d6fc14bSjoerg 789*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 790*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 791*4d6fc14bSjoergvoid 792*4d6fc14bSjoergswap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x, 793*4d6fc14bSjoerg basic_ostringstream<_CharT, _Traits, _Allocator>& __y) 794*4d6fc14bSjoerg{ 795*4d6fc14bSjoerg __x.swap(__y); 796*4d6fc14bSjoerg} 797*4d6fc14bSjoerg 798*4d6fc14bSjoerg// basic_stringstream 799*4d6fc14bSjoerg 800*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 801*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS basic_stringstream 802*4d6fc14bSjoerg : public basic_iostream<_CharT, _Traits> 803*4d6fc14bSjoerg{ 804*4d6fc14bSjoergpublic: 805*4d6fc14bSjoerg typedef _CharT char_type; 806*4d6fc14bSjoerg typedef _Traits traits_type; 807*4d6fc14bSjoerg typedef typename traits_type::int_type int_type; 808*4d6fc14bSjoerg typedef typename traits_type::pos_type pos_type; 809*4d6fc14bSjoerg typedef typename traits_type::off_type off_type; 810*4d6fc14bSjoerg typedef _Allocator allocator_type; 811*4d6fc14bSjoerg 812*4d6fc14bSjoerg typedef basic_string<char_type, traits_type, allocator_type> string_type; 813*4d6fc14bSjoerg 814*4d6fc14bSjoergprivate: 815*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type> __sb_; 816*4d6fc14bSjoerg 817*4d6fc14bSjoergpublic: 818*4d6fc14bSjoerg // 30.8.5.1 [stringstream.cons], constructors 819*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 820*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 821*4d6fc14bSjoerg basic_stringstream() : basic_stringstream(ios_base::in | ios_base::out) {} 822*4d6fc14bSjoerg 823*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 824*4d6fc14bSjoerg explicit basic_stringstream(ios_base::openmode __wch) 825*4d6fc14bSjoerg : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) {} 826*4d6fc14bSjoerg#else 827*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 828*4d6fc14bSjoerg explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | 829*4d6fc14bSjoerg ios_base::out) 830*4d6fc14bSjoerg : basic_iostream<_CharT, _Traits>(&__sb_), __sb_(__wch) {} 831*4d6fc14bSjoerg#endif 832*4d6fc14bSjoerg 833*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 834*4d6fc14bSjoerg explicit basic_stringstream(const string_type& __s, 835*4d6fc14bSjoerg ios_base::openmode __wch = ios_base::in | ios_base::out) 836*4d6fc14bSjoerg : basic_iostream<_CharT, _Traits>(&__sb_) 837*4d6fc14bSjoerg , __sb_(__s, __wch) 838*4d6fc14bSjoerg { } 839*4d6fc14bSjoerg 840*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 841*4d6fc14bSjoerg basic_stringstream(basic_stringstream&& __rhs) 842*4d6fc14bSjoerg : basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)) 843*4d6fc14bSjoerg , __sb_(_VSTD::move(__rhs.__sb_)) 844*4d6fc14bSjoerg { 845*4d6fc14bSjoerg basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_); 846*4d6fc14bSjoerg } 847*4d6fc14bSjoerg 848*4d6fc14bSjoerg // 27.8.2.2 Assign and swap: 849*4d6fc14bSjoerg basic_stringstream& operator=(basic_stringstream&& __rhs) { 850*4d6fc14bSjoerg basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 851*4d6fc14bSjoerg __sb_ = _VSTD::move(__rhs.__sb_); 852*4d6fc14bSjoerg return *this; 853*4d6fc14bSjoerg } 854*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 855*4d6fc14bSjoerg void swap(basic_stringstream& __rhs) { 856*4d6fc14bSjoerg basic_iostream<char_type, traits_type>::swap(__rhs); 857*4d6fc14bSjoerg __sb_.swap(__rhs.__sb_); 858*4d6fc14bSjoerg } 859*4d6fc14bSjoerg 860*4d6fc14bSjoerg // 27.8.2.3 Members: 861*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 862*4d6fc14bSjoerg basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const { 863*4d6fc14bSjoerg return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_); 864*4d6fc14bSjoerg } 865*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 866*4d6fc14bSjoerg string_type str() const { 867*4d6fc14bSjoerg return __sb_.str(); 868*4d6fc14bSjoerg } 869*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 870*4d6fc14bSjoerg void str(const string_type& __s) { 871*4d6fc14bSjoerg __sb_.str(__s); 872*4d6fc14bSjoerg } 873*4d6fc14bSjoerg}; 874*4d6fc14bSjoerg 875*4d6fc14bSjoergtemplate <class _CharT, class _Traits, class _Allocator> 876*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 877*4d6fc14bSjoergvoid 878*4d6fc14bSjoergswap(basic_stringstream<_CharT, _Traits, _Allocator>& __x, 879*4d6fc14bSjoerg basic_stringstream<_CharT, _Traits, _Allocator>& __y) 880*4d6fc14bSjoerg{ 881*4d6fc14bSjoerg __x.swap(__y); 882*4d6fc14bSjoerg} 883*4d6fc14bSjoerg 884*4d6fc14bSjoerg#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1) 885*4d6fc14bSjoerg_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf<char>) 886*4d6fc14bSjoerg_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream<char>) 887*4d6fc14bSjoerg_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream<char>) 888*4d6fc14bSjoerg_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream<char>) 889*4d6fc14bSjoerg#endif 890*4d6fc14bSjoerg 891*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_STD 892*4d6fc14bSjoerg 893*4d6fc14bSjoerg_LIBCPP_POP_MACROS 894*4d6fc14bSjoerg 895*4d6fc14bSjoerg#endif // _LIBCPP_SSTREAM 896