]>
Commit | Line | Data |
---|---|---|
9a56333e BK |
1 | // Backward-compat support -*- C++ -*- |
2 | ||
a5544970 | 3 | // Copyright (C) 2001-2019 Free Software Foundation, Inc. |
9a56333e BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
9a56333e BK |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
9a56333e | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
9a56333e BK |
24 | |
25 | /* | |
26 | * Copyright (c) 1998 | |
27 | * Silicon Graphics Computer Systems, Inc. | |
28 | * | |
29 | * Permission to use, copy, modify, distribute and sell this software | |
30 | * and its documentation for any purpose is hereby granted without fee, | |
31 | * provided that the above copyright notice appear in all copies and | |
32 | * that both that copyright notice and this permission notice appear | |
33 | * in supporting documentation. Silicon Graphics makes no | |
34 | * representations about the suitability of this software for any | |
35 | * purpose. It is provided "as is" without express or implied warranty. | |
36 | */ | |
37 | ||
38 | // WARNING: The classes defined in this header are DEPRECATED. This | |
39 | // header is defined in section D.7.1 of the C++ standard, and it | |
40abbf1f | 40 | // MAY BE REMOVED in a future standard revision. One should use the |
9a56333e BK |
41 | // header <sstream> instead. |
42 | ||
6b4f8906 JW |
43 | /** @file strstream |
44 | * This is a Standard C++ Library header. | |
30f276c1 BK |
45 | */ |
46 | ||
5ecfce5c PC |
47 | #ifndef _BACKWARD_STRSTREAM |
48 | #define _BACKWARD_STRSTREAM | |
9a56333e BK |
49 | |
50 | #include "backward_warning.h" | |
51 | #include <iosfwd> | |
52 | #include <ios> | |
53 | #include <istream> | |
54 | #include <ostream> | |
9a56333e | 55 | |
12ffa228 BK |
56 | namespace std _GLIBCXX_VISIBILITY(default) |
57 | { | |
58 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 59 | |
9a56333e BK |
60 | // Class strstreambuf, a streambuf class that manages an array of char. |
61 | // Note that this class is not a template. | |
62 | class strstreambuf : public basic_streambuf<char, char_traits<char> > | |
63 | { | |
e64738b3 | 64 | public: |
9a56333e BK |
65 | // Types. |
66 | typedef char_traits<char> _Traits; | |
67 | typedef basic_streambuf<char, _Traits> _Base; | |
68 | ||
e64738b3 | 69 | public: |
9a56333e | 70 | // Constructor, destructor |
e9ecac30 JW |
71 | #if __cplusplus >= 201103L |
72 | strstreambuf() : strstreambuf(0) { } | |
73 | explicit strstreambuf(streamsize __initial_capacity); | |
74 | #else | |
9a56333e | 75 | explicit strstreambuf(streamsize __initial_capacity = 0); |
e9ecac30 | 76 | #endif |
9a56333e BK |
77 | strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*)); |
78 | ||
50a681c4 JH |
79 | strstreambuf(char* __get, streamsize __n, char* __put = 0) throw (); |
80 | strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0) throw (); | |
81 | strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0) throw (); | |
9a56333e | 82 | |
50a681c4 JH |
83 | strstreambuf(const char* __get, streamsize __n) throw (); |
84 | strstreambuf(const signed char* __get, streamsize __n) throw (); | |
85 | strstreambuf(const unsigned char* __get, streamsize __n) throw (); | |
9a56333e BK |
86 | |
87 | virtual ~strstreambuf(); | |
88 | ||
c6d42579 JW |
89 | #if __cplusplus >= 201103L |
90 | strstreambuf(strstreambuf&& __rhs) noexcept | |
91 | : _Base(__rhs), _M_alloc_fun(__rhs._M_alloc_fun), | |
92 | _M_free_fun(__rhs._M_free_fun), _M_dynamic(__rhs._M_dynamic), | |
93 | _M_frozen(__rhs._M_frozen), _M_constant(__rhs._M_constant) | |
94 | { | |
95 | __rhs.setg(nullptr, nullptr, nullptr); | |
96 | __rhs.setp(nullptr, nullptr); | |
97 | } | |
98 | ||
99 | strstreambuf& | |
100 | operator=(strstreambuf&& __rhs) noexcept | |
101 | { | |
102 | if (_M_dynamic && !_M_frozen) | |
103 | _M_free(eback()); | |
104 | _Base::operator=(static_cast<const _Base&>(__rhs)); | |
105 | _M_alloc_fun = __rhs._M_alloc_fun; | |
106 | _M_free_fun = __rhs._M_free_fun; | |
107 | _M_dynamic = __rhs._M_dynamic; | |
108 | _M_frozen = __rhs._M_frozen; | |
109 | _M_constant = __rhs._M_constant; | |
110 | __rhs.setg(nullptr, nullptr, nullptr); | |
111 | __rhs.setp(nullptr, nullptr); | |
112 | return *this; | |
113 | } | |
114 | #endif | |
115 | ||
9a56333e | 116 | public: |
50a681c4 JH |
117 | void freeze(bool = true) throw (); |
118 | char* str() throw (); | |
119 | _GLIBCXX_PURE int pcount() const throw (); | |
9a56333e BK |
120 | |
121 | protected: | |
122 | virtual int_type overflow(int_type __c = _Traits::eof()); | |
123 | virtual int_type pbackfail(int_type __c = _Traits::eof()); | |
124 | virtual int_type underflow(); | |
125 | virtual _Base* setbuf(char* __buf, streamsize __n); | |
126 | virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir, | |
127 | ios_base::openmode __mode | |
128 | = ios_base::in | ios_base::out); | |
129 | virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode | |
130 | = ios_base::in | ios_base::out); | |
131 | ||
e64738b3 | 132 | private: |
c6d42579 | 133 | #if __cplusplus < 201103L |
26c691a8 BK |
134 | strstreambuf& |
135 | operator=(const strstreambuf&); | |
136 | ||
137 | strstreambuf(const strstreambuf&); | |
c6d42579 | 138 | #endif |
26c691a8 | 139 | |
9a56333e BK |
140 | // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun. |
141 | char* _M_alloc(size_t); | |
142 | void _M_free(char*); | |
143 | ||
144 | // Helper function used in constructors. | |
50a681c4 | 145 | void _M_setup(char* __get, char* __put, streamsize __n) throw (); |
9a56333e | 146 | |
9a56333e BK |
147 | // Data members. |
148 | void* (*_M_alloc_fun)(size_t); | |
149 | void (*_M_free_fun)(void*); | |
150 | ||
151 | bool _M_dynamic : 1; | |
152 | bool _M_frozen : 1; | |
153 | bool _M_constant : 1; | |
154 | }; | |
155 | ||
156 | // Class istrstream, an istream that manages a strstreambuf. | |
157 | class istrstream : public basic_istream<char> | |
158 | { | |
159 | public: | |
160 | explicit istrstream(char*); | |
161 | explicit istrstream(const char*); | |
162 | istrstream(char* , streamsize); | |
163 | istrstream(const char*, streamsize); | |
164 | virtual ~istrstream(); | |
165 | ||
c6d42579 JW |
166 | #if __cplusplus >= 201103L |
167 | istrstream(istrstream&& __rhs) | |
168 | : istream(std::move(__rhs)), _M_buf(std::move(__rhs._M_buf)) | |
169 | { set_rdbuf(&_M_buf); } | |
170 | ||
171 | istrstream& operator=(istrstream&&) = default; | |
172 | #endif | |
173 | ||
50a681c4 JH |
174 | _GLIBCXX_CONST strstreambuf* rdbuf() const throw (); |
175 | char* str() throw (); | |
9a56333e BK |
176 | |
177 | private: | |
178 | strstreambuf _M_buf; | |
179 | }; | |
180 | ||
181 | // Class ostrstream | |
182 | class ostrstream : public basic_ostream<char> | |
183 | { | |
184 | public: | |
185 | ostrstream(); | |
186 | ostrstream(char*, int, ios_base::openmode = ios_base::out); | |
187 | virtual ~ostrstream(); | |
188 | ||
c6d42579 JW |
189 | #if __cplusplus >= 201103L |
190 | ostrstream(ostrstream&& __rhs) | |
191 | : ostream(std::move(__rhs)), _M_buf(std::move(__rhs._M_buf)) | |
192 | { set_rdbuf(&_M_buf); } | |
193 | ||
194 | ostrstream& operator=(ostrstream&&) = default; | |
195 | #endif | |
196 | ||
50a681c4 JH |
197 | _GLIBCXX_CONST strstreambuf* rdbuf() const throw (); |
198 | void freeze(bool = true) throw(); | |
199 | char* str() throw (); | |
200 | _GLIBCXX_PURE int pcount() const throw (); | |
9a56333e BK |
201 | |
202 | private: | |
203 | strstreambuf _M_buf; | |
204 | }; | |
205 | ||
206 | // Class strstream | |
207 | class strstream : public basic_iostream<char> | |
208 | { | |
209 | public: | |
210 | typedef char char_type; | |
211 | typedef char_traits<char>::int_type int_type; | |
212 | typedef char_traits<char>::pos_type pos_type; | |
213 | typedef char_traits<char>::off_type off_type; | |
214 | ||
215 | strstream(); | |
216 | strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out); | |
217 | virtual ~strstream(); | |
218 | ||
c6d42579 JW |
219 | #if __cplusplus >= 201103L |
220 | strstream(strstream&& __rhs) | |
221 | : iostream(std::move(__rhs)), _M_buf(std::move(__rhs._M_buf)) | |
222 | { set_rdbuf(&_M_buf); } | |
223 | ||
224 | strstream& operator=(strstream&&) = default; | |
225 | #endif | |
226 | ||
50a681c4 JH |
227 | _GLIBCXX_CONST strstreambuf* rdbuf() const throw (); |
228 | void freeze(bool = true) throw (); | |
229 | _GLIBCXX_PURE int pcount() const throw (); | |
230 | char* str() throw (); | |
9a56333e BK |
231 | |
232 | private: | |
233 | strstreambuf _M_buf; | |
234 | }; | |
3cbc7af0 | 235 | |
12ffa228 BK |
236 | _GLIBCXX_END_NAMESPACE_VERSION |
237 | } // namespace | |
3cbc7af0 | 238 | |
e64738b3 | 239 | #endif |