williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@2
|
3 |
* Copyright (c) 1999
|
williamr@2
|
4 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
5 |
*
|
williamr@2
|
6 |
* Copyright (c) 1999
|
williamr@2
|
7 |
* Boris Fomitchev
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
10 |
* or implied. Any use is at your own risk.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
13 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
14 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
15 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
16 |
* modified is included with the above copyright notice.
|
williamr@2
|
17 |
*
|
williamr@2
|
18 |
*/
|
williamr@2
|
19 |
|
williamr@2
|
20 |
|
williamr@2
|
21 |
// This header defines classes basic_stringbuf, basic_istringstream,
|
williamr@2
|
22 |
// basic_ostringstream, and basic_stringstream. These classes
|
williamr@2
|
23 |
// represent streamsbufs and streams whose sources or destinations are
|
williamr@2
|
24 |
// C++ strings.
|
williamr@2
|
25 |
|
williamr@2
|
26 |
#ifndef _STLP_SSTREAM_H
|
williamr@2
|
27 |
#define _STLP_SSTREAM_H
|
williamr@2
|
28 |
|
williamr@2
|
29 |
#ifndef _STLP_INTERNAL_STREAMBUF
|
williamr@2
|
30 |
# include <stl/_streambuf.h>
|
williamr@2
|
31 |
#endif
|
williamr@2
|
32 |
|
williamr@2
|
33 |
#ifndef _STLP_INTERNAL_ISTREAM_H
|
williamr@2
|
34 |
# include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
|
williamr@2
|
35 |
#endif
|
williamr@2
|
36 |
|
williamr@2
|
37 |
#ifndef _STLP_STRING_H
|
williamr@2
|
38 |
# include <stl/_string.h>
|
williamr@2
|
39 |
#endif
|
williamr@2
|
40 |
|
williamr@2
|
41 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
42 |
|
williamr@2
|
43 |
//----------------------------------------------------------------------
|
williamr@2
|
44 |
// This version of basic_stringbuf relies on the internal details of
|
williamr@2
|
45 |
// basic_string. It relies on the fact that, in this implementation,
|
williamr@2
|
46 |
// basic_string's iterators are pointers. It also assumes (as allowed
|
williamr@2
|
47 |
// by the standard) that _CharT is a POD type.
|
williamr@2
|
48 |
|
williamr@2
|
49 |
// We have a very small buffer for the put area, just so that we don't
|
williamr@2
|
50 |
// have to use append() for every sputc. Conceptually, the buffer
|
williamr@2
|
51 |
// immediately follows the end of the underlying string. We use this
|
williamr@2
|
52 |
// buffer when appending to write-only streambufs, but we don't use it
|
williamr@2
|
53 |
// for read-write streambufs.
|
williamr@2
|
54 |
|
williamr@2
|
55 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
56 |
#ifdef __SYMBIAN32__
|
williamr@2
|
57 |
NONSHARABLE_CLASS ( basic_stringbuf ) : public basic_streambuf<_CharT, _Traits>
|
williamr@2
|
58 |
#else
|
williamr@2
|
59 |
class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
|
williamr@2
|
60 |
#endif
|
williamr@2
|
61 |
{
|
williamr@2
|
62 |
public: // Typedefs.
|
williamr@2
|
63 |
typedef _CharT char_type;
|
williamr@2
|
64 |
typedef typename _Traits::int_type int_type;
|
williamr@2
|
65 |
typedef typename _Traits::pos_type pos_type;
|
williamr@2
|
66 |
typedef typename _Traits::off_type off_type;
|
williamr@2
|
67 |
typedef _Traits traits_type;
|
williamr@2
|
68 |
|
williamr@2
|
69 |
typedef basic_streambuf<_CharT, _Traits> _Base;
|
williamr@2
|
70 |
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Self;
|
williamr@2
|
71 |
typedef basic_string<_CharT, _Traits, _Alloc> _String;
|
williamr@2
|
72 |
|
williamr@2
|
73 |
public: // Constructors, destructor.
|
williamr@2
|
74 |
_STLP_DECLSPEC explicit basic_stringbuf(ios_base::openmode __mode
|
williamr@2
|
75 |
= ios_base::in | ios_base::out);
|
williamr@2
|
76 |
_STLP_DECLSPEC explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode
|
williamr@2
|
77 |
= ios_base::in | ios_base::out);
|
williamr@2
|
78 |
_STLP_DECLSPEC virtual ~basic_stringbuf();
|
williamr@2
|
79 |
|
williamr@2
|
80 |
public: // Get or set the string.
|
williamr@2
|
81 |
_String str() const {
|
williamr@2
|
82 |
if ( _M_mode & ios_base::out )
|
williamr@2
|
83 |
_M_append_buffer();
|
williamr@2
|
84 |
return _M_str;
|
williamr@2
|
85 |
}
|
williamr@2
|
86 |
_STLP_DECLSPEC void str(const _String& __s);
|
williamr@2
|
87 |
|
williamr@2
|
88 |
protected: // Overridden virtual member functions.
|
williamr@2
|
89 |
virtual int_type underflow();
|
williamr@2
|
90 |
virtual int_type uflow();
|
williamr@2
|
91 |
virtual int_type pbackfail(int_type __c);
|
williamr@2
|
92 |
virtual int_type overflow(int_type __c);
|
williamr@2
|
93 |
int_type pbackfail() {return pbackfail(_Traits::eof());}
|
williamr@2
|
94 |
int_type overflow() {return overflow(_Traits::eof());}
|
williamr@2
|
95 |
|
williamr@2
|
96 |
virtual streamsize xsputn(const char_type* __s, streamsize __n);
|
williamr@2
|
97 |
virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
|
williamr@2
|
98 |
|
williamr@2
|
99 |
virtual _Base* setbuf(_CharT* __buf, streamsize __n);
|
williamr@2
|
100 |
virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
|
williamr@2
|
101 |
ios_base::openmode __mode
|
williamr@2
|
102 |
= ios_base::in | ios_base::out);
|
williamr@2
|
103 |
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
|
williamr@2
|
104 |
= ios_base::in | ios_base::out);
|
williamr@2
|
105 |
ios_base::openmode _M_mode;
|
williamr@2
|
106 |
|
williamr@2
|
107 |
private: // Helper functions.
|
williamr@2
|
108 |
// Append the internal buffer to the string if necessary.
|
williamr@2
|
109 |
void _M_append_buffer() const;
|
williamr@2
|
110 |
void _M_set_ptrs();
|
williamr@2
|
111 |
|
williamr@2
|
112 |
private:
|
williamr@2
|
113 |
mutable basic_string<_CharT, _Traits, _Alloc> _M_str;
|
williamr@2
|
114 |
|
williamr@2
|
115 |
enum _JustName { _S_BufSiz = 8 };
|
williamr@2
|
116 |
_CharT _M_Buf[ 8 /* _S_BufSiz */];
|
williamr@2
|
117 |
};
|
williamr@2
|
118 |
|
williamr@2
|
119 |
# if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@2
|
120 |
_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<char, char_traits<char>, allocator<char> >;
|
williamr@2
|
121 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@2
|
122 |
_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
|
williamr@2
|
123 |
# endif
|
williamr@2
|
124 |
# endif /* _STLP_USE_TEMPLATE_EXPORT */
|
williamr@2
|
125 |
|
williamr@2
|
126 |
//----------------------------------------------------------------------
|
williamr@2
|
127 |
// Class basic_istringstream, an input stream that uses a stringbuf.
|
williamr@2
|
128 |
|
williamr@2
|
129 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
130 |
#ifdef __SYMBIAN32__
|
williamr@2
|
131 |
NONSHARABLE_CLASS ( basic_istringstream ) : public basic_istream<_CharT, _Traits>
|
williamr@2
|
132 |
#else
|
williamr@2
|
133 |
class basic_istringstream : public basic_istream<_CharT, _Traits>
|
williamr@2
|
134 |
#endif
|
williamr@2
|
135 |
{
|
williamr@2
|
136 |
public: // Typedefs
|
williamr@2
|
137 |
typedef typename _Traits::char_type char_type;
|
williamr@2
|
138 |
typedef typename _Traits::int_type int_type;
|
williamr@2
|
139 |
typedef typename _Traits::pos_type pos_type;
|
williamr@2
|
140 |
typedef typename _Traits::off_type off_type;
|
williamr@2
|
141 |
typedef _Traits traits_type;
|
williamr@2
|
142 |
|
williamr@2
|
143 |
typedef basic_ios<_CharT, _Traits> _Basic_ios;
|
williamr@2
|
144 |
typedef basic_istream<_CharT, _Traits> _Base;
|
williamr@2
|
145 |
typedef basic_string<_CharT, _Traits, _Alloc> _String;
|
williamr@2
|
146 |
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
|
williamr@2
|
147 |
|
williamr@2
|
148 |
public: // Constructors, destructor.
|
williamr@2
|
149 |
basic_istringstream(ios_base::openmode __mode = ios_base::in);
|
williamr@2
|
150 |
basic_istringstream(const _String& __str,
|
williamr@2
|
151 |
ios_base::openmode __mode = ios_base::in);
|
williamr@2
|
152 |
~basic_istringstream();
|
williamr@2
|
153 |
|
williamr@2
|
154 |
public: // Member functions
|
williamr@2
|
155 |
|
williamr@2
|
156 |
basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
|
williamr@2
|
157 |
{ return __CONST_CAST(_Buf*,&_M_buf); }
|
williamr@2
|
158 |
|
williamr@2
|
159 |
_String str() const { return _M_buf.str(); }
|
williamr@2
|
160 |
void str(const _String& __s) { _M_buf.str(__s); }
|
williamr@2
|
161 |
|
williamr@2
|
162 |
private:
|
williamr@2
|
163 |
basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
|
williamr@2
|
164 |
};
|
williamr@2
|
165 |
|
williamr@2
|
166 |
|
williamr@2
|
167 |
//----------------------------------------------------------------------
|
williamr@2
|
168 |
// Class basic_ostringstream, an output stream that uses a stringbuf.
|
williamr@2
|
169 |
|
williamr@2
|
170 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
171 |
#ifdef __SYMBIAN32__
|
williamr@2
|
172 |
NONSHARABLE_CLASS ( basic_ostringstream ) : public basic_ostream<_CharT, _Traits>
|
williamr@2
|
173 |
#else
|
williamr@2
|
174 |
class basic_ostringstream : public basic_ostream<_CharT, _Traits>
|
williamr@2
|
175 |
#endif
|
williamr@2
|
176 |
{
|
williamr@2
|
177 |
public: // Typedefs
|
williamr@2
|
178 |
typedef typename _Traits::char_type char_type;
|
williamr@2
|
179 |
typedef typename _Traits::int_type int_type;
|
williamr@2
|
180 |
typedef typename _Traits::pos_type pos_type;
|
williamr@2
|
181 |
typedef typename _Traits::off_type off_type;
|
williamr@2
|
182 |
typedef _Traits traits_type;
|
williamr@2
|
183 |
|
williamr@2
|
184 |
typedef basic_ios<_CharT, _Traits> _Basic_ios;
|
williamr@2
|
185 |
typedef basic_ostream<_CharT, _Traits> _Base;
|
williamr@2
|
186 |
typedef basic_string<_CharT, _Traits, _Alloc> _String;
|
williamr@2
|
187 |
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
|
williamr@2
|
188 |
|
williamr@2
|
189 |
public: // Constructors, destructor.
|
williamr@2
|
190 |
basic_ostringstream(ios_base::openmode __mode = ios_base::out);
|
williamr@2
|
191 |
basic_ostringstream(const _String& __str,
|
williamr@2
|
192 |
ios_base::openmode __mode = ios_base::out);
|
williamr@2
|
193 |
~basic_ostringstream();
|
williamr@2
|
194 |
|
williamr@2
|
195 |
public: // Member functions.
|
williamr@2
|
196 |
|
williamr@2
|
197 |
basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
|
williamr@2
|
198 |
{ return __CONST_CAST(_Buf*,&_M_buf); }
|
williamr@2
|
199 |
|
williamr@2
|
200 |
_String str() const { return _M_buf.str(); }
|
williamr@2
|
201 |
void str(const _String& __s) { _M_buf.str(__s); } // dwa 02/07/00 - BUG STOMPER DAVE
|
williamr@2
|
202 |
|
williamr@2
|
203 |
|
williamr@2
|
204 |
private:
|
williamr@2
|
205 |
basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
|
williamr@2
|
206 |
};
|
williamr@2
|
207 |
|
williamr@2
|
208 |
|
williamr@2
|
209 |
//----------------------------------------------------------------------
|
williamr@2
|
210 |
// Class basic_stringstream, a bidirectional stream that uses a stringbuf.
|
williamr@2
|
211 |
|
williamr@2
|
212 |
template <class _CharT, class _Traits, class _Alloc>
|
williamr@2
|
213 |
#ifdef __SYMBIAN32__
|
williamr@2
|
214 |
NONSHARABLE_CLASS ( basic_stringstream ) : public basic_iostream<_CharT, _Traits>
|
williamr@2
|
215 |
#else
|
williamr@2
|
216 |
class basic_stringstream : public basic_iostream<_CharT, _Traits>
|
williamr@2
|
217 |
#endif
|
williamr@2
|
218 |
{
|
williamr@2
|
219 |
public: // Typedefs
|
williamr@2
|
220 |
typedef typename _Traits::char_type char_type;
|
williamr@2
|
221 |
typedef typename _Traits::int_type int_type;
|
williamr@2
|
222 |
typedef typename _Traits::pos_type pos_type;
|
williamr@2
|
223 |
typedef typename _Traits::off_type off_type;
|
williamr@2
|
224 |
typedef _Traits traits_type;
|
williamr@2
|
225 |
|
williamr@2
|
226 |
typedef basic_ios<_CharT, _Traits> _Basic_ios;
|
williamr@2
|
227 |
typedef basic_iostream<_CharT, _Traits> _Base;
|
williamr@2
|
228 |
typedef basic_string<_CharT, _Traits, _Alloc> _String;
|
williamr@2
|
229 |
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
|
williamr@2
|
230 |
|
williamr@2
|
231 |
typedef ios_base::openmode openmode;
|
williamr@2
|
232 |
|
williamr@2
|
233 |
public: // Constructors, destructor.
|
williamr@2
|
234 |
_STLP_DECLSPEC basic_stringstream(openmode __mod = ios_base::in | ios_base::out);
|
williamr@2
|
235 |
_STLP_DECLSPEC basic_stringstream(const _String& __str,
|
williamr@2
|
236 |
openmode __mod = ios_base::in | ios_base::out);
|
williamr@2
|
237 |
~basic_stringstream();
|
williamr@2
|
238 |
|
williamr@2
|
239 |
public: // Member functions.
|
williamr@2
|
240 |
|
williamr@2
|
241 |
basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
|
williamr@2
|
242 |
{ return __CONST_CAST(_Buf*,&_M_buf); }
|
williamr@2
|
243 |
|
williamr@2
|
244 |
_String str() const { return _M_buf.str(); }
|
williamr@2
|
245 |
void str(const _String& __s) { _M_buf.str(__s); }
|
williamr@2
|
246 |
|
williamr@2
|
247 |
private:
|
williamr@2
|
248 |
basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
|
williamr@2
|
249 |
};
|
williamr@2
|
250 |
|
williamr@2
|
251 |
|
williamr@2
|
252 |
# if defined (_STLP_USE_TEMPLATE_EXPORT)
|
williamr@2
|
253 |
_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<char, char_traits<char>, allocator<char> >;
|
williamr@2
|
254 |
_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<char, char_traits<char>, allocator<char> >;
|
williamr@2
|
255 |
_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<char, char_traits<char>, allocator<char> >;
|
williamr@2
|
256 |
# if !defined (_STLP_NO_WCHAR_T)
|
williamr@2
|
257 |
_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
|
williamr@2
|
258 |
_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
|
williamr@2
|
259 |
_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
|
williamr@2
|
260 |
# endif
|
williamr@2
|
261 |
# endif /* _STLP_USE_TEMPLATE_EXPORT */
|
williamr@2
|
262 |
|
williamr@2
|
263 |
_STLP_END_NAMESPACE
|
williamr@2
|
264 |
|
williamr@2
|
265 |
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
|
williamr@2
|
266 |
# include <stl/_sstream.c>
|
williamr@2
|
267 |
# endif
|
williamr@2
|
268 |
|
williamr@2
|
269 |
#endif /* _STLP_SSTREAM_H */
|
williamr@2
|
270 |
|
williamr@2
|
271 |
// Local Variables:
|
williamr@2
|
272 |
// mode:C++
|
williamr@2
|
273 |
// End:
|