Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- strstream --------------------------------===// |
| 3 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [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 | c51e102 | 2010-05-11 19:42:16 +0000 | [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 | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 40 | int pcount() const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [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 | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 79 | strstreambuf sb; // exposition only |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [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 | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 97 | strstreambuf sb; // exposition only |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [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 | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 123 | strstreambuf sb; // exposition only |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // std |
| 127 | |
| 128 | */ |
| 129 | |
| 130 | #include <__config> |
| 131 | #include <ostream> |
| 132 | #include <istream> |
| 133 | |
| 134 | #pragma GCC system_header |
| 135 | |
| 136 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 137 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 138 | class _LIBCPP_VISIBLE strstreambuf |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | : public streambuf |
| 140 | { |
| 141 | public: |
| 142 | explicit strstreambuf(streamsize __alsize = 0); |
| 143 | strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*)); |
| 144 | strstreambuf(char* __gnext, streamsize __n, char* __pbeg = 0); |
| 145 | strstreambuf(const char* __gnext, streamsize __n); |
| 146 | |
| 147 | strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = 0); |
| 148 | strstreambuf(const signed char* __gnext, streamsize __n); |
| 149 | strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = 0); |
| 150 | strstreambuf(const unsigned char* __gnext, streamsize __n); |
| 151 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 152 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 0dcdf02 | 2011-07-07 21:03:52 +0000 | [diff] [blame] | 153 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 154 | strstreambuf(strstreambuf&& __rhs); |
Howard Hinnant | 0dcdf02 | 2011-07-07 21:03:52 +0000 | [diff] [blame] | 155 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | strstreambuf& operator=(strstreambuf&& __rhs); |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 157 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 158 | |
| 159 | virtual ~strstreambuf(); |
| 160 | |
| 161 | void swap(strstreambuf& __rhs); |
| 162 | |
| 163 | void freeze(bool __freezefl = true); |
| 164 | char* str(); |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 165 | int pcount() const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 | |
| 167 | protected: |
| 168 | virtual int_type overflow (int_type __c = EOF); |
| 169 | virtual int_type pbackfail(int_type __c = EOF); |
| 170 | virtual int_type underflow(); |
| 171 | virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, |
| 172 | ios_base::openmode __which = ios_base::in | ios_base::out); |
| 173 | virtual pos_type seekpos(pos_type __sp, |
| 174 | ios_base::openmode __which = ios_base::in | ios_base::out); |
| 175 | |
| 176 | private: |
| 177 | typedef unsigned __mode_type; |
| 178 | static const __mode_type __allocated = 0x01; |
| 179 | static const __mode_type __constant = 0x02; |
| 180 | static const __mode_type __dynamic = 0x04; |
| 181 | static const __mode_type __frozen = 0x08; |
| 182 | static const streamsize __default_alsize = 4096; |
| 183 | |
| 184 | __mode_type __strmode_; |
| 185 | streamsize __alsize_; |
| 186 | void* (*__palloc_)(size_t); |
| 187 | void (*__pfree_)(void*); |
| 188 | |
| 189 | void __init(char* __gnext, streamsize __n, char* __pbeg); |
| 190 | }; |
| 191 | |
Howard Hinnant | 0dcdf02 | 2011-07-07 21:03:52 +0000 | [diff] [blame] | 192 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 193 | |
| 194 | inline _LIBCPP_INLINE_VISIBILITY |
| 195 | strstreambuf::strstreambuf(strstreambuf&& __rhs) |
| 196 | : streambuf(__rhs), |
| 197 | __strmode_(__rhs.__strmode_), |
| 198 | __alsize_(__rhs.__alsize_), |
| 199 | __palloc_(__rhs.__palloc_), |
| 200 | __pfree_(__rhs.__pfree_) |
| 201 | { |
| 202 | __rhs.setg(nullptr, nullptr, nullptr); |
| 203 | __rhs.setp(nullptr, nullptr); |
| 204 | } |
| 205 | |
| 206 | inline _LIBCPP_INLINE_VISIBILITY |
| 207 | strstreambuf& |
| 208 | strstreambuf::operator=(strstreambuf&& __rhs) |
| 209 | { |
| 210 | if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) |
| 211 | { |
| 212 | if (__pfree_) |
| 213 | __pfree_(eback()); |
| 214 | else |
| 215 | delete [] eback(); |
| 216 | } |
| 217 | streambuf::operator=(__rhs); |
| 218 | __strmode_ = __rhs.__strmode_; |
| 219 | __alsize_ = __rhs.__alsize_; |
| 220 | __palloc_ = __rhs.__palloc_; |
| 221 | __pfree_ = __rhs.__pfree_; |
| 222 | __rhs.setg(nullptr, nullptr, nullptr); |
| 223 | __rhs.setp(nullptr, nullptr); |
| 224 | return *this; |
| 225 | } |
| 226 | |
| 227 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 228 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 229 | class _LIBCPP_VISIBLE istrstream |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 230 | : public istream |
| 231 | { |
| 232 | public: |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 234 | explicit istrstream(const char* __s) |
| 235 | : istream(&__sb_), __sb_(__s, 0) {} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 236 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 237 | explicit istrstream(char* __s) |
| 238 | : istream(&__sb_), __sb_(__s, 0) {} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 239 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 240 | istrstream(const char* __s, streamsize __n) |
| 241 | : istream(&__sb_), __sb_(__s, __n) {} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 242 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | istrstream(char* __s, streamsize __n) |
| 244 | : istream(&__sb_), __sb_(__s, __n) {} |
| 245 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 246 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 248 | istrstream(istrstream&& __rhs) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 249 | : istream(_VSTD::move(__rhs)), |
| 250 | __sb_(_VSTD::move(__rhs.__sb_)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 | { |
| 252 | istream::set_rdbuf(&__sb_); |
| 253 | } |
| 254 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 255 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 256 | istrstream& operator=(istrstream&& __rhs) |
| 257 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 258 | istream::operator=(_VSTD::move(__rhs)); |
| 259 | __sb_ = _VSTD::move(__rhs.__sb_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 260 | return *this; |
| 261 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 262 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | |
| 264 | virtual ~istrstream(); |
| 265 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 266 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 267 | void swap(istrstream& __rhs) |
| 268 | { |
| 269 | istream::swap(__rhs); |
| 270 | __sb_.swap(__rhs.__sb_); |
| 271 | } |
| 272 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 273 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 275 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 276 | char *str() {return __sb_.str();} |
| 277 | |
| 278 | private: |
| 279 | strstreambuf __sb_; |
| 280 | }; |
| 281 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 282 | class _LIBCPP_VISIBLE ostrstream |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 283 | : public ostream |
| 284 | { |
| 285 | public: |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 286 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | ostrstream() |
| 288 | : ostream(&__sb_) {} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 289 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out) |
| 291 | : ostream(&__sb_), |
| 292 | __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) |
| 293 | {} |
| 294 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 295 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | ostrstream(ostrstream&& __rhs) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 298 | : ostream(_VSTD::move(__rhs)), |
| 299 | __sb_(_VSTD::move(__rhs.__sb_)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 300 | { |
| 301 | ostream::set_rdbuf(&__sb_); |
| 302 | } |
| 303 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 304 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 305 | ostrstream& operator=(ostrstream&& __rhs) |
| 306 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 307 | ostream::operator=(_VSTD::move(__rhs)); |
| 308 | __sb_ = _VSTD::move(__rhs.__sb_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | return *this; |
| 310 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 311 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | |
| 313 | virtual ~ostrstream(); |
| 314 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | void swap(ostrstream& __rhs) |
| 317 | { |
| 318 | ostream::swap(__rhs); |
| 319 | __sb_.swap(__rhs.__sb_); |
| 320 | } |
| 321 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 322 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 323 | strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 325 | void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 326 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 327 | char* str() {return __sb_.str();} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 328 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 329 | int pcount() const {return __sb_.pcount();} |
| 330 | |
| 331 | private: |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 332 | strstreambuf __sb_; // exposition only |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 335 | class _LIBCPP_VISIBLE strstream |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 336 | : public iostream |
| 337 | { |
| 338 | public: |
| 339 | // Types |
| 340 | typedef char char_type; |
| 341 | typedef char_traits<char>::int_type int_type; |
| 342 | typedef char_traits<char>::pos_type pos_type; |
| 343 | typedef char_traits<char>::off_type off_type; |
| 344 | |
| 345 | // constructors/destructor |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | strstream() |
| 348 | : iostream(&__sb_) {} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 349 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out) |
| 351 | : iostream(&__sb_), |
| 352 | __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0)) |
| 353 | {} |
| 354 | |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 355 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 357 | strstream(strstream&& __rhs) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 358 | : iostream(_VSTD::move(__rhs)), |
| 359 | __sb_(_VSTD::move(__rhs.__sb_)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | { |
| 361 | iostream::set_rdbuf(&__sb_); |
| 362 | } |
| 363 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | strstream& operator=(strstream&& __rhs) |
| 366 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 367 | iostream::operator=(_VSTD::move(__rhs)); |
| 368 | __sb_ = _VSTD::move(__rhs.__sb_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | return *this; |
| 370 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 371 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 | |
| 373 | virtual ~strstream(); |
| 374 | |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 375 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 376 | void swap(strstream& __rhs) |
| 377 | { |
| 378 | iostream::swap(__rhs); |
| 379 | __sb_.swap(__rhs.__sb_); |
| 380 | } |
| 381 | |
| 382 | // Members: |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 383 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 385 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 387 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | int pcount() const {return __sb_.pcount();} |
Howard Hinnant | 186dca8 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | char* str() {return __sb_.str();} |
| 391 | |
| 392 | private: |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 393 | strstreambuf __sb_; // exposition only |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | }; |
| 395 | |
| 396 | _LIBCPP_END_NAMESPACE_STD |
| 397 | |
| 398 | #endif // _LIBCPP_STRSTREAM |