libstdc++
strstream
Go to the documentation of this file.
00001 // Backward-compat support -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2015 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 strstream
00044  *  This is a Standard C++ Library header.
00045  */
00046 
00047 #ifndef _BACKWARD_STRSTREAM
00048 #define _BACKWARD_STRSTREAM
00049 
00050 #include "backward_warning.h"
00051 #include <iosfwd>
00052 #include <ios>
00053 #include <istream>
00054 #include <ostream>
00055 #include <string>
00056 
00057 namespace std _GLIBCXX_VISIBILITY(default)
00058 {
00059 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00060 
00061   // Class strstreambuf, a streambuf class that manages an array of char.
00062   // Note that this class is not a template.
00063   class strstreambuf : public basic_streambuf<char, char_traits<char> >
00064   {
00065   public:
00066     // Types.
00067     typedef char_traits<char>              _Traits;
00068     typedef basic_streambuf<char, _Traits> _Base;
00069 
00070   public:
00071     // 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) throw ();
00076     strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0) throw ();
00077     strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0) throw ();
00078 
00079     strstreambuf(const char* __get, streamsize __n) throw ();
00080     strstreambuf(const signed char* __get, streamsize __n) throw ();
00081     strstreambuf(const unsigned char* __get, streamsize __n) throw ();
00082 
00083     virtual ~strstreambuf();
00084 
00085   public:
00086     void freeze(bool = true) throw ();
00087     char* str() throw ();
00088     _GLIBCXX_PURE int pcount() const throw ();
00089 
00090   protected:
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:
00102     strstreambuf&
00103     operator=(const strstreambuf&);
00104 
00105     strstreambuf(const strstreambuf&);
00106 
00107     // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
00108     char* _M_alloc(size_t);
00109     void  _M_free(char*);
00110 
00111     // Helper function used in constructors.
00112     void _M_setup(char* __get, char* __put, streamsize __n) throw ();
00113 
00114   private:
00115     // Data members.
00116     void* (*_M_alloc_fun)(size_t);
00117     void  (*_M_free_fun)(void*);
00118 
00119     bool _M_dynamic  : 1;
00120     bool _M_frozen   : 1;
00121     bool _M_constant : 1;
00122   };
00123 
00124   // Class istrstream, an istream that manages a strstreambuf.
00125   class istrstream : public basic_istream<char>
00126   {
00127   public:
00128     explicit istrstream(char*);
00129     explicit istrstream(const char*);
00130     istrstream(char* , streamsize);
00131     istrstream(const char*, streamsize);
00132     virtual ~istrstream();
00133 
00134     _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
00135     char* str() throw ();
00136 
00137   private:
00138     strstreambuf _M_buf;
00139   };
00140 
00141   // Class ostrstream
00142   class ostrstream : public basic_ostream<char>
00143   {
00144   public:
00145     ostrstream();
00146     ostrstream(char*, int, ios_base::openmode = ios_base::out);
00147     virtual ~ostrstream();
00148 
00149     _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
00150     void freeze(bool = true) throw();
00151     char* str() throw ();
00152     _GLIBCXX_PURE int pcount() const throw ();
00153 
00154   private:
00155     strstreambuf _M_buf;
00156   };
00157 
00158   // Class strstream
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     _GLIBCXX_CONST strstreambuf* rdbuf() const throw ();
00172     void freeze(bool = true) throw ();
00173     _GLIBCXX_PURE int pcount() const throw ();
00174     char* str() throw ();
00175 
00176   private:
00177     strstreambuf _M_buf;
00178   };
00179 
00180 _GLIBCXX_END_NAMESPACE_VERSION
00181 } // namespace
00182 
00183 #endif