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
132 #include <__assert> // all public C++ headers provide the assertion handler
138 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
139 # pragma GCC system_header
142 _LIBCPP_BEGIN_NAMESPACE_STD
144 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf
148 #ifndef _LIBCPP_CXX03_LANG
149 _LIBCPP_HIDE_FROM_ABI strstreambuf() : strstreambuf(0) {}
150 explicit strstreambuf(streamsize __alsize);
152 explicit strstreambuf(streamsize __alsize = 0);
154 strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
155 strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
156 strstreambuf(const char* __gnext, streamsize __n);
158 strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);
159 strstreambuf(const signed char* __gnext, streamsize __n);
160 strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
161 strstreambuf(const unsigned char* __gnext, streamsize __n);
163 #ifndef _LIBCPP_CXX03_LANG
164 _LIBCPP_INLINE_VISIBILITY
165 strstreambuf(strstreambuf&& __rhs);
166 _LIBCPP_INLINE_VISIBILITY
167 strstreambuf& operator=(strstreambuf&& __rhs);
168 #endif // _LIBCPP_CXX03_LANG
170 ~strstreambuf() override;
172 void swap(strstreambuf& __rhs);
174 void freeze(bool __freezefl = true);
179 int_type overflow (int_type __c = EOF) override;
180 int_type pbackfail(int_type __c = EOF) override;
181 int_type underflow() override;
182 pos_type seekoff(off_type __off, ios_base::seekdir __way,
183 ios_base::openmode __which = ios_base::in | ios_base::out) override;
184 pos_type seekpos(pos_type __sp,
185 ios_base::openmode __which = ios_base::in | ios_base::out) override;
188 typedef unsigned __mode_type;
189 static const __mode_type __allocated = 0x01;
190 static const __mode_type __constant = 0x02;
191 static const __mode_type __dynamic = 0x04;
192 static const __mode_type __frozen = 0x08;
193 static const streamsize __default_alsize = 4096;
195 __mode_type __strmode_;
196 streamsize __alsize_;
197 void* (*__palloc_)(size_t);
198 void (*__pfree_)(void*);
200 void __init(char* __gnext, streamsize __n, char* __pbeg);
203 #ifndef _LIBCPP_CXX03_LANG
205 inline _LIBCPP_INLINE_VISIBILITY
206 strstreambuf::strstreambuf(strstreambuf&& __rhs)
208 __strmode_(__rhs.__strmode_),
209 __alsize_(__rhs.__alsize_),
210 __palloc_(__rhs.__palloc_),
211 __pfree_(__rhs.__pfree_)
213 __rhs.setg(nullptr, nullptr, nullptr);
214 __rhs.setp(nullptr, nullptr);
217 inline _LIBCPP_INLINE_VISIBILITY
219 strstreambuf::operator=(strstreambuf&& __rhs)
221 if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
228 streambuf::operator=(__rhs);
229 __strmode_ = __rhs.__strmode_;
230 __alsize_ = __rhs.__alsize_;
231 __palloc_ = __rhs.__palloc_;
232 __pfree_ = __rhs.__pfree_;
233 __rhs.setg(nullptr, nullptr, nullptr);
234 __rhs.setp(nullptr, nullptr);
238 #endif // _LIBCPP_CXX03_LANG
240 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream
244 _LIBCPP_INLINE_VISIBILITY
245 explicit istrstream(const char* __s)
246 : istream(&__sb_), __sb_(__s, 0) {}
247 _LIBCPP_INLINE_VISIBILITY
248 explicit istrstream(char* __s)
249 : istream(&__sb_), __sb_(__s, 0) {}
250 _LIBCPP_INLINE_VISIBILITY
251 istrstream(const char* __s, streamsize __n)
252 : istream(&__sb_), __sb_(__s, __n) {}
253 _LIBCPP_INLINE_VISIBILITY
254 istrstream(char* __s, streamsize __n)
255 : istream(&__sb_), __sb_(__s, __n) {}
257 #ifndef _LIBCPP_CXX03_LANG
258 _LIBCPP_INLINE_VISIBILITY
259 istrstream(istrstream&& __rhs) // extension
260 : istream(_VSTD::move(static_cast<istream&>(__rhs))),
261 __sb_(_VSTD::move(__rhs.__sb_))
263 istream::set_rdbuf(&__sb_);
266 _LIBCPP_INLINE_VISIBILITY
267 istrstream& operator=(istrstream&& __rhs)
269 __sb_ = _VSTD::move(__rhs.__sb_);
270 istream::operator=(_VSTD::move(__rhs));
273 #endif // _LIBCPP_CXX03_LANG
275 ~istrstream() override;
277 _LIBCPP_INLINE_VISIBILITY
278 void swap(istrstream& __rhs)
280 istream::swap(__rhs);
281 __sb_.swap(__rhs.__sb_);
284 _LIBCPP_INLINE_VISIBILITY
285 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
286 _LIBCPP_INLINE_VISIBILITY
287 char *str() {return __sb_.str();}
293 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI ostrstream
297 _LIBCPP_INLINE_VISIBILITY
300 _LIBCPP_INLINE_VISIBILITY
301 ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
303 __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
306 #ifndef _LIBCPP_CXX03_LANG
307 _LIBCPP_INLINE_VISIBILITY
308 ostrstream(ostrstream&& __rhs) // extension
309 : ostream(_VSTD::move(static_cast<ostream&>(__rhs))),
310 __sb_(_VSTD::move(__rhs.__sb_))
312 ostream::set_rdbuf(&__sb_);
315 _LIBCPP_INLINE_VISIBILITY
316 ostrstream& operator=(ostrstream&& __rhs)
318 __sb_ = _VSTD::move(__rhs.__sb_);
319 ostream::operator=(_VSTD::move(__rhs));
322 #endif // _LIBCPP_CXX03_LANG
324 ~ostrstream() override;
326 _LIBCPP_INLINE_VISIBILITY
327 void swap(ostrstream& __rhs)
329 ostream::swap(__rhs);
330 __sb_.swap(__rhs.__sb_);
333 _LIBCPP_INLINE_VISIBILITY
334 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
335 _LIBCPP_INLINE_VISIBILITY
336 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
337 _LIBCPP_INLINE_VISIBILITY
338 char* str() {return __sb_.str();}
339 _LIBCPP_INLINE_VISIBILITY
340 int pcount() const {return __sb_.pcount();}
343 strstreambuf __sb_; // exposition only
346 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstream
351 typedef char char_type;
352 typedef char_traits<char>::int_type int_type;
353 typedef char_traits<char>::pos_type pos_type;
354 typedef char_traits<char>::off_type off_type;
356 // constructors/destructor
357 _LIBCPP_INLINE_VISIBILITY
359 : iostream(&__sb_) {}
360 _LIBCPP_INLINE_VISIBILITY
361 strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
363 __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
366 #ifndef _LIBCPP_CXX03_LANG
367 _LIBCPP_INLINE_VISIBILITY
368 strstream(strstream&& __rhs) // extension
369 : iostream(_VSTD::move(static_cast<iostream&>(__rhs))),
370 __sb_(_VSTD::move(__rhs.__sb_))
372 iostream::set_rdbuf(&__sb_);
375 _LIBCPP_INLINE_VISIBILITY
376 strstream& operator=(strstream&& __rhs)
378 __sb_ = _VSTD::move(__rhs.__sb_);
379 iostream::operator=(_VSTD::move(__rhs));
382 #endif // _LIBCPP_CXX03_LANG
384 ~strstream() override;
386 _LIBCPP_INLINE_VISIBILITY
387 void swap(strstream& __rhs)
389 iostream::swap(__rhs);
390 __sb_.swap(__rhs.__sb_);
394 _LIBCPP_INLINE_VISIBILITY
395 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
396 _LIBCPP_INLINE_VISIBILITY
397 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
398 _LIBCPP_INLINE_VISIBILITY
399 int pcount() const {return __sb_.pcount();}
400 _LIBCPP_INLINE_VISIBILITY
401 char* str() {return __sb_.str();}
404 strstreambuf __sb_; // exposition only
407 _LIBCPP_END_NAMESPACE_STD
409 #endif // _LIBCPP_STRSTREAM