| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- | 
|  | 2 | //===--------------------------- strstream --------------------------------===// | 
|  | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 5 | // | 
| Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 | [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 | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 8 | // | 
|  | 9 | //===----------------------------------------------------------------------===// | 
|  | 10 |  | 
|  | 11 | #ifndef _LIBCPP_STRSTREAM | 
|  | 12 | #define _LIBCPP_STRSTREAM | 
|  | 13 |  | 
|  | 14 | /* | 
|  | 15 | strstream synopsis | 
|  | 16 |  | 
|  | 17 | class strstreambuf | 
|  | 18 | : public basic_streambuf<char> | 
|  | 19 | { | 
|  | 20 | public: | 
|  | 21 | explicit strstreambuf(streamsize alsize_arg = 0); | 
|  | 22 | strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*)); | 
|  | 23 | strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = 0); | 
|  | 24 | strstreambuf(const char* gnext_arg, streamsize n); | 
|  | 25 |  | 
|  | 26 | strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = 0); | 
|  | 27 | strstreambuf(const signed char* gnext_arg, streamsize n); | 
|  | 28 | strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = 0); | 
|  | 29 | strstreambuf(const unsigned char* gnext_arg, streamsize n); | 
|  | 30 |  | 
|  | 31 | strstreambuf(strstreambuf&& rhs); | 
|  | 32 | strstreambuf& operator=(strstreambuf&& rhs); | 
|  | 33 |  | 
|  | 34 | virtual ~strstreambuf(); | 
|  | 35 |  | 
|  | 36 | void swap(strstreambuf& rhs); | 
|  | 37 |  | 
|  | 38 | void freeze(bool freezefl = true); | 
|  | 39 | char* str(); | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 40 | int pcount() const; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 41 |  | 
|  | 42 | protected: | 
|  | 43 | virtual int_type overflow (int_type c = EOF); | 
|  | 44 | virtual int_type pbackfail(int_type c = EOF); | 
|  | 45 | virtual int_type underflow(); | 
|  | 46 | virtual pos_type seekoff(off_type off, ios_base::seekdir way, | 
|  | 47 | ios_base::openmode which = ios_base::in | ios_base::out); | 
|  | 48 | virtual pos_type seekpos(pos_type sp, | 
|  | 49 | ios_base::openmode which = ios_base::in | ios_base::out); | 
|  | 50 | virtual streambuf* setbuf(char* s, streamsize n); | 
|  | 51 |  | 
|  | 52 | private: | 
|  | 53 | typedef T1 strstate; // exposition only | 
|  | 54 | static const strstate allocated; // exposition only | 
|  | 55 | static const strstate constant; // exposition only | 
|  | 56 | static const strstate dynamic; // exposition only | 
|  | 57 | static const strstate frozen; // exposition only | 
|  | 58 | strstate strmode; // exposition only | 
|  | 59 | streamsize alsize; // exposition only | 
|  | 60 | void* (*palloc)(size_t); // exposition only | 
|  | 61 | void (*pfree)(void*); // exposition only | 
|  | 62 | }; | 
|  | 63 |  | 
|  | 64 | class istrstream | 
|  | 65 | : public basic_istream<char> | 
|  | 66 | { | 
|  | 67 | public: | 
|  | 68 | explicit istrstream(const char* s); | 
|  | 69 | explicit istrstream(char* s); | 
|  | 70 | istrstream(const char* s, streamsize n); | 
|  | 71 | istrstream(char* s, streamsize n); | 
|  | 72 |  | 
|  | 73 | virtual ~istrstream(); | 
|  | 74 |  | 
|  | 75 | strstreambuf* rdbuf() const; | 
|  | 76 | char *str(); | 
|  | 77 |  | 
|  | 78 | private: | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 79 | strstreambuf sb; // exposition only | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 80 | }; | 
|  | 81 |  | 
|  | 82 | class ostrstream | 
|  | 83 | : public basic_ostream<char> | 
|  | 84 | { | 
|  | 85 | public: | 
|  | 86 | ostrstream(); | 
|  | 87 | ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out); | 
|  | 88 |  | 
|  | 89 | virtual ~ostrstream(); | 
|  | 90 |  | 
|  | 91 | strstreambuf* rdbuf() const; | 
|  | 92 | void freeze(bool freezefl = true); | 
|  | 93 | char* str(); | 
|  | 94 | int pcount() const; | 
|  | 95 |  | 
|  | 96 | private: | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 97 | strstreambuf sb; // exposition only | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 98 | }; | 
|  | 99 |  | 
|  | 100 | class strstream | 
|  | 101 | : public basic_iostream<char> | 
|  | 102 | { | 
|  | 103 | public: | 
|  | 104 | // Types | 
|  | 105 | typedef char char_type; | 
|  | 106 | typedef char_traits<char>::int_type int_type; | 
|  | 107 | typedef char_traits<char>::pos_type pos_type; | 
|  | 108 | typedef char_traits<char>::off_type off_type; | 
|  | 109 |  | 
|  | 110 | // constructors/destructor | 
|  | 111 | strstream(); | 
|  | 112 | strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out); | 
|  | 113 |  | 
|  | 114 | virtual ~strstream(); | 
|  | 115 |  | 
|  | 116 | // Members: | 
|  | 117 | strstreambuf* rdbuf() const; | 
|  | 118 | void freeze(bool freezefl = true); | 
|  | 119 | int pcount() const; | 
|  | 120 | char* str(); | 
|  | 121 |  | 
|  | 122 | private: | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 123 | strstreambuf sb; // exposition only | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 124 | }; | 
|  | 125 |  | 
|  | 126 | } // std | 
|  | 127 |  | 
|  | 128 | */ | 
|  | 129 |  | 
|  | 130 | #include <__config> | 
|  | 131 | #include <ostream> | 
|  | 132 | #include <istream> | 
|  | 133 |  | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 | [diff] [blame] | 134 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 135 | #pragma GCC system_header | 
| Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 | [diff] [blame] | 136 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 137 |  | 
|  | 138 | _LIBCPP_BEGIN_NAMESPACE_STD | 
|  | 139 |  | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 | [diff] [blame] | 140 | class _LIBCPP_TYPE_VIS strstreambuf | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 141 | : public streambuf | 
|  | 142 | { | 
|  | 143 | public: | 
|  | 144 | explicit strstreambuf(streamsize __alsize = 0); | 
|  | 145 | strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*)); | 
|  | 146 | strstreambuf(char* __gnext, streamsize __n, char* __pbeg = 0); | 
|  | 147 | strstreambuf(const char* __gnext, streamsize __n); | 
|  | 148 |  | 
|  | 149 | strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = 0); | 
|  | 150 | strstreambuf(const signed char* __gnext, streamsize __n); | 
|  | 151 | strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = 0); | 
|  | 152 | strstreambuf(const unsigned char* __gnext, streamsize __n); | 
|  | 153 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 154 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 | [diff] [blame] | 155 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 156 | strstreambuf(strstreambuf&& __rhs); | 
| Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 | [diff] [blame] | 157 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 158 | strstreambuf& operator=(strstreambuf&& __rhs); | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 159 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 160 |  | 
|  | 161 | virtual ~strstreambuf(); | 
|  | 162 |  | 
|  | 163 | void swap(strstreambuf& __rhs); | 
|  | 164 |  | 
|  | 165 | void freeze(bool __freezefl = true); | 
|  | 166 | char* str(); | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 167 | int pcount() const; | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 168 |  | 
|  | 169 | protected: | 
|  | 170 | virtual int_type overflow (int_type __c = EOF); | 
|  | 171 | virtual int_type pbackfail(int_type __c = EOF); | 
|  | 172 | virtual int_type underflow(); | 
|  | 173 | virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, | 
|  | 174 | ios_base::openmode __which = ios_base::in | ios_base::out); | 
|  | 175 | virtual pos_type seekpos(pos_type __sp, | 
|  | 176 | ios_base::openmode __which = ios_base::in | ios_base::out); | 
|  | 177 |  | 
|  | 178 | private: | 
|  | 179 | typedef unsigned __mode_type; | 
|  | 180 | static const __mode_type __allocated = 0x01; | 
|  | 181 | static const __mode_type __constant = 0x02; | 
|  | 182 | static const __mode_type __dynamic = 0x04; | 
|  | 183 | static const __mode_type __frozen = 0x08; | 
|  | 184 | static const streamsize __default_alsize = 4096; | 
|  | 185 |  | 
|  | 186 | __mode_type __strmode_; | 
|  | 187 | streamsize __alsize_; | 
|  | 188 | void* (*__palloc_)(size_t); | 
|  | 189 | void (*__pfree_)(void*); | 
|  | 190 |  | 
|  | 191 | void __init(char* __gnext, streamsize __n, char* __pbeg); | 
|  | 192 | }; | 
|  | 193 |  | 
| Howard Hinnant | ac6de54 | 2011-07-07 21:03:52 | [diff] [blame] | 194 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
|  | 195 |  | 
|  | 196 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 197 | strstreambuf::strstreambuf(strstreambuf&& __rhs) | 
|  | 198 | : streambuf(__rhs), | 
|  | 199 | __strmode_(__rhs.__strmode_), | 
|  | 200 | __alsize_(__rhs.__alsize_), | 
|  | 201 | __palloc_(__rhs.__palloc_), | 
|  | 202 | __pfree_(__rhs.__pfree_) | 
|  | 203 | { | 
|  | 204 | __rhs.setg(nullptr, nullptr, nullptr); | 
|  | 205 | __rhs.setp(nullptr, nullptr); | 
|  | 206 | } | 
|  | 207 |  | 
|  | 208 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 209 | strstreambuf& | 
|  | 210 | strstreambuf::operator=(strstreambuf&& __rhs) | 
|  | 211 | { | 
|  | 212 | if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) | 
|  | 213 | { | 
|  | 214 | if (__pfree_) | 
|  | 215 | __pfree_(eback()); | 
|  | 216 | else | 
|  | 217 | delete [] eback(); | 
|  | 218 | } | 
|  | 219 | streambuf::operator=(__rhs); | 
|  | 220 | __strmode_ = __rhs.__strmode_; | 
|  | 221 | __alsize_ = __rhs.__alsize_; | 
|  | 222 | __palloc_ = __rhs.__palloc_; | 
|  | 223 | __pfree_ = __rhs.__pfree_; | 
|  | 224 | __rhs.setg(nullptr, nullptr, nullptr); | 
|  | 225 | __rhs.setp(nullptr, nullptr); | 
|  | 226 | return *this; | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
|  | 230 |  | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 | [diff] [blame] | 231 | class _LIBCPP_TYPE_VIS istrstream | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 232 | : public istream | 
|  | 233 | { | 
|  | 234 | public: | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 235 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 236 | explicit istrstream(const char* __s) | 
|  | 237 | : istream(&__sb_), __sb_(__s, 0) {} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 238 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 239 | explicit istrstream(char* __s) | 
|  | 240 | : istream(&__sb_), __sb_(__s, 0) {} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 241 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 242 | istrstream(const char* __s, streamsize __n) | 
|  | 243 | : istream(&__sb_), __sb_(__s, __n) {} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 244 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 245 | istrstream(char* __s, streamsize __n) | 
|  | 246 | : istream(&__sb_), __sb_(__s, __n) {} | 
|  | 247 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 248 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 249 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 250 | istrstream(istrstream&& __rhs) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 251 | : istream(_VSTD::move(__rhs)), | 
|  | 252 | __sb_(_VSTD::move(__rhs.__sb_)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 253 | { | 
|  | 254 | istream::set_rdbuf(&__sb_); | 
|  | 255 | } | 
|  | 256 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 257 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 258 | istrstream& operator=(istrstream&& __rhs) | 
|  | 259 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 260 | istream::operator=(_VSTD::move(__rhs)); | 
|  | 261 | __sb_ = _VSTD::move(__rhs.__sb_); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 262 | return *this; | 
|  | 263 | } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 264 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 265 |  | 
|  | 266 | virtual ~istrstream(); | 
|  | 267 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 268 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 269 | void swap(istrstream& __rhs) | 
|  | 270 | { | 
|  | 271 | istream::swap(__rhs); | 
|  | 272 | __sb_.swap(__rhs.__sb_); | 
|  | 273 | } | 
|  | 274 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 275 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 276 | strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 277 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 278 | char *str() {return __sb_.str();} | 
|  | 279 |  | 
|  | 280 | private: | 
|  | 281 | strstreambuf __sb_; | 
|  | 282 | }; | 
|  | 283 |  | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 | [diff] [blame] | 284 | class _LIBCPP_TYPE_VIS ostrstream | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 285 | : public ostream | 
|  | 286 | { | 
|  | 287 | public: | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 288 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 289 | ostrstream() | 
|  | 290 | : ostream(&__sb_) {} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 291 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 292 | ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out) | 
|  | 293 | : ostream(&__sb_), | 
|  | 294 | __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) | 
|  | 295 | {} | 
|  | 296 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 297 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 298 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 299 | ostrstream(ostrstream&& __rhs) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 300 | : ostream(_VSTD::move(__rhs)), | 
|  | 301 | __sb_(_VSTD::move(__rhs.__sb_)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 302 | { | 
|  | 303 | ostream::set_rdbuf(&__sb_); | 
|  | 304 | } | 
|  | 305 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 306 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 307 | ostrstream& operator=(ostrstream&& __rhs) | 
|  | 308 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 309 | ostream::operator=(_VSTD::move(__rhs)); | 
|  | 310 | __sb_ = _VSTD::move(__rhs.__sb_); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 311 | return *this; | 
|  | 312 | } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 313 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 314 |  | 
|  | 315 | virtual ~ostrstream(); | 
|  | 316 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 317 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 318 | void swap(ostrstream& __rhs) | 
|  | 319 | { | 
|  | 320 | ostream::swap(__rhs); | 
|  | 321 | __sb_.swap(__rhs.__sb_); | 
|  | 322 | } | 
|  | 323 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 324 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 325 | strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 326 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 327 | void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 328 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 329 | char* str() {return __sb_.str();} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 330 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 331 | int pcount() const {return __sb_.pcount();} | 
|  | 332 |  | 
|  | 333 | private: | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 334 | strstreambuf __sb_; // exposition only | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 335 | }; | 
|  | 336 |  | 
| Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 | [diff] [blame] | 337 | class _LIBCPP_TYPE_VIS strstream | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 338 | : public iostream | 
|  | 339 | { | 
|  | 340 | public: | 
|  | 341 | // Types | 
|  | 342 | typedef char char_type; | 
|  | 343 | typedef char_traits<char>::int_type int_type; | 
|  | 344 | typedef char_traits<char>::pos_type pos_type; | 
|  | 345 | typedef char_traits<char>::off_type off_type; | 
|  | 346 |  | 
|  | 347 | // constructors/destructor | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 348 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 349 | strstream() | 
|  | 350 | : iostream(&__sb_) {} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 351 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 352 | strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out) | 
|  | 353 | : iostream(&__sb_), | 
|  | 354 | __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) | 
|  | 355 | {} | 
|  | 356 |  | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 357 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 358 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 359 | strstream(strstream&& __rhs) | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 360 | : iostream(_VSTD::move(__rhs)), | 
|  | 361 | __sb_(_VSTD::move(__rhs.__sb_)) | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 362 | { | 
|  | 363 | iostream::set_rdbuf(&__sb_); | 
|  | 364 | } | 
|  | 365 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 366 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 367 | strstream& operator=(strstream&& __rhs) | 
|  | 368 | { | 
| Howard Hinnant | 0949eed | 2011-06-30 21:18:19 | [diff] [blame] | 369 | iostream::operator=(_VSTD::move(__rhs)); | 
|  | 370 | __sb_ = _VSTD::move(__rhs.__sb_); | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 371 | return *this; | 
|  | 372 | } | 
| Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 | [diff] [blame] | 373 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 374 |  | 
|  | 375 | virtual ~strstream(); | 
|  | 376 |  | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 377 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 378 | void swap(strstream& __rhs) | 
|  | 379 | { | 
|  | 380 | iostream::swap(__rhs); | 
|  | 381 | __sb_.swap(__rhs.__sb_); | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | // Members: | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 385 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 386 | strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 387 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 388 | void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 389 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 390 | int pcount() const {return __sb_.pcount();} | 
| Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 | [diff] [blame] | 391 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 392 | char* str() {return __sb_.str();} | 
|  | 393 |  | 
|  | 394 | private: | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 | [diff] [blame] | 395 | strstreambuf __sb_; // exposition only | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 | [diff] [blame] | 396 | }; | 
|  | 397 |  | 
|  | 398 | _LIBCPP_END_NAMESPACE_STD | 
|  | 399 |  | 
|  | 400 | #endif // _LIBCPP_STRSTREAM |