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