libstdc++
|
00001 // Backward-compat support -*- C++ -*- 00002 00003 // Copyright (C) 2001-2013 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /* 00026 * Copyright (c) 1998 00027 * Silicon Graphics Computer Systems, Inc. 00028 * 00029 * Permission to use, copy, modify, distribute and sell this software 00030 * and its documentation for any purpose is hereby granted without fee, 00031 * provided that the above copyright notice appear in all copies and 00032 * that both that copyright notice and this permission notice appear 00033 * in supporting documentation. Silicon Graphics makes no 00034 * representations about the suitability of this software for any 00035 * purpose. It is provided "as is" without express or implied warranty. 00036 */ 00037 00038 // WARNING: The classes defined in this header are DEPRECATED. This 00039 // header is defined in section D.7.1 of the C++ standard, and it 00040 // MAY BE REMOVED in a future standard revision. One should use the 00041 // header <sstream> instead. 00042 00043 /** @file backward/strstream 00044 * This is an internal header file, included by other library headers. 00045 * Do not attempt to use it directly. @headername{sstream} 00046 */ 00047 00048 #ifndef _BACKWARD_STRSTREAM 00049 #define _BACKWARD_STRSTREAM 00050 00051 #include "backward_warning.h" 00052 #include <iosfwd> 00053 #include <ios> 00054 #include <istream> 00055 #include <ostream> 00056 #include <string> 00057 00058 namespace std _GLIBCXX_VISIBILITY(default) 00059 { 00060 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00061 00062 // Class strstreambuf, a streambuf class that manages an array of char. 00063 // Note that this class is not a template. 00064 class strstreambuf : public basic_streambuf<char, char_traits<char> > 00065 { 00066 public: 00067 // Types. 00068 typedef char_traits<char> _Traits; 00069 typedef basic_streambuf<char, _Traits> _Base; 00070 00071 public: 00072 // Constructor, destructor 00073 explicit strstreambuf(streamsize __initial_capacity = 0); 00074 strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*)); 00075 00076 strstreambuf(char* __get, streamsize __n, char* __put = 0) throw (); 00077 strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0) throw (); 00078 strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0) throw (); 00079 00080 strstreambuf(const char* __get, streamsize __n) throw (); 00081 strstreambuf(const signed char* __get, streamsize __n) throw (); 00082 strstreambuf(const unsigned char* __get, streamsize __n) throw (); 00083 00084 virtual ~strstreambuf(); 00085 00086 public: 00087 void freeze(bool = true) throw (); 00088 char* str() throw (); 00089 _GLIBCXX_PURE int pcount() const throw (); 00090 00091 protected: 00092 virtual int_type overflow(int_type __c = _Traits::eof()); 00093 virtual int_type pbackfail(int_type __c = _Traits::eof()); 00094 virtual int_type underflow(); 00095 virtual _Base* setbuf(char* __buf, streamsize __n); 00096 virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir, 00097 ios_base::openmode __mode 00098 = ios_base::in | ios_base::out); 00099 virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 00100 = ios_base::in | ios_base::out); 00101 00102 private: 00103 strstreambuf& 00104 operator=(const strstreambuf&); 00105 00106 strstreambuf(const strstreambuf&); 00107 00108 // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun. 00109 char* _M_alloc(size_t); 00110 void _M_free(char*); 00111 00112 // Helper function used in constructors. 00113 void _M_setup(char* __get, char* __put, streamsize __n) throw (); 00114 00115 private: 00116 // Data members. 00117 void* (*_M_alloc_fun)(size_t); 00118 void (*_M_free_fun)(void*); 00119 00120 bool _M_dynamic : 1; 00121 bool _M_frozen : 1; 00122 bool _M_constant : 1; 00123 }; 00124 00125 // Class istrstream, an istream that manages a strstreambuf. 00126 class istrstream : public basic_istream<char> 00127 { 00128 public: 00129 explicit istrstream(char*); 00130 explicit istrstream(const char*); 00131 istrstream(char* , streamsize); 00132 istrstream(const char*, streamsize); 00133 virtual ~istrstream(); 00134 00135 _GLIBCXX_CONST strstreambuf* rdbuf() const throw (); 00136 char* str() throw (); 00137 00138 private: 00139 strstreambuf _M_buf; 00140 }; 00141 00142 // Class ostrstream 00143 class ostrstream : public basic_ostream<char> 00144 { 00145 public: 00146 ostrstream(); 00147 ostrstream(char*, int, ios_base::openmode = ios_base::out); 00148 virtual ~ostrstream(); 00149 00150 _GLIBCXX_CONST strstreambuf* rdbuf() const throw (); 00151 void freeze(bool = true) throw(); 00152 char* str() throw (); 00153 _GLIBCXX_PURE int pcount() const throw (); 00154 00155 private: 00156 strstreambuf _M_buf; 00157 }; 00158 00159 // Class strstream 00160 class strstream : public basic_iostream<char> 00161 { 00162 public: 00163 typedef char char_type; 00164 typedef char_traits<char>::int_type int_type; 00165 typedef char_traits<char>::pos_type pos_type; 00166 typedef char_traits<char>::off_type off_type; 00167 00168 strstream(); 00169 strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out); 00170 virtual ~strstream(); 00171 00172 _GLIBCXX_CONST strstreambuf* rdbuf() const throw (); 00173 void freeze(bool = true) throw (); 00174 _GLIBCXX_PURE int pcount() const throw (); 00175 char* str() throw (); 00176 00177 private: 00178 strstreambuf _M_buf; 00179 }; 00180 00181 _GLIBCXX_END_NAMESPACE_VERSION 00182 } // namespace 00183 00184 #endif