Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / strstream
blob35d655b8261a44a93c7c9c706f0ea1966ee1bed2
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_STRSTREAM
11 #define _LIBCPP_STRSTREAM
14     strstream synopsis
16 class strstreambuf
17     : public basic_streambuf<char>
19 public:
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);
41     char* str();
42     int pcount() const;
44 protected:
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);
54 private:
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
67     : public basic_istream<char>
69 public:
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;
78     char *str();
80 private:
81     strstreambuf sb; // exposition only
84 class ostrstream
85     : public basic_ostream<char>
87 public:
88     ostrstream();
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);
95     char* str();
96     int pcount() const;
98 private:
99     strstreambuf sb; // exposition only
102 class strstream
103     : public basic_iostream<char>
105 public:
106     // Types
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
113     strstream();
114     strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
116     virtual ~strstream();
118     // Members:
119     strstreambuf* rdbuf() const;
120     void freeze(bool freezefl = true);
121     int pcount() const;
122     char* str();
124 private:
125     strstreambuf sb; // exposition only
128 }  // std
132 #include <__assert> // all public C++ headers provide the assertion handler
133 #include <__config>
134 #include <istream>
135 #include <ostream>
136 #include <version>
138 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
139 #  pragma GCC system_header
140 #endif
142 _LIBCPP_BEGIN_NAMESPACE_STD
144 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf
145     : public streambuf
147 public:
148 #ifndef _LIBCPP_CXX03_LANG
149     _LIBCPP_HIDE_FROM_ABI strstreambuf() : strstreambuf(0) {}
150     explicit strstreambuf(streamsize __alsize);
151 #else
152     explicit strstreambuf(streamsize __alsize = 0);
153 #endif
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);
175     char* str();
176     int pcount() const;
178 protected:
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;
187 private:
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)
207     : streambuf(__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
218 strstreambuf&
219 strstreambuf::operator=(strstreambuf&& __rhs)
221     if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
222     {
223         if (__pfree_)
224             __pfree_(eback());
225         else
226             delete [] eback();
227     }
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);
235     return *this;
238 #endif // _LIBCPP_CXX03_LANG
240 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream
241     : public istream
243 public:
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_))
262     {
263         istream::set_rdbuf(&__sb_);
264     }
266     _LIBCPP_INLINE_VISIBILITY
267     istrstream& operator=(istrstream&& __rhs)
268     {
269         __sb_ = _VSTD::move(__rhs.__sb_);
270         istream::operator=(_VSTD::move(__rhs));
271         return *this;
272     }
273 #endif // _LIBCPP_CXX03_LANG
275     ~istrstream() override;
277     _LIBCPP_INLINE_VISIBILITY
278     void swap(istrstream& __rhs)
279     {
280         istream::swap(__rhs);
281         __sb_.swap(__rhs.__sb_);
282     }
284     _LIBCPP_INLINE_VISIBILITY
285     strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
286     _LIBCPP_INLINE_VISIBILITY
287     char *str() {return __sb_.str();}
289 private:
290     strstreambuf __sb_;
293 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI ostrstream
294     : public ostream
296 public:
297     _LIBCPP_INLINE_VISIBILITY
298     ostrstream()
299         : ostream(&__sb_) {}
300     _LIBCPP_INLINE_VISIBILITY
301     ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
302         : ostream(&__sb_),
303           __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
304         {}
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_))
311     {
312         ostream::set_rdbuf(&__sb_);
313     }
315     _LIBCPP_INLINE_VISIBILITY
316     ostrstream& operator=(ostrstream&& __rhs)
317     {
318         __sb_ = _VSTD::move(__rhs.__sb_);
319         ostream::operator=(_VSTD::move(__rhs));
320         return *this;
321     }
322 #endif // _LIBCPP_CXX03_LANG
324     ~ostrstream() override;
326     _LIBCPP_INLINE_VISIBILITY
327     void swap(ostrstream& __rhs)
328     {
329         ostream::swap(__rhs);
330         __sb_.swap(__rhs.__sb_);
331     }
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();}
342 private:
343     strstreambuf __sb_; // exposition only
346 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstream
347     : public iostream
349 public:
350     // Types
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
358     strstream()
359         : iostream(&__sb_) {}
360     _LIBCPP_INLINE_VISIBILITY
361     strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
362         : iostream(&__sb_),
363           __sb_(__s, __n, __s + (__mode & ios::app ? _VSTD::strlen(__s) : 0))
364         {}
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_))
371     {
372         iostream::set_rdbuf(&__sb_);
373     }
375     _LIBCPP_INLINE_VISIBILITY
376     strstream& operator=(strstream&& __rhs)
377     {
378         __sb_ = _VSTD::move(__rhs.__sb_);
379         iostream::operator=(_VSTD::move(__rhs));
380         return *this;
381     }
382 #endif // _LIBCPP_CXX03_LANG
384     ~strstream() override;
386     _LIBCPP_INLINE_VISIBILITY
387     void swap(strstream& __rhs)
388     {
389         iostream::swap(__rhs);
390         __sb_.swap(__rhs.__sb_);
391     }
393     // Members:
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();}
403 private:
404     strstreambuf __sb_; // exposition only
407 _LIBCPP_END_NAMESPACE_STD
409 #endif // _LIBCPP_STRSTREAM