~ubuntu-branches/ubuntu/saucy/emscripten/saucy-proposed

« back to all changes in this revision

Viewing changes to system/include/libcxx/sstream

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

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