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