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