w_compat_strstream.h

00001 /*
00002  * This stl "compatability" strstream implementation is
00003  * included with shore for use with newer c++ compilers whic
00004  * do not provide the strstream functionality.
00005  *
00006  * stringstreams are not usable for the functions shore needs,
00007  * since they provide no way of writing to and reading from
00008  * memory objects.
00009  *
00010  * This file should not be changed, except to incorporate bug
00011  * fixes from the SGI STL code.
00012  */
00013 
00014 /*
00015  * Copyright (c) 1998
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */ 
00026 
00027 // WARNING: The classes defined in this header are DEPRECATED.  This
00028 // header is defined in section D.7.1 of the C++ standard, and it
00029 // MAY BE REMOVED in a future standard revision.  You should use the
00030 // header <sstream> instead.
00031 
00032 
00033 #ifndef __SGI_STL_STRSTREAM_W_COMPAT_
00034 #define __SGI_STL_STRSTREAM_W_COMPAT_
00035 
00036 #if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
00037 #error This header file requires the -LANG:std option
00038 #endif
00039 
00040 #include <istream>              // Includes <ostream>, <ios>, <iosfwd>
00041 #include <streambuf>
00042 #include <ostream>
00043 #include <iostream>
00044 #include <ios>
00045 
00046 /** \brief  A namespace for implementations of old-style streambufs.
00047  */
00048 namespace shore_compat {
00049 
00050 using namespace std;
00051 
00052 
00053 /**\brief Streambuf class that manages an array of char.
00054  *
00055  * Note that this class is not a template.
00056  */
00057 class strstreambuf : public basic_streambuf<char, char_traits<char> >
00058 {
00059 public:                         // Types.
00060   typedef char_traits<char>              _Traits;
00061   typedef basic_streambuf<char, _Traits> _Base;
00062 
00063 public:                         // Constructor, destructor
00064   explicit strstreambuf(streamsize __initial_capacity = 0);
00065   strstreambuf(void* (*__alloc)(size_t), void (*__free)(void*));
00066 
00067   strstreambuf(char* __get, streamsize __n, char* __put = 0);
00068   strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
00069   strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
00070 
00071   strstreambuf(const char* __get, streamsize __n);
00072   strstreambuf(const signed char* __get, streamsize __n);
00073   strstreambuf(const unsigned char* __get, streamsize __n);
00074 
00075   virtual ~strstreambuf();
00076 
00077 public:                         // strstreambuf operations.
00078   char* str();
00079   int pcount() const;
00080 
00081 protected:                      // Overridden virtual member functions.
00082   virtual int_type overflow(int_type __c  = _Traits::eof());
00083   virtual int_type pbackfail(int_type __c = _Traits::eof());
00084   virtual int_type underflow();
00085   virtual _Base* setbuf(char* __buf, streamsize __n);
00086   virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
00087                            ios_base::openmode __mode 
00088                                       = ios_base::in | ios_base::out);
00089   virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 
00090                                       = ios_base::in | ios_base::out);
00091 
00092 private:                        // Helper functions.
00093   // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
00094   char* _M_alloc(size_t);
00095   void  _M_free(char*);
00096 
00097   // Helper function used in constructors.
00098   void _M_setup(char* __get, char* __put, streamsize __n);
00099 
00100 private:                        // Data members.
00101   void* (*_M_alloc_fun)(size_t);
00102   void  (*_M_free_fun)(void*);
00103 
00104   bool _M_dynamic  : 1;
00105   bool _M_constant : 1;
00106 };
00107 
00108 /// Class istrstream, an istream that manages a strstreambuf.
00109 class istrstream : public basic_istream<char>
00110 {
00111 public:
00112   explicit istrstream(char*);
00113   explicit istrstream(const char*);
00114   istrstream(char* , streamsize);
00115   istrstream(const char*, streamsize);
00116   virtual ~istrstream();
00117   
00118   strstreambuf* rdbuf() const;
00119   char* str();
00120 
00121 private:
00122   strstreambuf _M_buf;
00123 };
00124 
00125 
00126 /// Class ostrstream, an ostream that manages a strstreambuf.
00127 class ostrstream : public basic_ostream<char>
00128 {
00129 public:
00130   ostrstream();
00131   ostrstream(char*, int, ios_base::openmode = ios_base::out);
00132   virtual ~ostrstream();
00133 
00134   strstreambuf* rdbuf() const;
00135   char* str();
00136   int pcount() const;
00137 
00138 private:
00139   strstreambuf _M_buf;
00140 };
00141 
00142 
00143 } /* namespace shore compat */
00144 
00145 #endif /* __SGI_STL_STRSTREAM_W_COMPAT */

Generated on Wed Jul 7 17:22:32 2010 for Shore Storage Manager by  doxygen 1.4.7