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