1 // Backward-compat support -*- C++ -*-
3 // Copyright (C) 2001-2018 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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.
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.
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/>.
27 * Silicon Graphics Computer Systems, Inc.
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.
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
40 // MAY BE REMOVED in a future standard revision. One should use the
41 // header <sstream> instead.
44 * This is a Standard C++ Library header.
47 #ifndef _BACKWARD_STRSTREAM
48 #define _BACKWARD_STRSTREAM
50 #include "backward_warning.h"
56 namespace std _GLIBCXX_VISIBILITY(default)
58 _GLIBCXX_BEGIN_NAMESPACE_VERSION
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> >
66 typedef char_traits<char> _Traits;
67 typedef basic_streambuf<char, _Traits> _Base;
70 // Constructor, destructor
71 explicit strstreambuf(streamsize __initial_capacity = 0);
72 strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
74 strstreambuf(char* __get, streamsize __n, char* __put = 0) throw ();
75 strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0) throw ();
76 strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0) throw ();
78 strstreambuf(const char* __get, streamsize __n) throw ();
79 strstreambuf(const signed char* __get, streamsize __n) throw ();
80 strstreambuf(const unsigned char* __get, streamsize __n) throw ();
82 virtual ~strstreambuf();
84 #if __cplusplus >= 201103L
85 strstreambuf(strstreambuf&& __rhs) noexcept
86 : _Base(__rhs), _M_alloc_fun(__rhs._M_alloc_fun),
87 _M_free_fun(__rhs._M_free_fun), _M_dynamic(__rhs._M_dynamic),
88 _M_frozen(__rhs._M_frozen), _M_constant(__rhs._M_constant)
90 __rhs.setg(nullptr, nullptr, nullptr);
91 __rhs.setp(nullptr, nullptr);
95 operator=(strstreambuf&& __rhs) noexcept
97 if (_M_dynamic && !_M_frozen)
99 _Base::operator=(static_cast<const _Base&>(__rhs));
100 _M_alloc_fun = __rhs._M_alloc_fun;
101 _M_free_fun = __rhs._M_free_fun;
102 _M_dynamic = __rhs._M_dynamic;
103 _M_frozen = __rhs._M_frozen;
104 _M_constant = __rhs._M_constant;
105 __rhs.setg(nullptr, nullptr, nullptr);
106 __rhs.setp(nullptr, nullptr);
112 void freeze(bool = true) throw ();
113 char* str() throw ();
114 _GLIBCXX_PURE int pcount() const throw ();
117 virtual int_type overflow(int_type __c = _Traits::eof());
118 virtual int_type pbackfail(int_type __c = _Traits::eof());
119 virtual int_type underflow();
120 virtual _Base* setbuf(char* __buf, streamsize __n);
121 virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
122 ios_base::openmode __mode
123 = ios_base::in | ios_base::out);
124 virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
125 = ios_base::in | ios_base::out);
128 #if __cplusplus < 201103L
130 operator=(const strstreambuf&);
132 strstreambuf(const strstreambuf&);
135 // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
136 char* _M_alloc(size_t);
139 // Helper function used in constructors.
140 void _M_setup(char* __get, char* __put, streamsize __n) throw ();
143 void* (*_M_alloc_fun)(size_t);
144 void (*_M_free_fun)(void*);
148 bool _M_constant : 1;
151 // Class istrstream, an istream that manages a strstreambuf.
152 class istrstream : public basic_istream<char>
155 explicit istrstream(char*);
156 explicit istrstream(const char*);
157 istrstream(char* , streamsize);
158 istrstream(const char*, streamsize);
159 virtual ~istrstream();
161 #if __cplusplus >= 201103L
162 istrstream(istrstream&& __rhs)
163 : istream(std::move(__rhs)), _M_buf(std::move(__rhs._M_buf))
164 { set_rdbuf(&_M_buf); }
166 istrstream& operator=(istrstream&&) = default;
169 _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
170 char* str() throw ();
177 class ostrstream : public basic_ostream<char>
181 ostrstream(char*, int, ios_base::openmode = ios_base::out);
182 virtual ~ostrstream();
184 #if __cplusplus >= 201103L
185 ostrstream(ostrstream&& __rhs)
186 : ostream(std::move(__rhs)), _M_buf(std::move(__rhs._M_buf))
187 { set_rdbuf(&_M_buf); }
189 ostrstream& operator=(ostrstream&&) = default;
192 _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
193 void freeze(bool = true) throw();
194 char* str() throw ();
195 _GLIBCXX_PURE int pcount() const throw ();
202 class strstream : public basic_iostream<char>
205 typedef char char_type;
206 typedef char_traits<char>::int_type int_type;
207 typedef char_traits<char>::pos_type pos_type;
208 typedef char_traits<char>::off_type off_type;
211 strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
212 virtual ~strstream();
214 #if __cplusplus >= 201103L
215 strstream(strstream&& __rhs)
216 : iostream(std::move(__rhs)), _M_buf(std::move(__rhs._M_buf))
217 { set_rdbuf(&_M_buf); }
219 strstream& operator=(strstream&&) = default;
222 _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
223 void freeze(bool = true) throw ();
224 _GLIBCXX_PURE int pcount() const throw ();
225 char* str() throw ();
231 _GLIBCXX_END_NAMESPACE_VERSION