You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
7.3KB

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