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