3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
18 #ifndef _STLP_INTERNAL_STRSTREAM
19 #define _STLP_INTERNAL_STRSTREAM
21 #ifndef _STLP_INTERNAL_STREAMBUF
22 # include <stl/_streambuf.h>
25 #ifndef _STLP_INTERNAL_ISTREAM
26 # include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
29 #ifndef _STLP_INTERNAL_STRING_H
30 # include <stl/_string.h>
35 #ifndef _STLP_USE_NAMESPACES
36 # define strstream _STLP_strstream
37 # define ostrstream _STLP_ostrstream
38 # define istrstream _STLP_istrstream
39 # define strstreambuf _STLP_strstreambuf
42 //----------------------------------------------------------------------
43 // Class strstreambuf, a streambuf class that manages an array of char.
44 // Note that this class is not a template.
46 class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> > {
48 typedef char_traits<char> _Traits;
49 typedef basic_streambuf<char, char_traits<char> > _Base;
50 typedef void* (*__alloc_fn)(size_t);
51 typedef void (*__free_fn)(void*);
52 public: // Constructor, destructor
54 explicit strstreambuf(streamsize _Initial_capacity = 0);
56 strstreambuf(__alloc_fn, __free_fn);
58 strstreambuf(char* __get, streamsize __n, char* __put = 0);
59 strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
60 strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
62 strstreambuf(const char* __get, streamsize __n);
63 strstreambuf(const signed char* __get, streamsize __n);
64 strstreambuf(const unsigned char* __get, streamsize __n);
66 virtual ~strstreambuf();
68 public: // strstreambuf operations.
69 void freeze(bool = true);
73 protected: // Overridden virtual member functions.
74 virtual int_type overflow(int_type __c = _Traits::eof());
75 virtual int_type pbackfail(int_type __c = _Traits::eof());
76 virtual int_type underflow();
77 virtual _Base* setbuf(char* __buf, streamsize __n);
78 virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
79 ios_base::openmode __mode
80 = ios_base::in | ios_base::out);
81 virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
82 = ios_base::in | ios_base::out);
84 private: // Helper functions.
85 // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
86 char* _M_alloc(size_t);
89 // Helper function used in constructors.
90 void _M_setup(char* __get, char* __put, streamsize __n);
91 private: // Data members.
92 __alloc_fn _M_alloc_fun;
93 __free_fn _M_free_fun;
99 //----------------------------------------------------------------------
100 // Class istrstream, an istream that manages a strstreambuf.
102 class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> > {
104 explicit istrstream(char*);
105 explicit istrstream(const char*);
106 istrstream(char* , streamsize);
107 istrstream(const char*, streamsize);
108 virtual ~istrstream();
110 strstreambuf* rdbuf() const;
117 //----------------------------------------------------------------------
120 class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
124 ostrstream(char*, int, ios_base::openmode = ios_base::out);
125 virtual ~ostrstream();
127 strstreambuf* rdbuf() const;
128 void freeze(bool = true);
136 //----------------------------------------------------------------------
139 class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> > {
141 typedef char char_type;
142 typedef char_traits<char>::int_type int_type;
143 typedef char_traits<char>::pos_type pos_type;
144 typedef char_traits<char>::off_type off_type;
147 strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
148 virtual ~strstream();
150 strstreambuf* rdbuf() const;
151 void freeze(bool = true);
158 //explicitely defined as private to avoid warnings:
159 strstream(strstream const&);
160 strstream& operator = (strstream const&);
165 #endif /* _STLP_INTERNAL_STRSTREAM */