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
16 class strstreambuf // Removed in C++26
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
66 class istrstream // Removed in C++26
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
84 class ostrstream // Removed in C++26
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
102 class strstream // Removed in C++26
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 <__cxx03/__config>
133 #include <__cxx03/istream>
134 #include <__cxx03/ostream>
135 #include <__cxx03/version>
137 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138 # pragma GCC system_header
141 #if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
144 # include <__cxx03/__undef_macros>
146 _LIBCPP_BEGIN_NAMESPACE_STD
148 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf : public streambuf {
150 # ifndef _LIBCPP_CXX03_LANG
151 _LIBCPP_HIDE_FROM_ABI strstreambuf() : strstreambuf(0) {}
152 explicit strstreambuf(streamsize __alsize);
154 explicit strstreambuf(streamsize __alsize = 0);
156 strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
157 strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
158 strstreambuf(const char* __gnext, streamsize __n);
160 strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);
161 strstreambuf(const signed char* __gnext, streamsize __n);
162 strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
163 strstreambuf(const unsigned char* __gnext, streamsize __n);
165 # ifndef _LIBCPP_CXX03_LANG
166 _LIBCPP_HIDE_FROM_ABI strstreambuf(strstreambuf&& __rhs);
167 _LIBCPP_HIDE_FROM_ABI 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;
183 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) override;
184 pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) override;
187 typedef unsigned __mode_type;
188 static const __mode_type __allocated = 0x01;
189 static const __mode_type __constant = 0x02;
190 static const __mode_type __dynamic = 0x04;
191 static const __mode_type __frozen = 0x08;
192 static const streamsize __default_alsize = 4096;
194 __mode_type __strmode_;
195 streamsize __alsize_;
196 void* (*__palloc_)(size_t);
197 void (*__pfree_)(void*);
199 void __init(char* __gnext, streamsize __n, char* __pbeg);
202 # ifndef _LIBCPP_CXX03_LANG
204 inline _LIBCPP_HIDE_FROM_ABI strstreambuf::strstreambuf(strstreambuf&& __rhs)
206 __strmode_(__rhs.__strmode_),
207 __alsize_(__rhs.__alsize_),
208 __palloc_(__rhs.__palloc_),
209 __pfree_(__rhs.__pfree_) {
210 __rhs.setg(nullptr, nullptr, nullptr);
211 __rhs.setp(nullptr, nullptr);
214 inline _LIBCPP_HIDE_FROM_ABI strstreambuf& strstreambuf::operator=(strstreambuf&& __rhs) {
215 if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) {
221 streambuf::operator=(__rhs);
222 __strmode_ = __rhs.__strmode_;
223 __alsize_ = __rhs.__alsize_;
224 __palloc_ = __rhs.__palloc_;
225 __pfree_ = __rhs.__pfree_;
226 __rhs.setg(nullptr, nullptr, nullptr);
227 __rhs.setp(nullptr, nullptr);
231 # endif // _LIBCPP_CXX03_LANG
233 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream : public istream {
235 _LIBCPP_HIDE_FROM_ABI explicit istrstream(const char* __s) : istream(&__sb_), __sb_(__s, 0) {}
236 _LIBCPP_HIDE_FROM_ABI explicit istrstream(char* __s) : istream(&__sb_), __sb_(__s, 0) {}
237 _LIBCPP_HIDE_FROM_ABI istrstream(const char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
238 _LIBCPP_HIDE_FROM_ABI istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
240 # ifndef _LIBCPP_CXX03_LANG
241 _LIBCPP_HIDE_FROM_ABI istrstream(istrstream&& __rhs) // extension
242 : istream(std::move(static_cast<istream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
243 istream::set_rdbuf(&__sb_);
246 _LIBCPP_HIDE_FROM_ABI istrstream& operator=(istrstream&& __rhs) {
247 __sb_ = std::move(__rhs.__sb_);
248 istream::operator=(std::move(__rhs));
251 # endif // _LIBCPP_CXX03_LANG
253 ~istrstream() override;
255 _LIBCPP_HIDE_FROM_ABI void swap(istrstream& __rhs) {
256 istream::swap(__rhs);
257 __sb_.swap(__rhs.__sb_);
260 _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
261 _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
267 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI ostrstream : public ostream {
269 _LIBCPP_HIDE_FROM_ABI ostrstream() : ostream(&__sb_) {}
270 _LIBCPP_HIDE_FROM_ABI ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
271 : ostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
273 # ifndef _LIBCPP_CXX03_LANG
274 _LIBCPP_HIDE_FROM_ABI ostrstream(ostrstream&& __rhs) // extension
275 : ostream(std::move(static_cast<ostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
276 ostream::set_rdbuf(&__sb_);
279 _LIBCPP_HIDE_FROM_ABI ostrstream& operator=(ostrstream&& __rhs) {
280 __sb_ = std::move(__rhs.__sb_);
281 ostream::operator=(std::move(__rhs));
284 # endif // _LIBCPP_CXX03_LANG
286 ~ostrstream() override;
288 _LIBCPP_HIDE_FROM_ABI void swap(ostrstream& __rhs) {
289 ostream::swap(__rhs);
290 __sb_.swap(__rhs.__sb_);
293 _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
294 _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
295 _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
296 _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
299 strstreambuf __sb_; // exposition only
302 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstream : public iostream {
305 typedef char char_type;
306 typedef char_traits<char>::int_type int_type;
307 typedef char_traits<char>::pos_type pos_type;
308 typedef char_traits<char>::off_type off_type;
310 // constructors/destructor
311 _LIBCPP_HIDE_FROM_ABI strstream() : iostream(&__sb_) {}
312 _LIBCPP_HIDE_FROM_ABI strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
313 : iostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
315 # ifndef _LIBCPP_CXX03_LANG
316 _LIBCPP_HIDE_FROM_ABI strstream(strstream&& __rhs) // extension
317 : iostream(std::move(static_cast<iostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
318 iostream::set_rdbuf(&__sb_);
321 _LIBCPP_HIDE_FROM_ABI strstream& operator=(strstream&& __rhs) {
322 __sb_ = std::move(__rhs.__sb_);
323 iostream::operator=(std::move(__rhs));
326 # endif // _LIBCPP_CXX03_LANG
328 ~strstream() override;
330 _LIBCPP_HIDE_FROM_ABI void swap(strstream& __rhs) {
331 iostream::swap(__rhs);
332 __sb_.swap(__rhs.__sb_);
336 _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
337 _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
338 _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
339 _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
342 strstreambuf __sb_; // exposition only
345 _LIBCPP_END_NAMESPACE_STD
349 #endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
351 #endif // _LIBCPP_STRSTREAM