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