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