strstream 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Backward-compat support -*- C++ -*-
  2. // Copyright (C) 2001, 2002, 2004, 2005, 2009, 2010
  3. // Free Software Foundation, Inc.
  4. //
  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)
  9. // any later version.
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // Under Section 7 of GPL version 3, you are granted additional
  15. // permissions described in the GCC Runtime Library Exception, version
  16. // 3.1, as published by the Free Software Foundation.
  17. // You should have received a copy of the GNU General Public License and
  18. // a copy of the GCC Runtime Library Exception along with this program;
  19. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. // <http://www.gnu.org/licenses/>.
  21. /*
  22. * Copyright (c) 1998
  23. * Silicon Graphics Computer Systems, Inc.
  24. *
  25. * Permission to use, copy, modify, distribute and sell this software
  26. * and its documentation for any purpose is hereby granted without fee,
  27. * provided that the above copyright notice appear in all copies and
  28. * that both that copyright notice and this permission notice appear
  29. * in supporting documentation. Silicon Graphics makes no
  30. * representations about the suitability of this software for any
  31. * purpose. It is provided "as is" without express or implied warranty.
  32. */
  33. // WARNING: The classes defined in this header are DEPRECATED. This
  34. // header is defined in section D.7.1 of the C++ standard, and it
  35. // MAY BE REMOVED in a future standard revision. One should use the
  36. // header <sstream> instead.
  37. #ifndef _BACKWARD_STRSTREAM
  38. #define _BACKWARD_STRSTREAM
  39. #include "backward_warning.h"
  40. #include <iosfwd>
  41. #include <ios>
  42. #include <istream>
  43. #include <ostream>
  44. #include <string>
  45. _GLIBCXX_BEGIN_NAMESPACE(std)
  46. // Class strstreambuf, a streambuf class that manages an array of char.
  47. // Note that this class is not a template.
  48. class strstreambuf : public basic_streambuf<char, char_traits<char> >
  49. {
  50. public:
  51. // Types.
  52. typedef char_traits<char> _Traits;
  53. typedef basic_streambuf<char, _Traits> _Base;
  54. public:
  55. // Constructor, destructor
  56. explicit strstreambuf(streamsize __initial_capacity = 0);
  57. strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
  58. strstreambuf(char* __get, streamsize __n, char* __put = 0);
  59. strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
  60. strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
  61. strstreambuf(const char* __get, streamsize __n);
  62. strstreambuf(const signed char* __get, streamsize __n);
  63. strstreambuf(const unsigned char* __get, streamsize __n);
  64. virtual ~strstreambuf();
  65. public:
  66. void freeze(bool = true);
  67. char* str();
  68. int pcount() const;
  69. protected:
  70. virtual int_type overflow(int_type __c = _Traits::eof());
  71. virtual int_type pbackfail(int_type __c = _Traits::eof());
  72. virtual int_type underflow();
  73. virtual _Base* setbuf(char* __buf, streamsize __n);
  74. virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
  75. ios_base::openmode __mode
  76. = ios_base::in | ios_base::out);
  77. virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
  78. = ios_base::in | ios_base::out);
  79. private:
  80. strstreambuf&
  81. operator=(const strstreambuf&);
  82. strstreambuf(const strstreambuf&);
  83. // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
  84. char* _M_alloc(size_t);
  85. void _M_free(char*);
  86. // Helper function used in constructors.
  87. void _M_setup(char* __get, char* __put, streamsize __n);
  88. private:
  89. // Data members.
  90. void* (*_M_alloc_fun)(size_t);
  91. void (*_M_free_fun)(void*);
  92. bool _M_dynamic : 1;
  93. bool _M_frozen : 1;
  94. bool _M_constant : 1;
  95. };
  96. // Class istrstream, an istream that manages a strstreambuf.
  97. class istrstream : public basic_istream<char>
  98. {
  99. public:
  100. explicit istrstream(char*);
  101. explicit istrstream(const char*);
  102. istrstream(char* , streamsize);
  103. istrstream(const char*, streamsize);
  104. virtual ~istrstream();
  105. strstreambuf* rdbuf() const;
  106. char* str();
  107. private:
  108. strstreambuf _M_buf;
  109. };
  110. // Class ostrstream
  111. class ostrstream : public basic_ostream<char>
  112. {
  113. public:
  114. ostrstream();
  115. ostrstream(char*, int, ios_base::openmode = ios_base::out);
  116. virtual ~ostrstream();
  117. strstreambuf* rdbuf() const;
  118. void freeze(bool = true);
  119. char* str();
  120. int pcount() const;
  121. private:
  122. strstreambuf _M_buf;
  123. };
  124. // Class strstream
  125. class strstream : public basic_iostream<char>
  126. {
  127. public:
  128. typedef char char_type;
  129. typedef char_traits<char>::int_type int_type;
  130. typedef char_traits<char>::pos_type pos_type;
  131. typedef char_traits<char>::off_type off_type;
  132. strstream();
  133. strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
  134. virtual ~strstream();
  135. strstreambuf* rdbuf() const;
  136. void freeze(bool = true);
  137. int pcount() const;
  138. char* str();
  139. private:
  140. strstreambuf _M_buf;
  141. };
  142. _GLIBCXX_END_NAMESPACE
  143. #endif