# strstream

    00001 // Backward-compat support -*- C++ -*-
    00002
    00003 // Copyright (C) 2001 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 2, 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 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 /*
    00031  * Copyright (c) 1998
    00032  * Silicon Graphics Computer Systems, Inc.
    00033  *
    00034  * Permission to use, copy, modify, distribute and sell this software
    00035  * and its documentation for any purpose is hereby granted without fee,
    00036  * provided that the above copyright notice appear in all copies and
    00037  * that both that copyright notice and this permission notice appear
    00038  * in supporting documentation.  Silicon Graphics makes no
    00039  * representations about the suitability of this software for any
    00040  * purpose.  It is provided "as is" without express or implied warranty.
    00041  */
    00042
    00043 // WARNING: The classes defined in this header are DEPRECATED.  This
    00044 // header is defined in section D.7.1 of the C++ standard, and it
    00045 // MAY BE REMOVED in a future standard revision.  You should use the
    00046 // header <sstream> instead.
    00047
    00048 #ifndef __SGI_STL_STRSTREAM
    00049 #define __SGI_STL_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
    00059 {
    00060
    00061 //----------------------------------------------------------------------
    00062 // Class strstreambuf, a streambuf class that manages an array of char.
    00063 // Note that this class is not a template.
    00064
    00065 class strstreambuf : public basic_streambuf<char, char_traits<char> >
    00066 {
    00067 public:                         // Types.
    00068   typedef char_traits<char>              _Traits;
    00069   typedef basic_streambuf<char, _Traits> _Base;
    00070
    00071 public:                         // Constructor, destructor
    00072   explicit strstreambuf(streamsize __initial_capacity = 0);
    00073   strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
    00074
    00075   strstreambuf(char* __get, streamsize __n, char* __put = 0);
    00076   strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
    00077   strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
    00078
    00079   strstreambuf(const char* __get, streamsize __n);
    00080   strstreambuf(const signed char* __get, streamsize __n);
    00081   strstreambuf(const unsigned char* __get, streamsize __n);
    00082
    00083   virtual ~strstreambuf();
    00084
    00085 public:                         // strstreambuf operations.
    00086   void freeze(bool = true);
    00087   char* str();
    00088   int pcount() const;
    00089
    00090 protected:                      // Overridden virtual member functions.
    00091   virtual int_type overflow(int_type __c  = _Traits::eof());
    00092   virtual int_type pbackfail(int_type __c = _Traits::eof());
    00093   virtual int_type underflow();
    00094   virtual _Base* setbuf(char* __buf, streamsize __n);
    00095   virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
    00096                            ios_base::openmode __mode
    00097                                       = ios_base::in | ios_base::out);
    00098   virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
    00099                                       = ios_base::in | ios_base::out);
    00100
    00101 private:                        // Helper functions.
    00102   // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
    00103   char* _M_alloc(size_t);
    00104   void  _M_free(char*);
    00105
    00106   // Helper function used in constructors.
    00107   void _M_setup(char* __get, char* __put, streamsize __n);
    00108
    00109 private:                        // Data members.
    00110   void* (*_M_alloc_fun)(size_t);
    00111   void  (*_M_free_fun)(void*);
    00112
    00113   bool _M_dynamic  : 1;
    00114   bool _M_frozen   : 1;
    00115   bool _M_constant : 1;
    00116 };
    00117
    00118 //----------------------------------------------------------------------
    00119 // Class istrstream, an istream that manages a strstreambuf.
    00120
    00121 class istrstream : public basic_istream<char>
    00122 {
    00123 public:
    00124   explicit istrstream(char*);
    00125   explicit istrstream(const char*);
    00126   istrstream(char* , streamsize);
    00127   istrstream(const char*, streamsize);
    00128   virtual ~istrstream();
    00129
    00130   strstreambuf* rdbuf() const;
    00131   char* str();
    00132
    00133 private:
    00134   strstreambuf _M_buf;
    00135 };
    00136
    00137 //----------------------------------------------------------------------
    00138 // Class ostrstream
    00139
    00140 class ostrstream : public basic_ostream<char>
    00141 {
    00142 public:
    00143   ostrstream();
    00144   ostrstream(char*, int, ios_base::openmode = ios_base::out);
    00145   virtual ~ostrstream();
    00146
    00147   strstreambuf* rdbuf() const;
    00148   void freeze(bool = true);
    00149   char* str();
    00150   int pcount() const;
    00151
    00152 private:
    00153   strstreambuf _M_buf;
    00154 };
    00155
    00156 //----------------------------------------------------------------------
    00157 // Class strstream
    00158
    00159 class strstream : public basic_iostream<char>
    00160 {
    00161 public:
    00162   typedef char                        char_type;
    00163   typedef char_traits<char>::int_type int_type;
    00164   typedef char_traits<char>::pos_type pos_type;
    00165   typedef char_traits<char>::off_type off_type;
    00166
    00167   strstream();
    00168   strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
    00169   virtual ~strstream();
    00170
    00171   strstreambuf* rdbuf() const;
    00172   void freeze(bool = true);
    00173   int pcount() const;
    00174   char* str();
    00175
    00176 private:
    00177   strstreambuf _M_buf;
    00178 };
    00179
    00180 } // namespace std
    00181
    00182 #endif /* __SGI_STL_STRSTREAM */
    00183
    00184 // Local Variables:
    00185 // mode:C++
    00186 // End:
    00187
    00188