2 //===--------------------------- strstream --------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_STRSTREAM
12 #define _LIBCPP_STRSTREAM
18 : public basic_streambuf<char>
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);
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);
31 strstreambuf(strstreambuf&& rhs);
32 strstreambuf& operator=(strstreambuf&& rhs);
34 virtual ~strstreambuf();
36 void swap(strstreambuf& rhs);
38 void freeze(bool freezefl = true);
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);
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
65 : public basic_istream<char>
68 explicit istrstream(const char* s);
69 explicit istrstream(char* s);
70 istrstream(const char* s, streamsize n);
71 istrstream(char* s, streamsize n);
73 virtual ~istrstream();
75 strstreambuf* rdbuf() const;
79 strstreambuf sb; // exposition only
83 : public basic_ostream<char>
87 ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
89 virtual ~ostrstream();
91 strstreambuf* rdbuf() const;
92 void freeze(bool freezefl = true);
97 strstreambuf sb; // exposition only
101 : public basic_iostream<char>
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;
110 // constructors/destructor
112 strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
114 virtual ~strstream();
117 strstreambuf* rdbuf() const;
118 void freeze(bool freezefl = true);
123 strstreambuf sb; // exposition only
134 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
135 #pragma GCC system_header
138 _LIBCPP_BEGIN_NAMESPACE_STD
140 class _LIBCPP_TYPE_VIS strstreambuf
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);
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);
154 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
155 _LIBCPP_INLINE_VISIBILITY
156 strstreambuf(strstreambuf&& __rhs);
157 _LIBCPP_INLINE_VISIBILITY
158 strstreambuf& operator=(strstreambuf&& __rhs);
159 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
161 virtual ~strstreambuf();
163 void swap(strstreambuf& __rhs);
165 void freeze(bool __freezefl = true);
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);
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;
186 __mode_type __strmode_;
187 streamsize __alsize_;
188 void* (*__palloc_)(size_t);
189 void (*__pfree_)(void*);
191 void __init(char* __gnext, streamsize __n, char* __pbeg);
194 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
196 inline _LIBCPP_INLINE_VISIBILITY
197 strstreambuf::strstreambuf(strstreambuf&& __rhs)
199 __strmode_(__rhs.__strmode_),
200 __alsize_(__rhs.__alsize_),
201 __palloc_(__rhs.__palloc_),
202 __pfree_(__rhs.__pfree_)
204 __rhs.setg(nullptr, nullptr, nullptr);
205 __rhs.setp(nullptr, nullptr);
208 inline _LIBCPP_INLINE_VISIBILITY
210 strstreambuf::operator=(strstreambuf&& __rhs)
212 if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
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);
229 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
231 class _LIBCPP_TYPE_VIS istrstream
235 _LIBCPP_INLINE_VISIBILITY
236 explicit istrstream(const char* __s)
237 : istream(&__sb_), __sb_(__s, 0) {}
238 _LIBCPP_INLINE_VISIBILITY
239 explicit istrstream(char* __s)
240 : istream(&__sb_), __sb_(__s, 0) {}
241 _LIBCPP_INLINE_VISIBILITY
242 istrstream(const char* __s, streamsize __n)
243 : istream(&__sb_), __sb_(__s, __n) {}
244 _LIBCPP_INLINE_VISIBILITY
245 istrstream(char* __s, streamsize __n)
246 : istream(&__sb_), __sb_(__s, __n) {}
248 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
249 _LIBCPP_INLINE_VISIBILITY
250 istrstream(istrstream&& __rhs)
251 : istream(_VSTD::move(__rhs)),
252 __sb_(_VSTD::move(__rhs.__sb_))
254 istream::set_rdbuf(&__sb_);
257 _LIBCPP_INLINE_VISIBILITY
258 istrstream& operator=(istrstream&& __rhs)
260 istream::operator=(_VSTD::move(__rhs));
261 __sb_ = _VSTD::move(__rhs.__sb_);
264 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
266 virtual ~istrstream();
268 _LIBCPP_INLINE_VISIBILITY
269 void swap(istrstream& __rhs)
271 istream::swap(__rhs);
272 __sb_.swap(__rhs.__sb_);
275 _LIBCPP_INLINE_VISIBILITY
276 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
277 _LIBCPP_INLINE_VISIBILITY
278 char *str() {return __sb_.str();}
284 class _LIBCPP_TYPE_VIS ostrstream
288 _LIBCPP_INLINE_VISIBILITY
291 _LIBCPP_INLINE_VISIBILITY
292 ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
294 __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))
297 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
298 _LIBCPP_INLINE_VISIBILITY
299 ostrstream(ostrstream&& __rhs)
300 : ostream(_VSTD::move(__rhs)),
301 __sb_(_VSTD::move(__rhs.__sb_))
303 ostream::set_rdbuf(&__sb_);
306 _LIBCPP_INLINE_VISIBILITY
307 ostrstream& operator=(ostrstream&& __rhs)
309 ostream::operator=(_VSTD::move(__rhs));
310 __sb_ = _VSTD::move(__rhs.__sb_);
313 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
315 virtual ~ostrstream();
317 _LIBCPP_INLINE_VISIBILITY
318 void swap(ostrstream& __rhs)
320 ostream::swap(__rhs);
321 __sb_.swap(__rhs.__sb_);
324 _LIBCPP_INLINE_VISIBILITY
325 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
326 _LIBCPP_INLINE_VISIBILITY
327 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
328 _LIBCPP_INLINE_VISIBILITY
329 char* str() {return __sb_.str();}
330 _LIBCPP_INLINE_VISIBILITY
331 int pcount() const {return __sb_.pcount();}
334 strstreambuf __sb_; // exposition only
337 class _LIBCPP_TYPE_VIS strstream
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;
347 // constructors/destructor
348 _LIBCPP_INLINE_VISIBILITY
350 : iostream(&__sb_) {}
351 _LIBCPP_INLINE_VISIBILITY
352 strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
354 __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))
357 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
358 _LIBCPP_INLINE_VISIBILITY
359 strstream(strstream&& __rhs)
360 : iostream(_VSTD::move(__rhs)),
361 __sb_(_VSTD::move(__rhs.__sb_))
363 iostream::set_rdbuf(&__sb_);
366 _LIBCPP_INLINE_VISIBILITY
367 strstream& operator=(strstream&& __rhs)
369 iostream::operator=(_VSTD::move(__rhs));
370 __sb_ = _VSTD::move(__rhs.__sb_);
373 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
375 virtual ~strstream();
377 _LIBCPP_INLINE_VISIBILITY
378 void swap(strstream& __rhs)
380 iostream::swap(__rhs);
381 __sb_.swap(__rhs.__sb_);
385 _LIBCPP_INLINE_VISIBILITY
386 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
387 _LIBCPP_INLINE_VISIBILITY
388 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
389 _LIBCPP_INLINE_VISIBILITY
390 int pcount() const {return __sb_.pcount();}
391 _LIBCPP_INLINE_VISIBILITY
392 char* str() {return __sb_.str();}
395 strstreambuf __sb_; // exposition only
398 _LIBCPP_END_NAMESPACE_STD
400 #endif // _LIBCPP_STRSTREAM