xref: /freebsd/contrib/llvm-project/libcxx/include/strstream (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===--------------------------- strstream --------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_STRSTREAM
110b57cec5SDimitry Andric#define _LIBCPP_STRSTREAM
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    strstream synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricclass strstreambuf
170b57cec5SDimitry Andric    : public basic_streambuf<char>
180b57cec5SDimitry Andric{
190b57cec5SDimitry Andricpublic:
20*e8d8bef9SDimitry Andric    explicit strstreambuf(streamsize alsize_arg = 0); // before C++20
21*e8d8bef9SDimitry Andric    strstreambuf() : strstreambuf(0) {}               // C++20
22*e8d8bef9SDimitry Andric    explicit strstreambuf(streamsize alsize_arg);     // C++20
23*e8d8bef9SDimitry Andric
240b57cec5SDimitry Andric    strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
25*e8d8bef9SDimitry Andric    strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
260b57cec5SDimitry Andric    strstreambuf(const char* gnext_arg, streamsize n);
270b57cec5SDimitry Andric
28*e8d8bef9SDimitry Andric    strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = nullptr);
290b57cec5SDimitry Andric    strstreambuf(const signed char* gnext_arg, streamsize n);
30*e8d8bef9SDimitry Andric    strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = nullptr);
310b57cec5SDimitry Andric    strstreambuf(const unsigned char* gnext_arg, streamsize n);
320b57cec5SDimitry Andric
330b57cec5SDimitry Andric    strstreambuf(strstreambuf&& rhs);
340b57cec5SDimitry Andric    strstreambuf& operator=(strstreambuf&& rhs);
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric    virtual ~strstreambuf();
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric    void swap(strstreambuf& rhs);
390b57cec5SDimitry Andric
400b57cec5SDimitry Andric    void freeze(bool freezefl = true);
410b57cec5SDimitry Andric    char* str();
420b57cec5SDimitry Andric    int pcount() const;
430b57cec5SDimitry Andric
440b57cec5SDimitry Andricprotected:
450b57cec5SDimitry Andric    virtual int_type overflow (int_type c = EOF);
460b57cec5SDimitry Andric    virtual int_type pbackfail(int_type c = EOF);
470b57cec5SDimitry Andric    virtual int_type underflow();
480b57cec5SDimitry Andric    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
490b57cec5SDimitry Andric                             ios_base::openmode which = ios_base::in | ios_base::out);
500b57cec5SDimitry Andric    virtual pos_type seekpos(pos_type sp,
510b57cec5SDimitry Andric                             ios_base::openmode which = ios_base::in | ios_base::out);
520b57cec5SDimitry Andric    virtual streambuf* setbuf(char* s, streamsize n);
530b57cec5SDimitry Andric
540b57cec5SDimitry Andricprivate:
550b57cec5SDimitry Andric    typedef T1 strstate;                // exposition only
560b57cec5SDimitry Andric    static const strstate allocated;    // exposition only
570b57cec5SDimitry Andric    static const strstate constant;     // exposition only
580b57cec5SDimitry Andric    static const strstate dynamic;      // exposition only
590b57cec5SDimitry Andric    static const strstate frozen;       // exposition only
600b57cec5SDimitry Andric    strstate strmode;                   // exposition only
610b57cec5SDimitry Andric    streamsize alsize;                  // exposition only
620b57cec5SDimitry Andric    void* (*palloc)(size_t);            // exposition only
630b57cec5SDimitry Andric    void (*pfree)(void*);               // exposition only
640b57cec5SDimitry Andric};
650b57cec5SDimitry Andric
660b57cec5SDimitry Andricclass istrstream
670b57cec5SDimitry Andric    : public basic_istream<char>
680b57cec5SDimitry Andric{
690b57cec5SDimitry Andricpublic:
700b57cec5SDimitry Andric    explicit istrstream(const char* s);
710b57cec5SDimitry Andric    explicit istrstream(char* s);
720b57cec5SDimitry Andric    istrstream(const char* s, streamsize n);
730b57cec5SDimitry Andric    istrstream(char* s, streamsize n);
740b57cec5SDimitry Andric
750b57cec5SDimitry Andric    virtual ~istrstream();
760b57cec5SDimitry Andric
770b57cec5SDimitry Andric    strstreambuf* rdbuf() const;
780b57cec5SDimitry Andric    char *str();
790b57cec5SDimitry Andric
800b57cec5SDimitry Andricprivate:
810b57cec5SDimitry Andric    strstreambuf sb; // exposition only
820b57cec5SDimitry Andric};
830b57cec5SDimitry Andric
840b57cec5SDimitry Andricclass ostrstream
850b57cec5SDimitry Andric    : public basic_ostream<char>
860b57cec5SDimitry Andric{
870b57cec5SDimitry Andricpublic:
880b57cec5SDimitry Andric    ostrstream();
890b57cec5SDimitry Andric    ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
900b57cec5SDimitry Andric
910b57cec5SDimitry Andric    virtual ~ostrstream();
920b57cec5SDimitry Andric
930b57cec5SDimitry Andric    strstreambuf* rdbuf() const;
940b57cec5SDimitry Andric    void freeze(bool freezefl = true);
950b57cec5SDimitry Andric    char* str();
960b57cec5SDimitry Andric    int pcount() const;
970b57cec5SDimitry Andric
980b57cec5SDimitry Andricprivate:
990b57cec5SDimitry Andric    strstreambuf sb; // exposition only
1000b57cec5SDimitry Andric};
1010b57cec5SDimitry Andric
1020b57cec5SDimitry Andricclass strstream
1030b57cec5SDimitry Andric    : public basic_iostream<char>
1040b57cec5SDimitry Andric{
1050b57cec5SDimitry Andricpublic:
1060b57cec5SDimitry Andric    // Types
1070b57cec5SDimitry Andric    typedef char                        char_type;
1080b57cec5SDimitry Andric    typedef char_traits<char>::int_type int_type;
1090b57cec5SDimitry Andric    typedef char_traits<char>::pos_type pos_type;
1100b57cec5SDimitry Andric    typedef char_traits<char>::off_type off_type;
1110b57cec5SDimitry Andric
1120b57cec5SDimitry Andric    // constructors/destructor
1130b57cec5SDimitry Andric    strstream();
1140b57cec5SDimitry Andric    strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andric    virtual ~strstream();
1170b57cec5SDimitry Andric
1180b57cec5SDimitry Andric    // Members:
1190b57cec5SDimitry Andric    strstreambuf* rdbuf() const;
1200b57cec5SDimitry Andric    void freeze(bool freezefl = true);
1210b57cec5SDimitry Andric    int pcount() const;
1220b57cec5SDimitry Andric    char* str();
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andricprivate:
1250b57cec5SDimitry Andric    strstreambuf sb; // exposition only
1260b57cec5SDimitry Andric};
1270b57cec5SDimitry Andric
1280b57cec5SDimitry Andric}  // std
1290b57cec5SDimitry Andric
1300b57cec5SDimitry Andric*/
1310b57cec5SDimitry Andric
1320b57cec5SDimitry Andric#include <__config>
1330b57cec5SDimitry Andric#include <ostream>
1340b57cec5SDimitry Andric#include <istream>
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1370b57cec5SDimitry Andric#pragma GCC system_header
1380b57cec5SDimitry Andric#endif
1390b57cec5SDimitry Andric
1400b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1410b57cec5SDimitry Andric
1420b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS strstreambuf
1430b57cec5SDimitry Andric    : public streambuf
1440b57cec5SDimitry Andric{
1450b57cec5SDimitry Andricpublic:
146*e8d8bef9SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
147*e8d8bef9SDimitry Andric    strstreambuf() : strstreambuf(0) {}
148*e8d8bef9SDimitry Andric    explicit strstreambuf(streamsize __alsize);
149*e8d8bef9SDimitry Andric#else
1500b57cec5SDimitry Andric    explicit strstreambuf(streamsize __alsize = 0);
151*e8d8bef9SDimitry Andric#endif
1520b57cec5SDimitry Andric    strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
153*e8d8bef9SDimitry Andric    strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
1540b57cec5SDimitry Andric    strstreambuf(const char* __gnext, streamsize __n);
1550b57cec5SDimitry Andric
156*e8d8bef9SDimitry Andric    strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);
1570b57cec5SDimitry Andric    strstreambuf(const signed char* __gnext, streamsize __n);
158*e8d8bef9SDimitry Andric    strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
1590b57cec5SDimitry Andric    strstreambuf(const unsigned char* __gnext, streamsize __n);
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1630b57cec5SDimitry Andric    strstreambuf(strstreambuf&& __rhs);
1640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1650b57cec5SDimitry Andric    strstreambuf& operator=(strstreambuf&& __rhs);
1660b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andric    virtual ~strstreambuf();
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andric    void swap(strstreambuf& __rhs);
1710b57cec5SDimitry Andric
1720b57cec5SDimitry Andric    void freeze(bool __freezefl = true);
1730b57cec5SDimitry Andric    char* str();
1740b57cec5SDimitry Andric    int pcount() const;
1750b57cec5SDimitry Andric
1760b57cec5SDimitry Andricprotected:
1770b57cec5SDimitry Andric    virtual int_type overflow (int_type __c = EOF);
1780b57cec5SDimitry Andric    virtual int_type pbackfail(int_type __c = EOF);
1790b57cec5SDimitry Andric    virtual int_type underflow();
1800b57cec5SDimitry Andric    virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
1810b57cec5SDimitry Andric                             ios_base::openmode __which = ios_base::in | ios_base::out);
1820b57cec5SDimitry Andric    virtual pos_type seekpos(pos_type __sp,
1830b57cec5SDimitry Andric                             ios_base::openmode __which = ios_base::in | ios_base::out);
1840b57cec5SDimitry Andric
1850b57cec5SDimitry Andricprivate:
1860b57cec5SDimitry Andric    typedef unsigned __mode_type;
1870b57cec5SDimitry Andric    static const __mode_type __allocated = 0x01;
1880b57cec5SDimitry Andric    static const __mode_type __constant  = 0x02;
1890b57cec5SDimitry Andric    static const __mode_type __dynamic   = 0x04;
1900b57cec5SDimitry Andric    static const __mode_type __frozen    = 0x08;
1910b57cec5SDimitry Andric    static const streamsize    __default_alsize = 4096;
1920b57cec5SDimitry Andric
1930b57cec5SDimitry Andric    __mode_type __strmode_;
1940b57cec5SDimitry Andric    streamsize __alsize_;
1950b57cec5SDimitry Andric    void* (*__palloc_)(size_t);
1960b57cec5SDimitry Andric    void (*__pfree_)(void*);
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andric    void __init(char* __gnext, streamsize __n, char* __pbeg);
1990b57cec5SDimitry Andric};
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2020b57cec5SDimitry Andric
2030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2040b57cec5SDimitry Andricstrstreambuf::strstreambuf(strstreambuf&& __rhs)
2050b57cec5SDimitry Andric    : streambuf(__rhs),
2060b57cec5SDimitry Andric      __strmode_(__rhs.__strmode_),
2070b57cec5SDimitry Andric      __alsize_(__rhs.__alsize_),
2080b57cec5SDimitry Andric      __palloc_(__rhs.__palloc_),
2090b57cec5SDimitry Andric      __pfree_(__rhs.__pfree_)
2100b57cec5SDimitry Andric{
2110b57cec5SDimitry Andric    __rhs.setg(nullptr, nullptr, nullptr);
2120b57cec5SDimitry Andric    __rhs.setp(nullptr, nullptr);
2130b57cec5SDimitry Andric}
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2160b57cec5SDimitry Andricstrstreambuf&
2170b57cec5SDimitry Andricstrstreambuf::operator=(strstreambuf&& __rhs)
2180b57cec5SDimitry Andric{
2190b57cec5SDimitry Andric    if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
2200b57cec5SDimitry Andric    {
2210b57cec5SDimitry Andric        if (__pfree_)
2220b57cec5SDimitry Andric            __pfree_(eback());
2230b57cec5SDimitry Andric        else
2240b57cec5SDimitry Andric            delete [] eback();
2250b57cec5SDimitry Andric    }
2260b57cec5SDimitry Andric    streambuf::operator=(__rhs);
2270b57cec5SDimitry Andric    __strmode_ = __rhs.__strmode_;
2280b57cec5SDimitry Andric    __alsize_ = __rhs.__alsize_;
2290b57cec5SDimitry Andric    __palloc_ = __rhs.__palloc_;
2300b57cec5SDimitry Andric    __pfree_ = __rhs.__pfree_;
2310b57cec5SDimitry Andric    __rhs.setg(nullptr, nullptr, nullptr);
2320b57cec5SDimitry Andric    __rhs.setp(nullptr, nullptr);
2330b57cec5SDimitry Andric    return *this;
2340b57cec5SDimitry Andric}
2350b57cec5SDimitry Andric
2360b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
2370b57cec5SDimitry Andric
2380b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS istrstream
2390b57cec5SDimitry Andric    : public istream
2400b57cec5SDimitry Andric{
2410b57cec5SDimitry Andricpublic:
2420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2430b57cec5SDimitry Andric    explicit istrstream(const char* __s)
2440b57cec5SDimitry Andric        : istream(&__sb_), __sb_(__s, 0) {}
2450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2460b57cec5SDimitry Andric    explicit istrstream(char* __s)
2470b57cec5SDimitry Andric        : istream(&__sb_), __sb_(__s, 0) {}
2480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2490b57cec5SDimitry Andric    istrstream(const char* __s, streamsize __n)
2500b57cec5SDimitry Andric        : istream(&__sb_), __sb_(__s, __n) {}
2510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2520b57cec5SDimitry Andric    istrstream(char* __s, streamsize __n)
2530b57cec5SDimitry Andric        : istream(&__sb_), __sb_(__s, __n) {}
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2570b57cec5SDimitry Andric    istrstream(istrstream&& __rhs)
2580b57cec5SDimitry Andric        : istream(_VSTD::move(__rhs)),
2590b57cec5SDimitry Andric          __sb_(_VSTD::move(__rhs.__sb_))
2600b57cec5SDimitry Andric    {
2610b57cec5SDimitry Andric        istream::set_rdbuf(&__sb_);
2620b57cec5SDimitry Andric    }
2630b57cec5SDimitry Andric
2640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2650b57cec5SDimitry Andric    istrstream& operator=(istrstream&& __rhs)
2660b57cec5SDimitry Andric    {
2670b57cec5SDimitry Andric        istream::operator=(_VSTD::move(__rhs));
2680b57cec5SDimitry Andric        __sb_ = _VSTD::move(__rhs.__sb_);
2690b57cec5SDimitry Andric        return *this;
2700b57cec5SDimitry Andric    }
2710b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
2720b57cec5SDimitry Andric
2730b57cec5SDimitry Andric    virtual ~istrstream();
2740b57cec5SDimitry Andric
2750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2760b57cec5SDimitry Andric    void swap(istrstream& __rhs)
2770b57cec5SDimitry Andric    {
2780b57cec5SDimitry Andric        istream::swap(__rhs);
2790b57cec5SDimitry Andric        __sb_.swap(__rhs.__sb_);
2800b57cec5SDimitry Andric    }
2810b57cec5SDimitry Andric
2820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2830b57cec5SDimitry Andric    strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
2840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2850b57cec5SDimitry Andric    char *str() {return __sb_.str();}
2860b57cec5SDimitry Andric
2870b57cec5SDimitry Andricprivate:
2880b57cec5SDimitry Andric    strstreambuf __sb_;
2890b57cec5SDimitry Andric};
2900b57cec5SDimitry Andric
2910b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS ostrstream
2920b57cec5SDimitry Andric    : public ostream
2930b57cec5SDimitry Andric{
2940b57cec5SDimitry Andricpublic:
2950b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2960b57cec5SDimitry Andric    ostrstream()
2970b57cec5SDimitry Andric        : ostream(&__sb_) {}
2980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2990b57cec5SDimitry Andric    ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
3000b57cec5SDimitry Andric        : ostream(&__sb_),
301*e8d8bef9SDimitry Andric          __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
3020b57cec5SDimitry Andric        {}
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
3050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3060b57cec5SDimitry Andric    ostrstream(ostrstream&& __rhs)
3070b57cec5SDimitry Andric        : ostream(_VSTD::move(__rhs)),
3080b57cec5SDimitry Andric          __sb_(_VSTD::move(__rhs.__sb_))
3090b57cec5SDimitry Andric    {
3100b57cec5SDimitry Andric        ostream::set_rdbuf(&__sb_);
3110b57cec5SDimitry Andric    }
3120b57cec5SDimitry Andric
3130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3140b57cec5SDimitry Andric    ostrstream& operator=(ostrstream&& __rhs)
3150b57cec5SDimitry Andric    {
3160b57cec5SDimitry Andric        ostream::operator=(_VSTD::move(__rhs));
3170b57cec5SDimitry Andric        __sb_ = _VSTD::move(__rhs.__sb_);
3180b57cec5SDimitry Andric        return *this;
3190b57cec5SDimitry Andric    }
3200b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
3210b57cec5SDimitry Andric
3220b57cec5SDimitry Andric    virtual ~ostrstream();
3230b57cec5SDimitry Andric
3240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3250b57cec5SDimitry Andric    void swap(ostrstream& __rhs)
3260b57cec5SDimitry Andric    {
3270b57cec5SDimitry Andric        ostream::swap(__rhs);
3280b57cec5SDimitry Andric        __sb_.swap(__rhs.__sb_);
3290b57cec5SDimitry Andric    }
3300b57cec5SDimitry Andric
3310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3320b57cec5SDimitry Andric    strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
3330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3340b57cec5SDimitry Andric    void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
3350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3360b57cec5SDimitry Andric    char* str()         {return __sb_.str();}
3370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3380b57cec5SDimitry Andric    int pcount() const  {return __sb_.pcount();}
3390b57cec5SDimitry Andric
3400b57cec5SDimitry Andricprivate:
3410b57cec5SDimitry Andric    strstreambuf __sb_; // exposition only
3420b57cec5SDimitry Andric};
3430b57cec5SDimitry Andric
3440b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS strstream
3450b57cec5SDimitry Andric    : public iostream
3460b57cec5SDimitry Andric{
3470b57cec5SDimitry Andricpublic:
3480b57cec5SDimitry Andric    // Types
3490b57cec5SDimitry Andric    typedef char                        char_type;
3500b57cec5SDimitry Andric    typedef char_traits<char>::int_type int_type;
3510b57cec5SDimitry Andric    typedef char_traits<char>::pos_type pos_type;
3520b57cec5SDimitry Andric    typedef char_traits<char>::off_type off_type;
3530b57cec5SDimitry Andric
3540b57cec5SDimitry Andric    // constructors/destructor
3550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3560b57cec5SDimitry Andric    strstream()
3570b57cec5SDimitry Andric        : iostream(&__sb_) {}
3580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3590b57cec5SDimitry Andric    strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
3600b57cec5SDimitry Andric        : iostream(&__sb_),
361*e8d8bef9SDimitry Andric          __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
3620b57cec5SDimitry Andric        {}
3630b57cec5SDimitry Andric
3640b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
3650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3660b57cec5SDimitry Andric    strstream(strstream&& __rhs)
3670b57cec5SDimitry Andric        : iostream(_VSTD::move(__rhs)),
3680b57cec5SDimitry Andric          __sb_(_VSTD::move(__rhs.__sb_))
3690b57cec5SDimitry Andric    {
3700b57cec5SDimitry Andric        iostream::set_rdbuf(&__sb_);
3710b57cec5SDimitry Andric    }
3720b57cec5SDimitry Andric
3730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3740b57cec5SDimitry Andric    strstream& operator=(strstream&& __rhs)
3750b57cec5SDimitry Andric    {
3760b57cec5SDimitry Andric        iostream::operator=(_VSTD::move(__rhs));
3770b57cec5SDimitry Andric        __sb_ = _VSTD::move(__rhs.__sb_);
3780b57cec5SDimitry Andric        return *this;
3790b57cec5SDimitry Andric    }
3800b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andric    virtual ~strstream();
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3850b57cec5SDimitry Andric    void swap(strstream& __rhs)
3860b57cec5SDimitry Andric    {
3870b57cec5SDimitry Andric        iostream::swap(__rhs);
3880b57cec5SDimitry Andric        __sb_.swap(__rhs.__sb_);
3890b57cec5SDimitry Andric    }
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andric    // Members:
3920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3930b57cec5SDimitry Andric    strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
3940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3950b57cec5SDimitry Andric    void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
3960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3970b57cec5SDimitry Andric    int pcount() const {return __sb_.pcount();}
3980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3990b57cec5SDimitry Andric    char* str()        {return __sb_.str();}
4000b57cec5SDimitry Andric
4010b57cec5SDimitry Andricprivate:
4020b57cec5SDimitry Andric    strstreambuf __sb_; // exposition only
4030b57cec5SDimitry Andric};
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
4060b57cec5SDimitry Andric
4070b57cec5SDimitry Andric#endif  // _LIBCPP_STRSTREAM
408