# strstream

    00001 // Backward-compat support -*- C++ -*-
    00002
    00003 // Copyright (C) 2001, 2002, 2004, 2005, 2009 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 #ifndef _GLIBCXX_STRSTREAM
    00044 #define _GLIBCXX_STRSTREAM
    00045
    00046 #include "backward_warning.h"
    00047 #include <iosfwd>
    00048 #include <ios>
    00049 #include <istream>
    00050 #include <ostream>
    00051 #include <string>
    00052
    00053 _GLIBCXX_BEGIN_NAMESPACE(std)
    00054
    00055   // Class strstreambuf, a streambuf class that manages an array of char.
    00056   // Note that this class is not a template.
    00057   class strstreambuf : public basic_streambuf<char, char_traits<char> >
    00058   {
    00059   public:
    00060     // Types.
    00061     typedef char_traits<char>              _Traits;
    00062     typedef basic_streambuf<char, _Traits> _Base;
    00063
    00064   public:
    00065     // Constructor, destructor
    00066     explicit strstreambuf(streamsize __initial_capacity = 0);
    00067     strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
    00068
    00069     strstreambuf(char* __get, streamsize __n, char* __put = 0);
    00070     strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
    00071     strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
    00072
    00073     strstreambuf(const char* __get, streamsize __n);
    00074     strstreambuf(const signed char* __get, streamsize __n);
    00075     strstreambuf(const unsigned char* __get, streamsize __n);
    00076
    00077     virtual ~strstreambuf();
    00078
    00079   public:
    00080     void freeze(bool = true);
    00081     char* str();
    00082     int pcount() const;
    00083
    00084   protected:
    00085     virtual int_type overflow(int_type __c  = _Traits::eof());
    00086     virtual int_type pbackfail(int_type __c = _Traits::eof());
    00087     virtual int_type underflow();
    00088     virtual _Base* setbuf(char* __buf, streamsize __n);
    00089     virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
    00090                  ios_base::openmode __mode
    00091                  = ios_base::in | ios_base::out);
    00092     virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
    00093                  = ios_base::in | ios_base::out);
    00094
    00095   private:
    00096     strstreambuf&
    00097     operator=(const strstreambuf&);
    00098
    00099     strstreambuf(const strstreambuf&);
    00100
    00101     // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
    00102     char* _M_alloc(size_t);
    00103     void  _M_free(char*);
    00104
    00105     // Helper function used in constructors.
    00106     void _M_setup(char* __get, char* __put, streamsize __n);
    00107
    00108   private:
    00109     // 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   // Class istrstream, an istream that manages a strstreambuf.
    00119   class istrstream : public basic_istream<char>
    00120   {
    00121   public:
    00122     explicit istrstream(char*);
    00123     explicit istrstream(const char*);
    00124     istrstream(char* , streamsize);
    00125     istrstream(const char*, streamsize);
    00126     virtual ~istrstream();
    00127
    00128     strstreambuf* rdbuf() const;
    00129     char* str();
    00130
    00131   private:
    00132     strstreambuf _M_buf;
    00133   };
    00134
    00135   // Class ostrstream
    00136   class ostrstream : public basic_ostream<char>
    00137   {
    00138   public:
    00139     ostrstream();
    00140     ostrstream(char*, int, ios_base::openmode = ios_base::out);
    00141     virtual ~ostrstream();
    00142
    00143     strstreambuf* rdbuf() const;
    00144     void freeze(bool = true);
    00145     char* str();
    00146     int pcount() const;
    00147
    00148   private:
    00149     strstreambuf _M_buf;
    00150   };
    00151
    00152   // Class strstream
    00153   class strstream : public basic_iostream<char>
    00154   {
    00155   public:
    00156     typedef char                        char_type;
    00157     typedef char_traits<char>::int_type int_type;
    00158     typedef char_traits<char>::pos_type pos_type;
    00159     typedef char_traits<char>::off_type off_type;
    00160
    00161     strstream();
    00162     strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
    00163     virtual ~strstream();
    00164
    00165     strstreambuf* rdbuf() const;
    00166     void freeze(bool = true);
    00167     int pcount() const;
    00168     char* str();
    00169
    00170   private:
    00171     strstreambuf _M_buf;
    00172   };
    00173
    00174 _GLIBCXX_END_NAMESPACE
    00175
    00176 #endif