strstream 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Backward-compat support -*- C++ -*-
  2. // Copyright (C) 2001-2015 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 backward/strstream
  37. * This is an internal header file, included by other library headers.
  38. * Do not attempt to use it directly. @headername{sstream}
  39. */
  40. #ifndef _BACKWARD_STRSTREAM
  41. #define _BACKWARD_STRSTREAM
  42. #include "backward_warning.h"
  43. #include <iosfwd>
  44. #include <ios>
  45. #include <istream>
  46. #include <ostream>
  47. #include <string>
  48. namespace std _GLIBCXX_VISIBILITY(default)
  49. {
  50. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  51. // Class strstreambuf, a streambuf class that manages an array of char.
  52. // Note that this class is not a template.
  53. class strstreambuf : public basic_streambuf<char, char_traits<char> >
  54. {
  55. public:
  56. // Types.
  57. typedef char_traits<char> _Traits;
  58. typedef basic_streambuf<char, _Traits> _Base;
  59. public:
  60. // Constructor, destructor
  61. explicit strstreambuf(streamsize __initial_capacity = 0);
  62. strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
  63. strstreambuf(char* __get, streamsize __n, char* __put = 0) throw ();
  64. strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0) throw ();
  65. strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0) throw ();
  66. strstreambuf(const char* __get, streamsize __n) throw ();
  67. strstreambuf(const signed char* __get, streamsize __n) throw ();
  68. strstreambuf(const unsigned char* __get, streamsize __n) throw ();
  69. virtual ~strstreambuf();
  70. public:
  71. void freeze(bool = true) throw ();
  72. char* str() throw ();
  73. _GLIBCXX_PURE int pcount() const throw ();
  74. protected:
  75. virtual int_type overflow(int_type __c = _Traits::eof());
  76. virtual int_type pbackfail(int_type __c = _Traits::eof());
  77. virtual int_type underflow();
  78. virtual _Base* setbuf(char* __buf, streamsize __n);
  79. virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
  80. ios_base::openmode __mode
  81. = ios_base::in | ios_base::out);
  82. virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
  83. = ios_base::in | ios_base::out);
  84. private:
  85. strstreambuf&
  86. operator=(const strstreambuf&);
  87. strstreambuf(const strstreambuf&);
  88. // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
  89. char* _M_alloc(size_t);
  90. void _M_free(char*);
  91. // Helper function used in constructors.
  92. void _M_setup(char* __get, char* __put, streamsize __n) throw ();
  93. private:
  94. // Data members.
  95. void* (*_M_alloc_fun)(size_t);
  96. void (*_M_free_fun)(void*);
  97. bool _M_dynamic : 1;
  98. bool _M_frozen : 1;
  99. bool _M_constant : 1;
  100. };
  101. // Class istrstream, an istream that manages a strstreambuf.
  102. class istrstream : public basic_istream<char>
  103. {
  104. public:
  105. explicit istrstream(char*);
  106. explicit istrstream(const char*);
  107. istrstream(char* , streamsize);
  108. istrstream(const char*, streamsize);
  109. virtual ~istrstream();
  110. _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
  111. char* str() throw ();
  112. private:
  113. strstreambuf _M_buf;
  114. };
  115. // Class ostrstream
  116. class ostrstream : public basic_ostream<char>
  117. {
  118. public:
  119. ostrstream();
  120. ostrstream(char*, int, ios_base::openmode = ios_base::out);
  121. virtual ~ostrstream();
  122. _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
  123. void freeze(bool = true) throw();
  124. char* str() throw ();
  125. _GLIBCXX_PURE int pcount() const throw ();
  126. private:
  127. strstreambuf _M_buf;
  128. };
  129. // Class strstream
  130. class strstream : public basic_iostream<char>
  131. {
  132. public:
  133. typedef char char_type;
  134. typedef char_traits<char>::int_type int_type;
  135. typedef char_traits<char>::pos_type pos_type;
  136. typedef char_traits<char>::off_type off_type;
  137. strstream();
  138. strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
  139. virtual ~strstream();
  140. _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
  141. void freeze(bool = true) throw ();
  142. _GLIBCXX_PURE int pcount() const throw ();
  143. char* str() throw ();
  144. private:
  145. strstreambuf _M_buf;
  146. };
  147. _GLIBCXX_END_NAMESPACE_VERSION
  148. } // namespace
  149. #endif