2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_STRSTREAM
11 #define _LIBCPP_STRSTREAM
17 : public basic_streambuf<char>
20 explicit strstreambuf(streamsize alsize_arg = 0); // before C++20
21 strstreambuf() : strstreambuf(0) {} // C++20
22 explicit strstreambuf(streamsize alsize_arg); // C++20
24 strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
25 strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
26 strstreambuf(const char* gnext_arg, streamsize n);
28 strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = nullptr);
29 strstreambuf(const signed char* gnext_arg, streamsize n);
30 strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = nullptr);
31 strstreambuf(const unsigned char* gnext_arg, streamsize n);
33 strstreambuf(strstreambuf&& rhs);
34 strstreambuf& operator=(strstreambuf&& rhs);
36 virtual ~strstreambuf();
38 void swap(strstreambuf& rhs);
40 void freeze(bool freezefl = true);
45 virtual int_type overflow (int_type c = EOF);
46 virtual int_type pbackfail(int_type c = EOF);
47 virtual int_type underflow();
48 virtual pos_type seekoff(off_type off, ios_base::seekdir way,
49 ios_base::openmode which = ios_base::in | ios_base::out);
50 virtual pos_type seekpos(pos_type sp,
51 ios_base::openmode which = ios_base::in | ios_base::out);
52 virtual streambuf* setbuf(char* s, streamsize n);
55 typedef T1 strstate; // exposition only
56 static const strstate allocated; // exposition only
57 static const strstate constant; // exposition only
58 static const strstate dynamic; // exposition only
59 static const strstate frozen; // exposition only
60 strstate strmode; // exposition only
61 streamsize alsize; // exposition only
62 void* (*palloc)(size_t); // exposition only
63 void (*pfree)(void*); // exposition only
67 : public basic_istream<char>
70 explicit istrstream(const char* s);
71 explicit istrstream(char* s);
72 istrstream(const char* s, streamsize n);
73 istrstream(char* s, streamsize n);
75 virtual ~istrstream();
77 strstreambuf* rdbuf() const;
81 strstreambuf sb; // exposition only
85 : public basic_ostream<char>
89 ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
91 virtual ~ostrstream();
93 strstreambuf* rdbuf() const;
94 void freeze(bool freezefl = true);
99 strstreambuf sb; // exposition only
103 : public basic_iostream<char>
107 typedef char char_type;
108 typedef char_traits<char>::int_type int_type;
109 typedef char_traits<char>::pos_type pos_type;
110 typedef char_traits<char>::off_type off_type;
112 // constructors/destructor
114 strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
116 virtual ~strstream();
119 strstreambuf* rdbuf() const;
120 void freeze(bool freezefl = true);
125 strstreambuf sb; // exposition only
136 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
137 #pragma GCC system_header
140 _LIBCPP_BEGIN_NAMESPACE_STD
142 class _LIBCPP_TYPE_VIS strstreambuf
146 #ifndef _LIBCPP_CXX03_LANG
147 strstreambuf() : strstreambuf(0) {}
148 explicit strstreambuf(streamsize __alsize);
150 explicit strstreambuf(streamsize __alsize = 0);
152 strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
153 strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
154 strstreambuf(const char* __gnext, streamsize __n);
156 strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);
157 strstreambuf(const signed char* __gnext, streamsize __n);
158 strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
159 strstreambuf(const unsigned char* __gnext, streamsize __n);
161 #ifndef _LIBCPP_CXX03_LANG
162 _LIBCPP_INLINE_VISIBILITY
163 strstreambuf(strstreambuf&& __rhs);
164 _LIBCPP_INLINE_VISIBILITY
165 strstreambuf& operator=(strstreambuf&& __rhs);
166 #endif // _LIBCPP_CXX03_LANG
168 virtual ~strstreambuf();
170 void swap(strstreambuf& __rhs);
172 void freeze(bool __freezefl = true);
177 virtual int_type overflow (int_type __c = EOF);
178 virtual int_type pbackfail(int_type __c = EOF);
179 virtual int_type underflow();
180 virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
181 ios_base::openmode __which = ios_base::in | ios_base::out);
182 virtual pos_type seekpos(pos_type __sp,
183 ios_base::openmode __which = ios_base::in | ios_base::out);
186 typedef unsigned __mode_type;
187 static const __mode_type __allocated = 0x01;
188 static const __mode_type __constant = 0x02;
189 static const __mode_type __dynamic = 0x04;
190 static const __mode_type __frozen = 0x08;
191 static const streamsize __default_alsize = 4096;
193 __mode_type __strmode_;
194 streamsize __alsize_;
195 void* (*__palloc_)(size_t);
196 void (*__pfree_)(void*);
198 void __init(char* __gnext, streamsize __n, char* __pbeg);
201 #ifndef _LIBCPP_CXX03_LANG
203 inline _LIBCPP_INLINE_VISIBILITY
204 strstreambuf::strstreambuf(strstreambuf&& __rhs)
206 __strmode_(__rhs.__strmode_),
207 __alsize_(__rhs.__alsize_),
208 __palloc_(__rhs.__palloc_),
209 __pfree_(__rhs.__pfree_)
211 __rhs.setg(nullptr, nullptr, nullptr);
212 __rhs.setp(nullptr, nullptr);
215 inline _LIBCPP_INLINE_VISIBILITY
217 strstreambuf::operator=(strstreambuf&& __rhs)
219 if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
226 streambuf::operator=(__rhs);
227 __strmode_ = __rhs.__strmode_;
228 __alsize_ = __rhs.__alsize_;
229 __palloc_ = __rhs.__palloc_;
230 __pfree_ = __rhs.__pfree_;
231 __rhs.setg(nullptr, nullptr, nullptr);
232 __rhs.setp(nullptr, nullptr);
236 #endif // _LIBCPP_CXX03_LANG
238 class _LIBCPP_TYPE_VIS istrstream
242 _LIBCPP_INLINE_VISIBILITY
243 explicit istrstream(const char* __s)
244 : istream(&__sb_), __sb_(__s, 0) {}
245 _LIBCPP_INLINE_VISIBILITY
246 explicit istrstream(char* __s)
247 : istream(&__sb_), __sb_(__s, 0) {}
248 _LIBCPP_INLINE_VISIBILITY
249 istrstream(const char* __s, streamsize __n)
250 : istream(&__sb_), __sb_(__s, __n) {}
251 _LIBCPP_INLINE_VISIBILITY
252 istrstream(char* __s, streamsize __n)
253 : istream(&__sb_), __sb_(__s, __n) {}
255 #ifndef _LIBCPP_CXX03_LANG
256 _LIBCPP_INLINE_VISIBILITY
257 istrstream(istrstream&& __rhs)
258 : istream(_VSTD::move(__rhs)),
259 __sb_(_VSTD::move(__rhs.__sb_))
261 istream::set_rdbuf(&__sb_);
264 _LIBCPP_INLINE_VISIBILITY
265 istrstream& operator=(istrstream&& __rhs)
267 istream::operator=(_VSTD::move(__rhs));
268 __sb_ = _VSTD::move(__rhs.__sb_);
271 #endif // _LIBCPP_CXX03_LANG
273 virtual ~istrstream();
275 _LIBCPP_INLINE_VISIBILITY
276 void swap(istrstream& __rhs)
278 istream::swap(__rhs);
279 __sb_.swap(__rhs.__sb_);
282 _LIBCPP_INLINE_VISIBILITY
283 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
284 _LIBCPP_INLINE_VISIBILITY
285 char *str() {return __sb_.str();}
291 class _LIBCPP_TYPE_VIS ostrstream
295 _LIBCPP_INLINE_VISIBILITY
298 _LIBCPP_INLINE_VISIBILITY
299 ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
301 __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
304 #ifndef _LIBCPP_CXX03_LANG
305 _LIBCPP_INLINE_VISIBILITY
306 ostrstream(ostrstream&& __rhs)
307 : ostream(_VSTD::move(__rhs)),
308 __sb_(_VSTD::move(__rhs.__sb_))
310 ostream::set_rdbuf(&__sb_);
313 _LIBCPP_INLINE_VISIBILITY
314 ostrstream& operator=(ostrstream&& __rhs)
316 ostream::operator=(_VSTD::move(__rhs));
317 __sb_ = _VSTD::move(__rhs.__sb_);
320 #endif // _LIBCPP_CXX03_LANG
322 virtual ~ostrstream();
324 _LIBCPP_INLINE_VISIBILITY
325 void swap(ostrstream& __rhs)
327 ostream::swap(__rhs);
328 __sb_.swap(__rhs.__sb_);
331 _LIBCPP_INLINE_VISIBILITY
332 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
333 _LIBCPP_INLINE_VISIBILITY
334 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
335 _LIBCPP_INLINE_VISIBILITY
336 char* str() {return __sb_.str();}
337 _LIBCPP_INLINE_VISIBILITY
338 int pcount() const {return __sb_.pcount();}
341 strstreambuf __sb_; // exposition only
344 class _LIBCPP_TYPE_VIS strstream
349 typedef char char_type;
350 typedef char_traits<char>::int_type int_type;
351 typedef char_traits<char>::pos_type pos_type;
352 typedef char_traits<char>::off_type off_type;
354 // constructors/destructor
355 _LIBCPP_INLINE_VISIBILITY
357 : iostream(&__sb_) {}
358 _LIBCPP_INLINE_VISIBILITY
359 strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
361 __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
364 #ifndef _LIBCPP_CXX03_LANG
365 _LIBCPP_INLINE_VISIBILITY
366 strstream(strstream&& __rhs)
367 : iostream(_VSTD::move(__rhs)),
368 __sb_(_VSTD::move(__rhs.__sb_))
370 iostream::set_rdbuf(&__sb_);
373 _LIBCPP_INLINE_VISIBILITY
374 strstream& operator=(strstream&& __rhs)
376 iostream::operator=(_VSTD::move(__rhs));
377 __sb_ = _VSTD::move(__rhs.__sb_);
380 #endif // _LIBCPP_CXX03_LANG
382 virtual ~strstream();
384 _LIBCPP_INLINE_VISIBILITY
385 void swap(strstream& __rhs)
387 iostream::swap(__rhs);
388 __sb_.swap(__rhs.__sb_);
392 _LIBCPP_INLINE_VISIBILITY
393 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
394 _LIBCPP_INLINE_VISIBILITY
395 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
396 _LIBCPP_INLINE_VISIBILITY
397 int pcount() const {return __sb_.pcount();}
398 _LIBCPP_INLINE_VISIBILITY
399 char* str() {return __sb_.str();}
402 strstreambuf __sb_; // exposition only
405 _LIBCPP_END_NAMESPACE_STD
407 #endif // _LIBCPP_STRSTREAM