xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/strstream (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric// -*- C++ -*-
2*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric//
4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric//
8*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric
10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03_STRSTREAM
11*700637cbSDimitry Andric#define _LIBCPP___CXX03_STRSTREAM
12*700637cbSDimitry Andric
13*700637cbSDimitry Andric/*
14*700637cbSDimitry Andric    strstream synopsis
15*700637cbSDimitry Andric
16*700637cbSDimitry Andricclass strstreambuf                                    // Removed in C++26
17*700637cbSDimitry Andric    : public basic_streambuf<char>
18*700637cbSDimitry Andric{
19*700637cbSDimitry Andricpublic:
20*700637cbSDimitry Andric    explicit strstreambuf(streamsize alsize_arg = 0); // before C++20
21*700637cbSDimitry Andric    strstreambuf() : strstreambuf(0) {}               // C++20
22*700637cbSDimitry Andric    explicit strstreambuf(streamsize alsize_arg);     // C++20
23*700637cbSDimitry Andric
24*700637cbSDimitry Andric    strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
25*700637cbSDimitry Andric    strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
26*700637cbSDimitry Andric    strstreambuf(const char* gnext_arg, streamsize n);
27*700637cbSDimitry Andric
28*700637cbSDimitry Andric    strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = nullptr);
29*700637cbSDimitry Andric    strstreambuf(const signed char* gnext_arg, streamsize n);
30*700637cbSDimitry Andric    strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = nullptr);
31*700637cbSDimitry Andric    strstreambuf(const unsigned char* gnext_arg, streamsize n);
32*700637cbSDimitry Andric
33*700637cbSDimitry Andric    strstreambuf(strstreambuf&& rhs);
34*700637cbSDimitry Andric    strstreambuf& operator=(strstreambuf&& rhs);
35*700637cbSDimitry Andric
36*700637cbSDimitry Andric    virtual ~strstreambuf();
37*700637cbSDimitry Andric
38*700637cbSDimitry Andric    void swap(strstreambuf& rhs);
39*700637cbSDimitry Andric
40*700637cbSDimitry Andric    void freeze(bool freezefl = true);
41*700637cbSDimitry Andric    char* str();
42*700637cbSDimitry Andric    int pcount() const;
43*700637cbSDimitry Andric
44*700637cbSDimitry Andricprotected:
45*700637cbSDimitry Andric    virtual int_type overflow (int_type c = EOF);
46*700637cbSDimitry Andric    virtual int_type pbackfail(int_type c = EOF);
47*700637cbSDimitry Andric    virtual int_type underflow();
48*700637cbSDimitry Andric    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
49*700637cbSDimitry Andric                             ios_base::openmode which = ios_base::in | ios_base::out);
50*700637cbSDimitry Andric    virtual pos_type seekpos(pos_type sp,
51*700637cbSDimitry Andric                             ios_base::openmode which = ios_base::in | ios_base::out);
52*700637cbSDimitry Andric    virtual streambuf* setbuf(char* s, streamsize n);
53*700637cbSDimitry Andric
54*700637cbSDimitry Andricprivate:
55*700637cbSDimitry Andric    typedef T1 strstate;                // exposition only
56*700637cbSDimitry Andric    static const strstate allocated;    // exposition only
57*700637cbSDimitry Andric    static const strstate constant;     // exposition only
58*700637cbSDimitry Andric    static const strstate dynamic;      // exposition only
59*700637cbSDimitry Andric    static const strstate frozen;       // exposition only
60*700637cbSDimitry Andric    strstate strmode;                   // exposition only
61*700637cbSDimitry Andric    streamsize alsize;                  // exposition only
62*700637cbSDimitry Andric    void* (*palloc)(size_t);            // exposition only
63*700637cbSDimitry Andric    void (*pfree)(void*);               // exposition only
64*700637cbSDimitry Andric};
65*700637cbSDimitry Andric
66*700637cbSDimitry Andricclass istrstream                                      // Removed in C++26
67*700637cbSDimitry Andric    : public basic_istream<char>
68*700637cbSDimitry Andric{
69*700637cbSDimitry Andricpublic:
70*700637cbSDimitry Andric    explicit istrstream(const char* s);
71*700637cbSDimitry Andric    explicit istrstream(char* s);
72*700637cbSDimitry Andric    istrstream(const char* s, streamsize n);
73*700637cbSDimitry Andric    istrstream(char* s, streamsize n);
74*700637cbSDimitry Andric
75*700637cbSDimitry Andric    virtual ~istrstream();
76*700637cbSDimitry Andric
77*700637cbSDimitry Andric    strstreambuf* rdbuf() const;
78*700637cbSDimitry Andric    char *str();
79*700637cbSDimitry Andric
80*700637cbSDimitry Andricprivate:
81*700637cbSDimitry Andric    strstreambuf sb; // exposition only
82*700637cbSDimitry Andric};
83*700637cbSDimitry Andric
84*700637cbSDimitry Andricclass ostrstream                                      // Removed in C++26
85*700637cbSDimitry Andric    : public basic_ostream<char>
86*700637cbSDimitry Andric{
87*700637cbSDimitry Andricpublic:
88*700637cbSDimitry Andric    ostrstream();
89*700637cbSDimitry Andric    ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
90*700637cbSDimitry Andric
91*700637cbSDimitry Andric    virtual ~ostrstream();
92*700637cbSDimitry Andric
93*700637cbSDimitry Andric    strstreambuf* rdbuf() const;
94*700637cbSDimitry Andric    void freeze(bool freezefl = true);
95*700637cbSDimitry Andric    char* str();
96*700637cbSDimitry Andric    int pcount() const;
97*700637cbSDimitry Andric
98*700637cbSDimitry Andricprivate:
99*700637cbSDimitry Andric    strstreambuf sb; // exposition only
100*700637cbSDimitry Andric};
101*700637cbSDimitry Andric
102*700637cbSDimitry Andricclass strstream                                       // Removed in C++26
103*700637cbSDimitry Andric    : public basic_iostream<char>
104*700637cbSDimitry Andric{
105*700637cbSDimitry Andricpublic:
106*700637cbSDimitry Andric    // Types
107*700637cbSDimitry Andric    typedef char                        char_type;
108*700637cbSDimitry Andric    typedef char_traits<char>::int_type int_type;
109*700637cbSDimitry Andric    typedef char_traits<char>::pos_type pos_type;
110*700637cbSDimitry Andric    typedef char_traits<char>::off_type off_type;
111*700637cbSDimitry Andric
112*700637cbSDimitry Andric    // constructors/destructor
113*700637cbSDimitry Andric    strstream();
114*700637cbSDimitry Andric    strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
115*700637cbSDimitry Andric
116*700637cbSDimitry Andric    virtual ~strstream();
117*700637cbSDimitry Andric
118*700637cbSDimitry Andric    // Members:
119*700637cbSDimitry Andric    strstreambuf* rdbuf() const;
120*700637cbSDimitry Andric    void freeze(bool freezefl = true);
121*700637cbSDimitry Andric    int pcount() const;
122*700637cbSDimitry Andric    char* str();
123*700637cbSDimitry Andric
124*700637cbSDimitry Andricprivate:
125*700637cbSDimitry Andric    strstreambuf sb; // exposition only
126*700637cbSDimitry Andric};
127*700637cbSDimitry Andric
128*700637cbSDimitry Andric}  // std
129*700637cbSDimitry Andric
130*700637cbSDimitry Andric*/
131*700637cbSDimitry Andric
132*700637cbSDimitry Andric#include <__cxx03/__config>
133*700637cbSDimitry Andric#include <__cxx03/istream>
134*700637cbSDimitry Andric#include <__cxx03/ostream>
135*700637cbSDimitry Andric#include <__cxx03/version>
136*700637cbSDimitry Andric
137*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
138*700637cbSDimitry Andric#  pragma GCC system_header
139*700637cbSDimitry Andric#endif
140*700637cbSDimitry Andric
141*700637cbSDimitry Andric_LIBCPP_PUSH_MACROS
142*700637cbSDimitry Andric#  include <__cxx03/__undef_macros>
143*700637cbSDimitry Andric
144*700637cbSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
145*700637cbSDimitry Andric
146*700637cbSDimitry Andricclass _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf : public streambuf {
147*700637cbSDimitry Andricpublic:
148*700637cbSDimitry Andric  explicit strstreambuf(streamsize __alsize = 0);
149*700637cbSDimitry Andric  strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
150*700637cbSDimitry Andric  strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
151*700637cbSDimitry Andric  strstreambuf(const char* __gnext, streamsize __n);
152*700637cbSDimitry Andric
153*700637cbSDimitry Andric  strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);
154*700637cbSDimitry Andric  strstreambuf(const signed char* __gnext, streamsize __n);
155*700637cbSDimitry Andric  strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
156*700637cbSDimitry Andric  strstreambuf(const unsigned char* __gnext, streamsize __n);
157*700637cbSDimitry Andric
158*700637cbSDimitry Andric  ~strstreambuf() override;
159*700637cbSDimitry Andric
160*700637cbSDimitry Andric  void swap(strstreambuf& __rhs);
161*700637cbSDimitry Andric
162*700637cbSDimitry Andric  void freeze(bool __freezefl = true);
163*700637cbSDimitry Andric  char* str();
164*700637cbSDimitry Andric  int pcount() const;
165*700637cbSDimitry Andric
166*700637cbSDimitry Andricprotected:
167*700637cbSDimitry Andric  int_type overflow(int_type __c = EOF) override;
168*700637cbSDimitry Andric  int_type pbackfail(int_type __c = EOF) override;
169*700637cbSDimitry Andric  int_type underflow() override;
170*700637cbSDimitry Andric  pos_type
171*700637cbSDimitry Andric  seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) override;
172*700637cbSDimitry Andric  pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) override;
173*700637cbSDimitry Andric
174*700637cbSDimitry Andricprivate:
175*700637cbSDimitry Andric  typedef unsigned __mode_type;
176*700637cbSDimitry Andric  static const __mode_type __allocated     = 0x01;
177*700637cbSDimitry Andric  static const __mode_type __constant      = 0x02;
178*700637cbSDimitry Andric  static const __mode_type __dynamic       = 0x04;
179*700637cbSDimitry Andric  static const __mode_type __frozen        = 0x08;
180*700637cbSDimitry Andric  static const streamsize __default_alsize = 4096;
181*700637cbSDimitry Andric
182*700637cbSDimitry Andric  __mode_type __strmode_;
183*700637cbSDimitry Andric  streamsize __alsize_;
184*700637cbSDimitry Andric  void* (*__palloc_)(size_t);
185*700637cbSDimitry Andric  void (*__pfree_)(void*);
186*700637cbSDimitry Andric
187*700637cbSDimitry Andric  void __init(char* __gnext, streamsize __n, char* __pbeg);
188*700637cbSDimitry Andric};
189*700637cbSDimitry Andric
190*700637cbSDimitry Andricclass _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream : public istream {
191*700637cbSDimitry Andricpublic:
192*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit istrstream(const char* __s) : istream(&__sb_), __sb_(__s, 0) {}
193*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit istrstream(char* __s) : istream(&__sb_), __sb_(__s, 0) {}
194*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI istrstream(const char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
195*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
196*700637cbSDimitry Andric
197*700637cbSDimitry Andric  ~istrstream() override;
198*700637cbSDimitry Andric
199*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(istrstream& __rhs) {
200*700637cbSDimitry Andric    istream::swap(__rhs);
201*700637cbSDimitry Andric    __sb_.swap(__rhs.__sb_);
202*700637cbSDimitry Andric  }
203*700637cbSDimitry Andric
204*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
205*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
206*700637cbSDimitry Andric
207*700637cbSDimitry Andricprivate:
208*700637cbSDimitry Andric  strstreambuf __sb_;
209*700637cbSDimitry Andric};
210*700637cbSDimitry Andric
211*700637cbSDimitry Andricclass _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI ostrstream : public ostream {
212*700637cbSDimitry Andricpublic:
213*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ostrstream() : ostream(&__sb_) {}
214*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
215*700637cbSDimitry Andric      : ostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
216*700637cbSDimitry Andric
217*700637cbSDimitry Andric  ~ostrstream() override;
218*700637cbSDimitry Andric
219*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(ostrstream& __rhs) {
220*700637cbSDimitry Andric    ostream::swap(__rhs);
221*700637cbSDimitry Andric    __sb_.swap(__rhs.__sb_);
222*700637cbSDimitry Andric  }
223*700637cbSDimitry Andric
224*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
225*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
226*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
227*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
228*700637cbSDimitry Andric
229*700637cbSDimitry Andricprivate:
230*700637cbSDimitry Andric  strstreambuf __sb_; // exposition only
231*700637cbSDimitry Andric};
232*700637cbSDimitry Andric
233*700637cbSDimitry Andricclass _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstream : public iostream {
234*700637cbSDimitry Andricpublic:
235*700637cbSDimitry Andric  // Types
236*700637cbSDimitry Andric  typedef char char_type;
237*700637cbSDimitry Andric  typedef char_traits<char>::int_type int_type;
238*700637cbSDimitry Andric  typedef char_traits<char>::pos_type pos_type;
239*700637cbSDimitry Andric  typedef char_traits<char>::off_type off_type;
240*700637cbSDimitry Andric
241*700637cbSDimitry Andric  // constructors/destructor
242*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI strstream() : iostream(&__sb_) {}
243*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
244*700637cbSDimitry Andric      : iostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
245*700637cbSDimitry Andric
246*700637cbSDimitry Andric  ~strstream() override;
247*700637cbSDimitry Andric
248*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(strstream& __rhs) {
249*700637cbSDimitry Andric    iostream::swap(__rhs);
250*700637cbSDimitry Andric    __sb_.swap(__rhs.__sb_);
251*700637cbSDimitry Andric  }
252*700637cbSDimitry Andric
253*700637cbSDimitry Andric  // Members:
254*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
255*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
256*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
257*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
258*700637cbSDimitry Andric
259*700637cbSDimitry Andricprivate:
260*700637cbSDimitry Andric  strstreambuf __sb_; // exposition only
261*700637cbSDimitry Andric};
262*700637cbSDimitry Andric
263*700637cbSDimitry Andric_LIBCPP_END_NAMESPACE_STD
264*700637cbSDimitry Andric
265*700637cbSDimitry Andric_LIBCPP_POP_MACROS
266*700637cbSDimitry Andric
267*700637cbSDimitry Andric#endif // _LIBCPP___CXX03_STRSTREAM
268