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