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