strstream 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Backward-compat support -*- C++ -*-
  2. // Copyright (C) 2001-2018 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_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. explicit strstreambuf(streamsize __initial_capacity = 0);
  60. strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
  61. strstreambuf(char* __get, streamsize __n, char* __put = 0) throw ();
  62. strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0) throw ();
  63. strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0) throw ();
  64. strstreambuf(const char* __get, streamsize __n) throw ();
  65. strstreambuf(const signed char* __get, streamsize __n) throw ();
  66. strstreambuf(const unsigned char* __get, streamsize __n) throw ();
  67. virtual ~strstreambuf();
  68. public:
  69. void freeze(bool = true) throw ();
  70. char* str() throw ();
  71. _GLIBCXX_PURE int pcount() const throw ();
  72. protected:
  73. virtual int_type overflow(int_type __c = _Traits::eof());
  74. virtual int_type pbackfail(int_type __c = _Traits::eof());
  75. virtual int_type underflow();
  76. virtual _Base* setbuf(char* __buf, streamsize __n);
  77. virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
  78. ios_base::openmode __mode
  79. = ios_base::in | ios_base::out);
  80. virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
  81. = ios_base::in | ios_base::out);
  82. private:
  83. strstreambuf&
  84. operator=(const strstreambuf&);
  85. strstreambuf(const strstreambuf&);
  86. // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
  87. char* _M_alloc(size_t);
  88. void _M_free(char*);
  89. // Helper function used in constructors.
  90. void _M_setup(char* __get, char* __put, streamsize __n) throw ();
  91. private:
  92. // Data members.
  93. void* (*_M_alloc_fun)(size_t);
  94. void (*_M_free_fun)(void*);
  95. bool _M_dynamic : 1;
  96. bool _M_frozen : 1;
  97. bool _M_constant : 1;
  98. };
  99. // Class istrstream, an istream that manages a strstreambuf.
  100. class istrstream : public basic_istream<char>
  101. {
  102. public:
  103. explicit istrstream(char*);
  104. explicit istrstream(const char*);
  105. istrstream(char* , streamsize);
  106. istrstream(const char*, streamsize);
  107. virtual ~istrstream();
  108. _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
  109. char* str() throw ();
  110. private:
  111. strstreambuf _M_buf;
  112. };
  113. // Class ostrstream
  114. class ostrstream : public basic_ostream<char>
  115. {
  116. public:
  117. ostrstream();
  118. ostrstream(char*, int, ios_base::openmode = ios_base::out);
  119. virtual ~ostrstream();
  120. _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
  121. void freeze(bool = true) throw();
  122. char* str() throw ();
  123. _GLIBCXX_PURE int pcount() const throw ();
  124. private:
  125. strstreambuf _M_buf;
  126. };
  127. // Class strstream
  128. class strstream : public basic_iostream<char>
  129. {
  130. public:
  131. typedef char char_type;
  132. typedef char_traits<char>::int_type int_type;
  133. typedef char_traits<char>::pos_type pos_type;
  134. typedef char_traits<char>::off_type off_type;
  135. strstream();
  136. strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
  137. virtual ~strstream();
  138. _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
  139. void freeze(bool = true) throw ();
  140. _GLIBCXX_PURE int pcount() const throw ();
  141. char* str() throw ();
  142. private:
  143. strstreambuf _M_buf;
  144. };
  145. _GLIBCXX_END_NAMESPACE_VERSION
  146. } // namespace
  147. #endif