strstream

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

Generated on 19 Jun 2018 for libstdc++ by  doxygen 1.6.1