Home | History | Annotate | Download | only in backward
      1 // Backward-compat support -*- C++ -*-
      2 
      3 // Copyright (C) 2001, 2002, 2004, 2005, 2009 Free Software Foundation, Inc.
      4 //
      5 // This file is part of the GNU ISO C++ Library.  This library is free
      6 // software; you can redistribute it and/or modify it under the
      7 // terms of the GNU General Public License as published by the
      8 // Free Software Foundation; either version 3, or (at your option)
      9 // any later version.
     10 
     11 // This library is distributed in the hope that it will be useful,
     12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 // GNU General Public License for more details.
     15 
     16 // Under Section 7 of GPL version 3, you are granted additional
     17 // permissions described in the GCC Runtime Library Exception, version
     18 // 3.1, as published by the Free Software Foundation.
     19 
     20 // You should have received a copy of the GNU General Public License and
     21 // a copy of the GCC Runtime Library Exception along with this program;
     22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23 // <http://www.gnu.org/licenses/>.
     24 
     25 /*
     26  * Copyright (c) 1998
     27  * Silicon Graphics Computer Systems, Inc.
     28  *
     29  * Permission to use, copy, modify, distribute and sell this software
     30  * and its documentation for any purpose is hereby granted without fee,
     31  * provided that the above copyright notice appear in all copies and
     32  * that both that copyright notice and this permission notice appear
     33  * in supporting documentation.  Silicon Graphics makes no
     34  * representations about the suitability of this software for any
     35  * purpose.  It is provided "as is" without express or implied warranty.
     36  */
     37 
     38 // WARNING: The classes defined in this header are DEPRECATED.  This
     39 // header is defined in section D.7.1 of the C++ standard, and it
     40 // MAY BE REMOVED in a future standard revision.  One should use the
     41 // header <sstream> instead.
     42 
     43 #ifndef _GLIBCXX_STRSTREAM
     44 #define _GLIBCXX_STRSTREAM
     45 
     46 #include "backward_warning.h"
     47 #include <iosfwd>
     48 #include <ios>
     49 #include <istream>
     50 #include <ostream>
     51 #include <string>
     52 
     53 _GLIBCXX_BEGIN_NAMESPACE(std)
     54 
     55   // Class strstreambuf, a streambuf class that manages an array of char.
     56   // Note that this class is not a template.
     57   class strstreambuf : public basic_streambuf<char, char_traits<char> >
     58   {
     59   public:
     60     // Types.
     61     typedef char_traits<char>              _Traits;
     62     typedef basic_streambuf<char, _Traits> _Base;
     63 
     64   public:
     65     // Constructor, destructor
     66     explicit strstreambuf(streamsize __initial_capacity = 0);
     67     strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
     68 
     69     strstreambuf(char* __get, streamsize __n, char* __put = 0);
     70     strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
     71     strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
     72 
     73     strstreambuf(const char* __get, streamsize __n);
     74     strstreambuf(const signed char* __get, streamsize __n);
     75     strstreambuf(const unsigned char* __get, streamsize __n);
     76 
     77     virtual ~strstreambuf();
     78 
     79   public:
     80     void freeze(bool = true);
     81     char* str();
     82     int pcount() const;
     83 
     84   protected:
     85     virtual int_type overflow(int_type __c  = _Traits::eof());
     86     virtual int_type pbackfail(int_type __c = _Traits::eof());
     87     virtual int_type underflow();
     88     virtual _Base* setbuf(char* __buf, streamsize __n);
     89     virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
     90 			     ios_base::openmode __mode
     91 			     = ios_base::in | ios_base::out);
     92     virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
     93 			     = ios_base::in | ios_base::out);
     94 
     95   private:
     96     strstreambuf&
     97     operator=(const strstreambuf&);
     98 
     99     strstreambuf(const strstreambuf&);
    100 
    101     // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
    102     char* _M_alloc(size_t);
    103     void  _M_free(char*);
    104 
    105     // Helper function used in constructors.
    106     void _M_setup(char* __get, char* __put, streamsize __n);
    107 
    108   private:
    109     // Data members.
    110     void* (*_M_alloc_fun)(size_t);
    111     void  (*_M_free_fun)(void*);
    112 
    113     bool _M_dynamic  : 1;
    114     bool _M_frozen   : 1;
    115     bool _M_constant : 1;
    116   };
    117 
    118   // Class istrstream, an istream that manages a strstreambuf.
    119   class istrstream : public basic_istream<char>
    120   {
    121   public:
    122     explicit istrstream(char*);
    123     explicit istrstream(const char*);
    124     istrstream(char* , streamsize);
    125     istrstream(const char*, streamsize);
    126     virtual ~istrstream();
    127 
    128     strstreambuf* rdbuf() const;
    129     char* str();
    130 
    131   private:
    132     strstreambuf _M_buf;
    133   };
    134 
    135   // Class ostrstream
    136   class ostrstream : public basic_ostream<char>
    137   {
    138   public:
    139     ostrstream();
    140     ostrstream(char*, int, ios_base::openmode = ios_base::out);
    141     virtual ~ostrstream();
    142 
    143     strstreambuf* rdbuf() const;
    144     void freeze(bool = true);
    145     char* str();
    146     int pcount() const;
    147 
    148   private:
    149     strstreambuf _M_buf;
    150   };
    151 
    152   // Class strstream
    153   class strstream : public basic_iostream<char>
    154   {
    155   public:
    156     typedef char                        char_type;
    157     typedef char_traits<char>::int_type int_type;
    158     typedef char_traits<char>::pos_type pos_type;
    159     typedef char_traits<char>::off_type off_type;
    160 
    161     strstream();
    162     strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
    163     virtual ~strstream();
    164 
    165     strstreambuf* rdbuf() const;
    166     void freeze(bool = true);
    167     int pcount() const;
    168     char* str();
    169 
    170   private:
    171     strstreambuf _M_buf;
    172   };
    173 
    174 _GLIBCXX_END_NAMESPACE
    175 
    176 #endif
    177