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