2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
23 #ifndef _STLP_INTERNAL_STREAMBUF
24 #include <stl/_streambuf.h>
27 #include <istream> // Includes <ostream>, <ios>, <iosfwd>
29 #ifndef _STLP_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 strstreambuf : public basic_streambuf<char, char_traits<char> >
48 class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> >
52 typedef char_traits<char> _Traits;
53 typedef basic_streambuf<char, char_traits<char> > _Base;
54 typedef void* (*__alloc_fn)(size_t);
55 typedef void (*__free_fn)(void*);
56 public: // Constructor, destructor
58 explicit strstreambuf(streamsize _Initial_capacity = 0);
60 _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn);
62 _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0);
63 _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
64 _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
66 _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n);
67 _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n);
68 _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n);
70 virtual ~strstreambuf();
72 public: // strstreambuf operations.
73 _STLP_DECLSPEC void freeze(bool = true);
74 _STLP_DECLSPEC char* str();
75 _STLP_DECLSPEC int pcount() const;
77 protected: // Overridden virtual member functions.
78 virtual int_type overflow(int_type __c = _Traits::eof());
79 virtual int_type pbackfail(int_type __c = _Traits::eof());
80 virtual int_type underflow();
81 virtual _Base* setbuf(char* __buf, streamsize __n);
82 virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
83 ios_base::openmode __mode
84 = ios_base::in | ios_base::out);
85 virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
86 = ios_base::in | ios_base::out);
88 private: // Helper functions.
89 // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
90 char* _M_alloc(size_t);
91 inline void _M_free(char*);
93 // Helper function used in constructors.
94 void _M_setup(char* __get, char* __put, streamsize __n);
95 private: // Data members.
96 __alloc_fn _M_alloc_fun;
97 __free_fn _M_free_fun;
100 bool _M_constant : 1;
102 char* _pfrozenendsave;
103 char* _pgetfrozenendsave;
107 inline strstreambuf::~strstreambuf()
110 if (_M_dynamic && !_M_frozen)
113 _M_free_fun(eback());
118 if (_M_dynamic && !_M_frozen)
123 inline void strstreambuf::_M_free(char* p)
133 //----------------------------------------------------------------------
134 // Class istrstream, an istream that manages a strstreambuf.
137 NONSHARABLE_CLASS (istrstream) : public basic_istream<char, char_traits<char> >
139 class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> >
143 _STLP_DECLSPEC explicit istrstream(char*);
144 _STLP_DECLSPEC explicit istrstream(const char*);
145 _STLP_DECLSPEC istrstream(char* , streamsize);
146 _STLP_DECLSPEC istrstream(const char*, streamsize);
147 virtual ~istrstream();
149 _STLP_DECLSPEC strstreambuf* rdbuf() const;
150 _STLP_DECLSPEC char* str();
156 //----------------------------------------------------------------------
159 NONSHARABLE_CLASS (ostrstream) : public basic_ostream<char, char_traits<char> >
161 class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
165 _STLP_DECLSPEC ostrstream();
166 _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out);
167 virtual ~ostrstream();
169 _STLP_DECLSPEC strstreambuf* rdbuf() const;
170 _STLP_DECLSPEC void freeze(bool = true);
171 _STLP_DECLSPEC char* str();
172 _STLP_DECLSPEC int pcount() const;
178 //----------------------------------------------------------------------
181 NONSHARABLE_CLASS (strstream) : public basic_iostream<char, char_traits<char> >
183 class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> >
187 typedef char char_type;
188 typedef char_traits<char>::int_type int_type;
189 typedef char_traits<char>::pos_type pos_type;
190 typedef char_traits<char>::off_type off_type;
192 _STLP_DECLSPEC strstream();
193 _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
194 virtual ~strstream();
196 _STLP_DECLSPEC strstreambuf* rdbuf() const;
197 _STLP_DECLSPEC void freeze(bool = true);
198 _STLP_DECLSPEC int pcount() const;
199 _STLP_DECLSPEC char* str();