williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
williamr@4
|
3 |
*
|
williamr@4
|
4 |
* Copyright (c) 1999
|
williamr@4
|
5 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
6 |
*
|
williamr@4
|
7 |
* Copyright (c) 1999
|
williamr@4
|
8 |
* Boris Fomitchev
|
williamr@4
|
9 |
*
|
williamr@4
|
10 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
11 |
* or implied. Any use is at your own risk.
|
williamr@4
|
12 |
*
|
williamr@4
|
13 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
14 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
15 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
16 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
17 |
* modified is included with the above copyright notice.
|
williamr@4
|
18 |
*
|
williamr@4
|
19 |
*/
|
williamr@4
|
20 |
#ifndef _STLP_INTERNAL_STREAMBUF
|
williamr@4
|
21 |
#define _STLP_INTERNAL_STREAMBUF
|
williamr@4
|
22 |
|
williamr@4
|
23 |
#ifndef _STLP_IOS_BASE_H
|
williamr@4
|
24 |
#include <stl/_ios_base.h> // Needed for ios_base bitfield members.
|
williamr@4
|
25 |
// <ios_base> includes <iosfwd>.
|
williamr@4
|
26 |
#endif
|
williamr@4
|
27 |
|
williamr@4
|
28 |
#ifndef _STLP_STDIO_FILE_H
|
williamr@4
|
29 |
#include <stl/_stdio_file.h> // Declaration of struct FILE, and of
|
williamr@4
|
30 |
// functions to manipulate it.
|
williamr@4
|
31 |
#endif
|
williamr@4
|
32 |
|
williamr@4
|
33 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
34 |
|
williamr@4
|
35 |
//----------------------------------------------------------------------
|
williamr@4
|
36 |
// Class basic_streambuf<>, the base class of the streambuf hierarchy.
|
williamr@4
|
37 |
|
williamr@4
|
38 |
// A basic_streambuf<> manages an input (get) area and an output (put)
|
williamr@4
|
39 |
// area. Each is described by three pointers: a beginning, an end, and a
|
williamr@4
|
40 |
// current position. basic_streambuf<> contains some very simple member
|
williamr@4
|
41 |
// functions that manipulate those six pointers, but almost all of the real
|
williamr@4
|
42 |
// functionality gets delegated to protected virtual member functions.
|
williamr@4
|
43 |
// All of the public member functions are inline, and most of the protected
|
williamr@4
|
44 |
// member functions are virtual.
|
williamr@4
|
45 |
|
williamr@4
|
46 |
// Although basic_streambuf<> is not abstract, it is useful only as a base
|
williamr@4
|
47 |
// class. Its virtual member functions have default definitions such that
|
williamr@4
|
48 |
// reading from a basic_streambuf<> will always yield EOF, and writing to a
|
williamr@4
|
49 |
// basic_streambuf<> will always fail.
|
williamr@4
|
50 |
|
williamr@4
|
51 |
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
|
williamr@4
|
52 |
// The default is declared in header <iosfwd>, and it isn't declared here
|
williamr@4
|
53 |
// because C++ language rules do not allow it to be declared twice.
|
williamr@4
|
54 |
|
williamr@4
|
55 |
template <class _CharT, class _Traits>
|
williamr@4
|
56 |
#ifdef __SYMBIAN32__
|
williamr@4
|
57 |
class basic_streambuf
|
williamr@4
|
58 |
#else
|
williamr@4
|
59 |
class basic_streambuf
|
williamr@4
|
60 |
#endif
|
williamr@4
|
61 |
{
|
williamr@4
|
62 |
friend class basic_istream<_CharT, _Traits>;
|
williamr@4
|
63 |
friend class basic_ostream<_CharT, _Traits>;
|
williamr@4
|
64 |
|
williamr@4
|
65 |
public: // Typedefs.
|
williamr@4
|
66 |
typedef _CharT char_type;
|
williamr@4
|
67 |
typedef typename _Traits::int_type int_type;
|
williamr@4
|
68 |
typedef typename _Traits::pos_type pos_type;
|
williamr@4
|
69 |
typedef typename _Traits::off_type off_type;
|
williamr@4
|
70 |
typedef _Traits traits_type;
|
williamr@4
|
71 |
|
williamr@4
|
72 |
private: // Data members.
|
williamr@4
|
73 |
|
williamr@4
|
74 |
char_type* _M_gbegin; // Beginning of get area
|
williamr@4
|
75 |
char_type* _M_gnext; // Current position within the get area
|
williamr@4
|
76 |
char_type* _M_gend; // End of get area
|
williamr@4
|
77 |
|
williamr@4
|
78 |
char_type* _M_pbegin; // Beginning of put area
|
williamr@4
|
79 |
char_type* _M_pnext; // Current position within the put area
|
williamr@4
|
80 |
char_type* _M_pend; // End of put area
|
williamr@4
|
81 |
|
williamr@4
|
82 |
locale _M_locale; // The streambuf's locale object
|
williamr@4
|
83 |
|
williamr@4
|
84 |
public: // Extension: locking, for thread safety.
|
williamr@4
|
85 |
_STLP_mutex _M_lock;
|
williamr@4
|
86 |
|
williamr@4
|
87 |
public: // Destructor.
|
williamr@4
|
88 |
_STLP_DECLSPEC virtual ~basic_streambuf();
|
williamr@4
|
89 |
|
williamr@4
|
90 |
protected: // The default constructor.
|
williamr@4
|
91 |
_STLP_DECLSPEC basic_streambuf();
|
williamr@4
|
92 |
|
williamr@4
|
93 |
protected: // Protected interface to the get area.
|
williamr@4
|
94 |
char_type* eback() const { return _M_gbegin; } // Beginning
|
williamr@4
|
95 |
char_type* gptr() const { return _M_gnext; } // Current position
|
williamr@4
|
96 |
char_type* egptr() const { return _M_gend; } // End
|
williamr@4
|
97 |
|
williamr@4
|
98 |
void gbump(int __n) { _M_gnext += __n; }
|
williamr@4
|
99 |
void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) {
|
williamr@4
|
100 |
_M_gbegin = __gbegin;
|
williamr@4
|
101 |
_M_gnext = __gnext;
|
williamr@4
|
102 |
_M_gend = __gend;
|
williamr@4
|
103 |
}
|
williamr@4
|
104 |
|
williamr@4
|
105 |
public:
|
williamr@4
|
106 |
// An alternate public interface to the above functions
|
williamr@4
|
107 |
// which allows us to avoid using templated friends which
|
williamr@4
|
108 |
// are not supported on some compilers.
|
williamr@4
|
109 |
|
williamr@4
|
110 |
char_type* _M_eback() const { return eback(); }
|
williamr@4
|
111 |
char_type* _M_gptr() const { return gptr(); }
|
williamr@4
|
112 |
char_type* _M_egptr() const { return egptr(); }
|
williamr@4
|
113 |
void _M_gbump(int __n) { gbump(__n); }
|
williamr@4
|
114 |
void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
|
williamr@4
|
115 |
{ setg(__gbegin, __gnext, __gend); }
|
williamr@4
|
116 |
|
williamr@4
|
117 |
protected: // Protected interface to the put area
|
williamr@4
|
118 |
|
williamr@4
|
119 |
char_type* pbase() const { return _M_pbegin; } // Beginning
|
williamr@4
|
120 |
char_type* pptr() const { return _M_pnext; } // Current position
|
williamr@4
|
121 |
char_type* epptr() const { return _M_pend; } // End
|
williamr@4
|
122 |
|
williamr@4
|
123 |
void pbump(int __n) { _M_pnext += __n; }
|
williamr@4
|
124 |
void setp(char_type* __pbegin, char_type* __pend) {
|
williamr@4
|
125 |
_M_pbegin = __pbegin;
|
williamr@4
|
126 |
_M_pnext = __pbegin;
|
williamr@4
|
127 |
_M_pend = __pend;
|
williamr@4
|
128 |
}
|
williamr@4
|
129 |
|
williamr@4
|
130 |
protected: // Virtual buffer management functions.
|
williamr@4
|
131 |
|
williamr@4
|
132 |
_STLP_DECLSPEC virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
|
williamr@4
|
133 |
|
williamr@4
|
134 |
// Alters the stream position, using an integer offset. In this
|
williamr@4
|
135 |
// class seekoff does nothing; subclasses are expected to override it.
|
williamr@4
|
136 |
_STLP_DECLSPEC virtual pos_type seekoff(off_type, ios_base::seekdir,
|
williamr@4
|
137 |
ios_base::openmode = ios_base::in | ios_base::out);
|
williamr@4
|
138 |
|
williamr@4
|
139 |
// Alters the stream position, using a previously obtained streampos. In
|
williamr@4
|
140 |
// this class seekpos does nothing; subclasses are expected to override it.
|
williamr@4
|
141 |
_STLP_DECLSPEC virtual pos_type
|
williamr@4
|
142 |
seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
|
williamr@4
|
143 |
|
williamr@4
|
144 |
// Synchronizes (i.e. flushes) the buffer. All subclasses are expected to
|
williamr@4
|
145 |
// override this virtual member function.
|
williamr@4
|
146 |
_STLP_DECLSPEC virtual int sync();
|
williamr@4
|
147 |
|
williamr@4
|
148 |
|
williamr@4
|
149 |
public: // Buffer management.
|
williamr@4
|
150 |
basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n)
|
williamr@4
|
151 |
{ return this->setbuf(__s, __n); }
|
williamr@4
|
152 |
|
williamr@4
|
153 |
pos_type pubseekoff(off_type __offset, ios_base::seekdir __way,
|
williamr@4
|
154 |
ios_base::openmode __mod = ios_base::in | ios_base::out)
|
williamr@4
|
155 |
{ return this->seekoff(__offset, __way, __mod); }
|
williamr@4
|
156 |
|
williamr@4
|
157 |
pos_type pubseekpos(pos_type __sp,
|
williamr@4
|
158 |
ios_base::openmode __mod = ios_base::in | ios_base::out)
|
williamr@4
|
159 |
{ return this->seekpos(__sp, __mod); }
|
williamr@4
|
160 |
|
williamr@4
|
161 |
int pubsync() { return this->sync(); }
|
williamr@4
|
162 |
|
williamr@4
|
163 |
protected: // Virtual get area functions, as defined in
|
williamr@4
|
164 |
// 17.5.2.4.3 and 17.5.2.4.4 of the standard.
|
williamr@4
|
165 |
// Returns a lower bound on the number of characters that we can read,
|
williamr@4
|
166 |
// with underflow, before reaching end of file. (-1 is a special value:
|
williamr@4
|
167 |
// it means that underflow will fail.) Most subclasses should probably
|
williamr@4
|
168 |
// override this virtual member function.
|
williamr@4
|
169 |
_STLP_DECLSPEC virtual streamsize showmanyc();
|
williamr@4
|
170 |
|
williamr@4
|
171 |
// Reads up to __n characters. Return value is the number of
|
williamr@4
|
172 |
// characters read.
|
williamr@4
|
173 |
_STLP_DECLSPEC virtual streamsize xsgetn(char_type* __s, streamsize __n);
|
williamr@4
|
174 |
|
williamr@4
|
175 |
// Called when there is no read position, i.e. when gptr() is null
|
williamr@4
|
176 |
// or when gptr() >= egptr(). Subclasses are expected to override
|
williamr@4
|
177 |
// this virtual member function.
|
williamr@4
|
178 |
_STLP_DECLSPEC virtual int_type underflow();
|
williamr@4
|
179 |
|
williamr@4
|
180 |
// Similar to underflow(), but used for unbuffered input. Most
|
williamr@4
|
181 |
// subclasses should probably override this virtual member function.
|
williamr@4
|
182 |
_STLP_DECLSPEC virtual int_type uflow();
|
williamr@4
|
183 |
|
williamr@4
|
184 |
// Called when there is no putback position, i.e. when gptr() is null
|
williamr@4
|
185 |
// or when gptr() == eback(). All subclasses are expected to override
|
williamr@4
|
186 |
// this virtual member function.
|
williamr@4
|
187 |
_STLP_DECLSPEC virtual int_type pbackfail(int_type = traits_type::eof());
|
williamr@4
|
188 |
|
williamr@4
|
189 |
protected: // Virtual put area functions, as defined in
|
williamr@4
|
190 |
// 27.5.2.4.5 of the standard.
|
williamr@4
|
191 |
|
williamr@4
|
192 |
// Writes up to __n characters. Return value is the number of characters
|
williamr@4
|
193 |
// written.
|
williamr@4
|
194 |
_STLP_DECLSPEC virtual streamsize xsputn(const char_type* __s, streamsize __n);
|
williamr@4
|
195 |
|
williamr@4
|
196 |
// Extension: writes up to __n copies of __c. Return value is the number
|
williamr@4
|
197 |
// of characters written.
|
williamr@4
|
198 |
_STLP_DECLSPEC virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
|
williamr@4
|
199 |
|
williamr@4
|
200 |
// Called when there is no write position. All subclasses are expected to
|
williamr@4
|
201 |
// override this virtual member function.
|
williamr@4
|
202 |
_STLP_DECLSPEC virtual int_type overflow(int_type = traits_type::eof());
|
williamr@4
|
203 |
|
williamr@4
|
204 |
public: // Public members for writing characters.
|
williamr@4
|
205 |
// Write a single character.
|
williamr@4
|
206 |
int_type sputc(char_type __c) {
|
williamr@4
|
207 |
return ((_M_pnext < _M_pend) ? _Traits::to_int_type(*_M_pnext++ = __c)
|
williamr@4
|
208 |
: this->overflow(_Traits::to_int_type(__c)));
|
williamr@4
|
209 |
}
|
williamr@4
|
210 |
|
williamr@4
|
211 |
// Write __n characters.
|
williamr@4
|
212 |
streamsize sputn(const char_type* __s, streamsize __n)
|
williamr@4
|
213 |
{ return this->xsputn(__s, __n); }
|
williamr@4
|
214 |
|
williamr@4
|
215 |
// Extension: write __n copies of __c.
|
williamr@4
|
216 |
streamsize _M_sputnc(char_type __c, streamsize __n)
|
williamr@4
|
217 |
{ return this->_M_xsputnc(__c, __n); }
|
williamr@4
|
218 |
|
williamr@4
|
219 |
private: // Helper functions.
|
williamr@4
|
220 |
_STLP_DECLSPEC int_type _M_snextc_aux();
|
williamr@4
|
221 |
|
williamr@4
|
222 |
|
williamr@4
|
223 |
public: // Public members for reading characters.
|
williamr@4
|
224 |
streamsize in_avail() {
|
williamr@4
|
225 |
return (_M_gnext < _M_gend) ? (_M_gend - _M_gnext) : this->showmanyc();
|
williamr@4
|
226 |
}
|
williamr@4
|
227 |
|
williamr@4
|
228 |
// Advance to the next character and return it.
|
williamr@4
|
229 |
int_type snextc() {
|
williamr@4
|
230 |
return ( _M_gend - _M_gnext > 1 ?
|
williamr@4
|
231 |
_Traits::to_int_type(*++_M_gnext) :
|
williamr@4
|
232 |
this->_M_snextc_aux());
|
williamr@4
|
233 |
}
|
williamr@4
|
234 |
|
williamr@4
|
235 |
// Return the current character and advance to the next.
|
williamr@4
|
236 |
int_type sbumpc() {
|
williamr@4
|
237 |
return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext++)
|
williamr@4
|
238 |
: this->uflow();
|
williamr@4
|
239 |
}
|
williamr@4
|
240 |
|
williamr@4
|
241 |
// Return the current character without advancing to the next.
|
williamr@4
|
242 |
int_type sgetc() {
|
williamr@4
|
243 |
return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext)
|
williamr@4
|
244 |
: this->underflow();
|
williamr@4
|
245 |
}
|
williamr@4
|
246 |
|
williamr@4
|
247 |
streamsize sgetn(char_type* __s, streamsize __n)
|
williamr@4
|
248 |
{ return this->xsgetn(__s, __n); }
|
williamr@4
|
249 |
|
williamr@4
|
250 |
int_type sputbackc(char_type __c) {
|
williamr@4
|
251 |
return ((_M_gbegin < _M_gnext) && _Traits::eq(__c, *(_M_gnext - 1)))
|
williamr@4
|
252 |
? _Traits::to_int_type(*--_M_gnext)
|
williamr@4
|
253 |
: this->pbackfail(_Traits::to_int_type(__c));
|
williamr@4
|
254 |
}
|
williamr@4
|
255 |
|
williamr@4
|
256 |
int_type sungetc() {
|
williamr@4
|
257 |
return (_M_gbegin < _M_gnext)
|
williamr@4
|
258 |
? _Traits::to_int_type(*--_M_gnext)
|
williamr@4
|
259 |
: this->pbackfail();
|
williamr@4
|
260 |
}
|
williamr@4
|
261 |
|
williamr@4
|
262 |
protected: // Virtual locale functions.
|
williamr@4
|
263 |
|
williamr@4
|
264 |
// This is a hook, called by pubimbue() just before pubimbue()
|
williamr@4
|
265 |
// sets the streambuf's locale to __loc. Note that imbue should
|
williamr@4
|
266 |
// not (and cannot, since it has no access to streambuf's private
|
williamr@4
|
267 |
// members) set the streambuf's locale itself.
|
williamr@4
|
268 |
_STLP_DECLSPEC virtual void imbue(const locale&);
|
williamr@4
|
269 |
|
williamr@4
|
270 |
public: // Locale-related functions.
|
williamr@4
|
271 |
_STLP_DECLSPEC locale pubimbue(const locale&);
|
williamr@4
|
272 |
locale getloc() const { return _M_locale; }
|
williamr@4
|
273 |
|
williamr@4
|
274 |
# ifndef _STLP_NO_ANACHRONISMS
|
williamr@4
|
275 |
void stossc() { this->sbumpc(); }
|
williamr@4
|
276 |
# endif
|
williamr@4
|
277 |
#if defined(__MVS__) || defined(__OS400__)
|
williamr@4
|
278 |
private: // Data members.
|
williamr@4
|
279 |
|
williamr@4
|
280 |
char_type* _M_gbegin; // Beginning of get area
|
williamr@4
|
281 |
char_type* _M_gnext; // Current position within the get area
|
williamr@4
|
282 |
char_type* _M_gend; // End of get area
|
williamr@4
|
283 |
|
williamr@4
|
284 |
char_type* _M_pbegin; // Beginning of put area
|
williamr@4
|
285 |
char_type* _M_pnext; // Current position within the put area
|
williamr@4
|
286 |
char_type* _M_pend; // End of put area
|
williamr@4
|
287 |
#endif
|
williamr@4
|
288 |
};
|
williamr@4
|
289 |
|
williamr@4
|
290 |
|
williamr@4
|
291 |
//----------------------------------------------------------------------
|
williamr@4
|
292 |
// Specialization: basic_streambuf<char, char_traits<char> >
|
williamr@4
|
293 |
|
williamr@4
|
294 |
// We implement basic_streambuf<char, char_traits<char> > very differently
|
williamr@4
|
295 |
// than the general basic_streambuf<> template. The main reason for this
|
williamr@4
|
296 |
// difference is a requirement in the C++ standard: the standard input
|
williamr@4
|
297 |
// and output streams cin and cout are required by default to be synchronized
|
williamr@4
|
298 |
// with the C library components stdin and stdout. This means it must be
|
williamr@4
|
299 |
// possible to synchronize a basic_streambuf<char> with a C buffer.
|
williamr@4
|
300 |
//
|
williamr@4
|
301 |
// There are two basic ways to do that. First, the streambuf could be
|
williamr@4
|
302 |
// unbuffered and delegate all buffering to stdio operations. This
|
williamr@4
|
303 |
// would be correct, but slow: it would require at least one virtual
|
williamr@4
|
304 |
// function call for every character. Second, the streambuf could use
|
williamr@4
|
305 |
// a C stdio FILE as its buffer.
|
williamr@4
|
306 |
//
|
williamr@4
|
307 |
// We choose the latter option. Every streambuf has pointers to two
|
williamr@4
|
308 |
// FILE objects, one for the get area and one for the put area. Ordinarily
|
williamr@4
|
309 |
// it just uses a FILE object as a convenient way to package the three
|
williamr@4
|
310 |
// get/put area pointers. If a basic_streambuf<char> is synchronized with
|
williamr@4
|
311 |
// a stdio stream, though, then the pointers are to a FILE object that's
|
williamr@4
|
312 |
// also used by the C library.
|
williamr@4
|
313 |
//
|
williamr@4
|
314 |
// The header <stl/_stdio_file.h> encapsulates the implementation details
|
williamr@4
|
315 |
// of struct FILE. It contains low-level inline functions that convert
|
williamr@4
|
316 |
// between whe FILE's internal representation and the three-pointer
|
williamr@4
|
317 |
// representation that basic_streambuf<> needs.
|
williamr@4
|
318 |
|
williamr@4
|
319 |
_STLP_TEMPLATE_NULL
|
williamr@4
|
320 |
#ifdef __SYMBIAN32__
|
williamr@4
|
321 |
class basic_streambuf<char, char_traits<char> >
|
williamr@4
|
322 |
#else
|
williamr@4
|
323 |
class _STLP_CLASS_DECLSPEC basic_streambuf<char, char_traits<char> >
|
williamr@4
|
324 |
#endif
|
williamr@4
|
325 |
{
|
williamr@4
|
326 |
friend class basic_istream<char, char_traits<char> >;
|
williamr@4
|
327 |
friend class basic_ostream<char, char_traits<char> >;
|
williamr@4
|
328 |
public: // Typedefs.
|
williamr@4
|
329 |
typedef char char_type;
|
williamr@4
|
330 |
typedef char_traits<char>::int_type int_type;
|
williamr@4
|
331 |
typedef char_traits<char>::pos_type pos_type;
|
williamr@4
|
332 |
typedef char_traits<char>::off_type off_type;
|
williamr@4
|
333 |
typedef char_traits<char> traits_type;
|
williamr@4
|
334 |
|
williamr@4
|
335 |
private: // Data members.
|
williamr@4
|
336 |
|
williamr@4
|
337 |
FILE* _M_get; // Reference to the get area
|
williamr@4
|
338 |
FILE* _M_put; // Reference to the put area
|
williamr@4
|
339 |
|
williamr@4
|
340 |
#if defined(__hpux)
|
williamr@4
|
341 |
_FILEX _M_default_get; // Get area, unless we're syncing with stdio.
|
williamr@4
|
342 |
_FILEX _M_default_put; // Put area, unless we're syncing with stdio.
|
williamr@4
|
343 |
#else
|
williamr@4
|
344 |
FILE _M_default_get; // Get area, unless we're syncing with stdio.
|
williamr@4
|
345 |
FILE _M_default_put; // Put area, unless we're syncing with stdio.
|
williamr@4
|
346 |
#endif
|
williamr@4
|
347 |
|
williamr@4
|
348 |
locale _M_locale;
|
williamr@4
|
349 |
|
williamr@4
|
350 |
public: // Extension: locking, for thread safety.
|
williamr@4
|
351 |
_STLP_mutex _M_lock;
|
williamr@4
|
352 |
|
williamr@4
|
353 |
public: // Destructor.
|
williamr@4
|
354 |
_STLP_DECLSPEC virtual ~basic_streambuf _STLP_PSPEC2(char, char_traits<char>) ();
|
williamr@4
|
355 |
|
williamr@4
|
356 |
public:
|
williamr@4
|
357 |
// The default constructor; defined here inline as some compilers require it
|
williamr@4
|
358 |
_STLP_DECLSPEC basic_streambuf _STLP_PSPEC2(char, char_traits<char>) ();
|
williamr@4
|
359 |
// Extension: a constructor for streambufs synchronized with C stdio files.
|
williamr@4
|
360 |
_STLP_DECLSPEC basic_streambuf _STLP_PSPEC2(char, char_traits<char>) (FILE* __get, FILE* __put);
|
williamr@4
|
361 |
|
williamr@4
|
362 |
protected: // Protected interface to the get area.
|
williamr@4
|
363 |
char_type* eback() const { return _FILE_I_begin(_M_get); }
|
williamr@4
|
364 |
char_type* gptr() const { return _FILE_I_next(_M_get); }
|
williamr@4
|
365 |
char_type* egptr() const { return _FILE_I_end(_M_get); }
|
williamr@4
|
366 |
void gbump(int __n) { _FILE_I_bump(_M_get, __n); }
|
williamr@4
|
367 |
void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
|
williamr@4
|
368 |
{
|
williamr@4
|
369 |
_FILE_I_set(_M_get, __gbegin, __gnext, __gend);
|
williamr@4
|
370 |
#ifdef __SYMBIAN32__
|
williamr@4
|
371 |
_change_input_mode();
|
williamr@4
|
372 |
#endif
|
williamr@4
|
373 |
}
|
williamr@4
|
374 |
|
williamr@4
|
375 |
public:
|
williamr@4
|
376 |
// An alternate public interface to the above functions
|
williamr@4
|
377 |
// which allows us to avoid using templated friends which
|
williamr@4
|
378 |
// are not supported on some compilers.
|
williamr@4
|
379 |
|
williamr@4
|
380 |
char_type* _M_eback() const { return _FILE_I_begin(_M_get); }
|
williamr@4
|
381 |
char_type* _M_gptr() const { return _FILE_I_next(_M_get); }
|
williamr@4
|
382 |
char_type* _M_egptr() const { return _FILE_I_end(_M_get); }
|
williamr@4
|
383 |
|
williamr@4
|
384 |
void _M_gbump(int __n) { _FILE_I_bump(_M_get, __n); }
|
williamr@4
|
385 |
void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
|
williamr@4
|
386 |
{ _FILE_I_set(_M_get, __gbegin, __gnext, __gend); }
|
williamr@4
|
387 |
|
williamr@4
|
388 |
protected: // Protected interface to the put area
|
williamr@4
|
389 |
char_type* pbase() const { return _FILE_O_begin(_M_put); }
|
williamr@4
|
390 |
char_type* pptr() const { return _FILE_O_next(_M_put); }
|
williamr@4
|
391 |
char_type* epptr() const { return _FILE_O_end(_M_put); }
|
williamr@4
|
392 |
|
williamr@4
|
393 |
void pbump(int __n) { _FILE_O_bump(_M_put, __n); }
|
williamr@4
|
394 |
void setp(char_type* __pbegin, char_type* __pend)
|
williamr@4
|
395 |
{ _FILE_O_set(_M_put, __pbegin, __pbegin, __pend); }
|
williamr@4
|
396 |
|
williamr@4
|
397 |
protected: // Virtual buffer-management functions.
|
williamr@4
|
398 |
_STLP_DECLSPEC virtual basic_streambuf<char, char_traits<char> >* setbuf(char_type*, streamsize);
|
williamr@4
|
399 |
_STLP_DECLSPEC virtual pos_type seekoff(off_type, ios_base::seekdir,
|
williamr@4
|
400 |
ios_base::openmode = ios_base::in | ios_base::out);
|
williamr@4
|
401 |
_STLP_DECLSPEC virtual pos_type
|
williamr@4
|
402 |
seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
|
williamr@4
|
403 |
_STLP_DECLSPEC virtual int sync();
|
williamr@4
|
404 |
|
williamr@4
|
405 |
public: // Buffer management.
|
williamr@4
|
406 |
basic_streambuf<char, char_traits<char> >* pubsetbuf(char_type* __s, streamsize __n)
|
williamr@4
|
407 |
{ return this->setbuf(__s, __n); }
|
williamr@4
|
408 |
|
williamr@4
|
409 |
pos_type pubseekoff(off_type __offset, ios_base::seekdir __way,
|
williamr@4
|
410 |
ios_base::openmode __mod = ios_base::in | ios_base::out)
|
williamr@4
|
411 |
{ return this->seekoff(__offset, __way, __mod); }
|
williamr@4
|
412 |
|
williamr@4
|
413 |
pos_type pubseekpos(pos_type __sp,
|
williamr@4
|
414 |
ios_base::openmode __mod = ios_base::in | ios_base::out)
|
williamr@4
|
415 |
{ return this->seekpos(__sp, __mod); }
|
williamr@4
|
416 |
|
williamr@4
|
417 |
int pubsync() { return this->sync(); }
|
williamr@4
|
418 |
|
williamr@4
|
419 |
protected: // Virtual get area functions.
|
williamr@4
|
420 |
_STLP_DECLSPEC virtual streamsize showmanyc();
|
williamr@4
|
421 |
_STLP_DECLSPEC virtual streamsize xsgetn(char_type* __s, streamsize __n);
|
williamr@4
|
422 |
_STLP_DECLSPEC virtual int_type underflow();
|
williamr@4
|
423 |
_STLP_DECLSPEC virtual int_type uflow();
|
williamr@4
|
424 |
_STLP_DECLSPEC virtual int_type pbackfail(int_type __c = traits_type::eof());
|
williamr@4
|
425 |
|
williamr@4
|
426 |
protected: // Virtual put area functions.
|
williamr@4
|
427 |
_STLP_DECLSPEC virtual streamsize xsputn(const char_type* __s, streamsize __n);
|
williamr@4
|
428 |
_STLP_DECLSPEC virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
|
williamr@4
|
429 |
_STLP_DECLSPEC virtual int_type overflow(int_type = traits_type::eof());
|
williamr@4
|
430 |
#ifdef __SYMBIAN32__
|
williamr@4
|
431 |
virtual int save_read_buffer () { return 0; }
|
williamr@4
|
432 |
virtual void _change_input_mode() {};
|
williamr@4
|
433 |
#endif
|
williamr@4
|
434 |
public: // Public members for writing characters.
|
williamr@4
|
435 |
// Write a single character.
|
williamr@4
|
436 |
int_type sputc(char_type __c) {
|
williamr@4
|
437 |
int_type __res;
|
williamr@4
|
438 |
if( _FILE_O_avail(_M_put) > 0 )
|
williamr@4
|
439 |
{
|
williamr@4
|
440 |
_FILE_O_postincr(_M_put) = __c;
|
williamr@4
|
441 |
__res = traits_type::to_int_type(__c);
|
williamr@4
|
442 |
}
|
williamr@4
|
443 |
else
|
williamr@4
|
444 |
__res = this->overflow(traits_type::to_int_type(__c));
|
williamr@4
|
445 |
return __res;
|
williamr@4
|
446 |
}
|
williamr@4
|
447 |
|
williamr@4
|
448 |
// Write __n characters.
|
williamr@4
|
449 |
streamsize sputn(const char_type* __s, streamsize __n)
|
williamr@4
|
450 |
{ return this->xsputn(__s, __n); }
|
williamr@4
|
451 |
|
williamr@4
|
452 |
// Extension: write __n copies of __c.
|
williamr@4
|
453 |
streamsize _M_sputnc(char_type __c, streamsize __n)
|
williamr@4
|
454 |
{ return this->_M_xsputnc(__c, __n); }
|
williamr@4
|
455 |
|
williamr@4
|
456 |
private: // Helper functions.
|
williamr@4
|
457 |
_STLP_DECLSPEC int_type _M_snextc_aux();
|
williamr@4
|
458 |
|
williamr@4
|
459 |
public: // Public members for reading characters.
|
williamr@4
|
460 |
streamsize in_avail()
|
williamr@4
|
461 |
{ return _FILE_I_avail(_M_get) > 0 ? _FILE_I_avail(_M_get)
|
williamr@4
|
462 |
#ifdef __SYMBIAN32__
|
williamr@4
|
463 |
+ save_read_buffer()
|
williamr@4
|
464 |
#endif
|
williamr@4
|
465 |
: this->showmanyc(); }
|
williamr@4
|
466 |
|
williamr@4
|
467 |
// Advance to the next character and return it.
|
williamr@4
|
468 |
int_type snextc() {
|
williamr@4
|
469 |
return _FILE_I_avail(_M_get) > 1
|
williamr@4
|
470 |
? traits_type::to_int_type(_FILE_I_preincr(_M_get))
|
williamr@4
|
471 |
: this->_M_snextc_aux();
|
williamr@4
|
472 |
}
|
williamr@4
|
473 |
|
williamr@4
|
474 |
// Return the current character and advance to the next.
|
williamr@4
|
475 |
int_type sbumpc() {
|
williamr@4
|
476 |
return _FILE_I_avail(_M_get) > 0
|
williamr@4
|
477 |
? traits_type::to_int_type(_FILE_I_postincr(_M_get))
|
williamr@4
|
478 |
: this->uflow();
|
williamr@4
|
479 |
}
|
williamr@4
|
480 |
|
williamr@4
|
481 |
// Return the current character without advancing to the next.
|
williamr@4
|
482 |
int_type sgetc() {
|
williamr@4
|
483 |
return _FILE_I_avail(_M_get) > 0
|
williamr@4
|
484 |
? traits_type::to_int_type(*_FILE_I_next(_M_get))
|
williamr@4
|
485 |
: this->underflow();
|
williamr@4
|
486 |
}
|
williamr@4
|
487 |
|
williamr@4
|
488 |
streamsize sgetn(char_type* __s, streamsize __n)
|
williamr@4
|
489 |
{ return this->xsgetn(__s, __n); }
|
williamr@4
|
490 |
|
williamr@4
|
491 |
int_type sputbackc(char_type __c) {
|
williamr@4
|
492 |
return _FILE_I_begin(_M_get) < _FILE_I_next(_M_get) &&
|
williamr@4
|
493 |
__c == *(_FILE_I_next(_M_get) - 1)
|
williamr@4
|
494 |
? traits_type::to_int_type(_FILE_I_predecr(_M_get))
|
williamr@4
|
495 |
: this->pbackfail(traits_type::to_int_type(__c));
|
williamr@4
|
496 |
}
|
williamr@4
|
497 |
|
williamr@4
|
498 |
int_type sungetc() {
|
williamr@4
|
499 |
return _FILE_I_begin(_M_get) < _FILE_I_next(_M_get)
|
williamr@4
|
500 |
? traits_type::to_int_type(_FILE_I_predecr(_M_get))
|
williamr@4
|
501 |
: this->pbackfail();
|
williamr@4
|
502 |
}
|
williamr@4
|
503 |
|
williamr@4
|
504 |
protected: // Virtual locale functions.
|
williamr@4
|
505 |
_STLP_DECLSPEC virtual void imbue(const locale&);
|
williamr@4
|
506 |
public: // Locale-related functions.
|
williamr@4
|
507 |
_STLP_DECLSPEC locale pubimbue(const locale&);
|
williamr@4
|
508 |
locale getloc() const { return _M_locale; }
|
williamr@4
|
509 |
|
williamr@4
|
510 |
# ifndef _STLP_NO_ANACHRONISMS
|
williamr@4
|
511 |
public:
|
williamr@4
|
512 |
void stossc() { this->sbumpc(); }
|
williamr@4
|
513 |
# endif
|
williamr@4
|
514 |
|
williamr@4
|
515 |
#if defined(__MVS__) || defined(__OS400__)
|
williamr@4
|
516 |
private: // Data members.
|
williamr@4
|
517 |
|
williamr@4
|
518 |
char_type* _M_gbegin; // Beginning of get area
|
williamr@4
|
519 |
char_type* _M_gnext; // Current position within the get area
|
williamr@4
|
520 |
char_type* _M_gend; // End of get area
|
williamr@4
|
521 |
|
williamr@4
|
522 |
char_type* _M_pbegin; // Beginning of put area
|
williamr@4
|
523 |
char_type* _M_pnext; // Current position within the put area
|
williamr@4
|
524 |
char_type* _M_pend; // End of put area
|
williamr@4
|
525 |
#endif
|
williamr@4
|
526 |
|
williamr@4
|
527 |
};
|
williamr@4
|
528 |
_STLP_END_NAMESPACE
|
williamr@4
|
529 |
|
williamr@4
|
530 |
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
|
williamr@4
|
531 |
# include <stl/_streambuf.c>
|
williamr@4
|
532 |
# endif
|
williamr@4
|
533 |
|
williamr@4
|
534 |
#endif
|
williamr@4
|
535 |
// Local Variables:
|
williamr@4
|
536 |
// mode:C++
|
williamr@4
|
537 |
// End:
|