williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* Copyright (c) 1999
|
williamr@4
|
3 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
4 |
*
|
williamr@4
|
5 |
* Copyright (c) 1999
|
williamr@4
|
6 |
* Boris Fomitchev
|
williamr@4
|
7 |
*
|
williamr@4
|
8 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
9 |
* or implied. Any use is at your own risk.
|
williamr@4
|
10 |
*
|
williamr@4
|
11 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
12 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
13 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
14 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
15 |
* modified is included with the above copyright notice.
|
williamr@4
|
16 |
*
|
williamr@4
|
17 |
*/
|
williamr@4
|
18 |
#ifndef _STLP_ISTREAM_C
|
williamr@4
|
19 |
#define _STLP_ISTREAM_C
|
williamr@4
|
20 |
|
williamr@4
|
21 |
#ifndef _STLP_INTERNAL_ISTREAM
|
williamr@4
|
22 |
# include <stl/_istream.h>
|
williamr@4
|
23 |
#endif
|
williamr@4
|
24 |
|
williamr@4
|
25 |
#ifndef _STLP_INTERNAL_LIMITS
|
williamr@4
|
26 |
# include <stl/_limits.h>
|
williamr@4
|
27 |
#endif
|
williamr@4
|
28 |
|
williamr@4
|
29 |
#ifndef _STLP_INTERNAL_NUM_GET_H
|
williamr@4
|
30 |
# include <stl/_num_get.h>
|
williamr@4
|
31 |
#endif
|
williamr@4
|
32 |
|
williamr@4
|
33 |
#if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
|
williamr@4
|
34 |
// no wchar_t is supported for this mode
|
williamr@4
|
35 |
# define __BIS_int_type__ int
|
williamr@4
|
36 |
# define __BIS_pos_type__ streampos
|
williamr@4
|
37 |
# define __BIS_off_type__ streamoff
|
williamr@4
|
38 |
#else
|
williamr@4
|
39 |
# define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type
|
williamr@4
|
40 |
# define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type
|
williamr@4
|
41 |
# define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type
|
williamr@4
|
42 |
#endif
|
williamr@4
|
43 |
|
williamr@4
|
44 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
45 |
|
williamr@4
|
46 |
//----------------------------------------------------------------------
|
williamr@4
|
47 |
// Function object structs used by some member functions.
|
williamr@4
|
48 |
|
williamr@4
|
49 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
50 |
|
williamr@4
|
51 |
template <class _Traits>
|
williamr@4
|
52 |
struct _Is_not_wspace {
|
williamr@4
|
53 |
typedef typename _Traits::char_type argument_type;
|
williamr@4
|
54 |
typedef bool result_type;
|
williamr@4
|
55 |
|
williamr@4
|
56 |
const ctype<argument_type>* _M_ctype;
|
williamr@4
|
57 |
|
williamr@4
|
58 |
_Is_not_wspace(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
|
williamr@4
|
59 |
bool operator()(argument_type __c) const
|
williamr@4
|
60 |
{ return !_M_ctype->is(ctype_base::space, __c); }
|
williamr@4
|
61 |
};
|
williamr@4
|
62 |
|
williamr@4
|
63 |
template <class _Traits>
|
williamr@4
|
64 |
struct _Is_wspace_null {
|
williamr@4
|
65 |
typedef typename _Traits::char_type argument_type;
|
williamr@4
|
66 |
typedef bool result_type;
|
williamr@4
|
67 |
|
williamr@4
|
68 |
const ctype<argument_type>* _M_ctype;
|
williamr@4
|
69 |
|
williamr@4
|
70 |
_Is_wspace_null(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
|
williamr@4
|
71 |
bool operator()(argument_type __c) const {
|
williamr@4
|
72 |
return _Traits::eq(__c, argument_type()) ||
|
williamr@4
|
73 |
_M_ctype->is(ctype_base::space, __c);
|
williamr@4
|
74 |
}
|
williamr@4
|
75 |
};
|
williamr@4
|
76 |
|
williamr@4
|
77 |
template <class _Traits>
|
williamr@4
|
78 |
struct _Scan_for_wspace {
|
williamr@4
|
79 |
typedef typename _Traits::char_type char_type;
|
williamr@4
|
80 |
typedef char_type* first_argument_type;
|
williamr@4
|
81 |
typedef char_type* second_argument_type;
|
williamr@4
|
82 |
typedef char_type* result_type;
|
williamr@4
|
83 |
|
williamr@4
|
84 |
const ctype<char_type>* _M_ctype;
|
williamr@4
|
85 |
|
williamr@4
|
86 |
_Scan_for_wspace(const ctype<char_type>* __ctype) : _M_ctype(__ctype) {}
|
williamr@4
|
87 |
const char_type*
|
williamr@4
|
88 |
operator()(const char_type* __first, const char_type* __last) const {
|
williamr@4
|
89 |
return _M_ctype->scan_is(ctype_base::space, __first, __last);
|
williamr@4
|
90 |
}
|
williamr@4
|
91 |
};
|
williamr@4
|
92 |
|
williamr@4
|
93 |
template <class _Traits>
|
williamr@4
|
94 |
struct _Scan_wspace_null {
|
williamr@4
|
95 |
typedef typename _Traits::char_type char_type;
|
williamr@4
|
96 |
typedef char_type* first_argument_type;
|
williamr@4
|
97 |
typedef char_type* second_argument_type;
|
williamr@4
|
98 |
typedef char_type* result_type;
|
williamr@4
|
99 |
|
williamr@4
|
100 |
const ctype<char_type>* _M_ctype;
|
williamr@4
|
101 |
|
williamr@4
|
102 |
_Scan_wspace_null(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
|
williamr@4
|
103 |
const char_type*
|
williamr@4
|
104 |
operator()(const char_type* __first, const char_type* __last) const {
|
williamr@4
|
105 |
__last = find_if(__first, __last,
|
williamr@4
|
106 |
_Eq_char_bound<_Traits>(char_type()));
|
williamr@4
|
107 |
return _M_ctype->scan_is(ctype_base::space, __first, __last);
|
williamr@4
|
108 |
}
|
williamr@4
|
109 |
};
|
williamr@4
|
110 |
|
williamr@4
|
111 |
template <class _Traits>
|
williamr@4
|
112 |
struct _Scan_for_not_wspace {
|
williamr@4
|
113 |
typedef typename _Traits::char_type char_type;
|
williamr@4
|
114 |
typedef char_type* first_argument_type;
|
williamr@4
|
115 |
typedef char_type* second_argument_type;
|
williamr@4
|
116 |
typedef char_type* result_type;
|
williamr@4
|
117 |
|
williamr@4
|
118 |
const ctype<char_type>* _M_ctype;
|
williamr@4
|
119 |
|
williamr@4
|
120 |
_Scan_for_not_wspace(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
|
williamr@4
|
121 |
const char_type*
|
williamr@4
|
122 |
operator()(const char_type* __first, const char_type* __last) const {
|
williamr@4
|
123 |
return _M_ctype->scan_not(ctype_base::space, __first, __last);
|
williamr@4
|
124 |
}
|
williamr@4
|
125 |
};
|
williamr@4
|
126 |
|
williamr@4
|
127 |
template <class _Traits>
|
williamr@4
|
128 |
struct _Scan_for_char_val {
|
williamr@4
|
129 |
typedef typename _Traits::char_type char_type;
|
williamr@4
|
130 |
typedef char_type* first_argument_type;
|
williamr@4
|
131 |
typedef char_type* second_argument_type;
|
williamr@4
|
132 |
typedef char_type* result_type;
|
williamr@4
|
133 |
|
williamr@4
|
134 |
char_type _M_val;
|
williamr@4
|
135 |
|
williamr@4
|
136 |
_Scan_for_char_val(char_type __val) : _M_val(__val) {}
|
williamr@4
|
137 |
|
williamr@4
|
138 |
const char_type*
|
williamr@4
|
139 |
operator()(const char_type* __first, const char_type* __last) const {
|
williamr@4
|
140 |
return find_if(__first, __last, _Eq_char_bound<_Traits>(_M_val));
|
williamr@4
|
141 |
}
|
williamr@4
|
142 |
};
|
williamr@4
|
143 |
|
williamr@4
|
144 |
template <class _Traits>
|
williamr@4
|
145 |
struct _Scan_for_int_val {
|
williamr@4
|
146 |
typedef typename _Traits::char_type char_type;
|
williamr@4
|
147 |
typedef typename _Traits::int_type int_type;
|
williamr@4
|
148 |
typedef char_type* first_argument_type;
|
williamr@4
|
149 |
typedef char_type* second_argument_type;
|
williamr@4
|
150 |
typedef char_type* result_type;
|
williamr@4
|
151 |
|
williamr@4
|
152 |
int_type _M_val;
|
williamr@4
|
153 |
|
williamr@4
|
154 |
_Scan_for_int_val(int_type __val) : _M_val(__val) {}
|
williamr@4
|
155 |
|
williamr@4
|
156 |
const char_type*
|
williamr@4
|
157 |
operator()(const char_type* __first, const char_type* __last) const {
|
williamr@4
|
158 |
return find_if(__first, __last,
|
williamr@4
|
159 |
_Eq_int_bound<_Traits>(_M_val));
|
williamr@4
|
160 |
}
|
williamr@4
|
161 |
};
|
williamr@4
|
162 |
|
williamr@4
|
163 |
// Helper function: try to push back a character to a streambuf,
|
williamr@4
|
164 |
// return true if the pushback succeeded. Does not throw.
|
williamr@4
|
165 |
|
williamr@4
|
166 |
template <class _CharT, class _Traits>
|
williamr@4
|
167 |
bool _STLP_CALL
|
williamr@4
|
168 |
__pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c) {
|
williamr@4
|
169 |
bool ret;
|
williamr@4
|
170 |
_STLP_TRY {
|
williamr@4
|
171 |
const typename _Traits::int_type __eof = _Traits::eof();
|
williamr@4
|
172 |
ret = !_Traits::eq_int_type(__buf->sputbackc(__c), __eof);
|
williamr@4
|
173 |
}
|
williamr@4
|
174 |
_STLP_CATCH_ALL {
|
williamr@4
|
175 |
ret = false;
|
williamr@4
|
176 |
}
|
williamr@4
|
177 |
return ret;
|
williamr@4
|
178 |
}
|
williamr@4
|
179 |
|
williamr@4
|
180 |
//----------------------------------------------------------------------
|
williamr@4
|
181 |
// Definitions of basic_istream<>'s noninline member functions.
|
williamr@4
|
182 |
|
williamr@4
|
183 |
// Helper function for formatted input of numbers.
|
williamr@4
|
184 |
template <class _CharT, class _Traits, class _Number>
|
williamr@4
|
185 |
ios_base::iostate _STLP_CALL
|
williamr@4
|
186 |
__get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val) {
|
williamr@4
|
187 |
typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
|
williamr@4
|
188 |
ios_base::iostate __err = 0;
|
williamr@4
|
189 |
_Sentry __sentry( __that ); // Skip whitespace.
|
williamr@4
|
190 |
if (__sentry) {
|
williamr@4
|
191 |
typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > _Num_get;
|
williamr@4
|
192 |
_STLP_TRY {
|
williamr@4
|
193 |
((const _Num_get&)use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()),
|
williamr@4
|
194 |
0, __that, __err, __val);
|
williamr@4
|
195 |
}
|
williamr@4
|
196 |
_STLP_CATCH_ALL {
|
williamr@4
|
197 |
__that._M_handle_exception(ios_base::badbit);
|
williamr@4
|
198 |
}
|
williamr@4
|
199 |
if (__err) __that.setstate(__err);
|
williamr@4
|
200 |
}
|
williamr@4
|
201 |
return __err;
|
williamr@4
|
202 |
}
|
williamr@4
|
203 |
|
williamr@4
|
204 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
205 |
|
williamr@4
|
206 |
template <class _CharT, class _Traits>
|
williamr@4
|
207 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (short& __val) {
|
williamr@4
|
208 |
long __lval;
|
williamr@4
|
209 |
_STLP_PRIV __get_num(*this, __lval);
|
williamr@4
|
210 |
if ( this->fail() ) {
|
williamr@4
|
211 |
return *this;
|
williamr@4
|
212 |
}
|
williamr@4
|
213 |
short __tmp = __STATIC_CAST(short, __lval);
|
williamr@4
|
214 |
unsigned short __uval = __STATIC_CAST(unsigned short, __lval);
|
williamr@4
|
215 |
// check if we lose digits
|
williamr@4
|
216 |
// if ((__val != __lval) && ((unsigned short)__val != __lval))
|
williamr@4
|
217 |
if ((__tmp != __lval) && ((long)__uval != __lval))
|
williamr@4
|
218 |
this->setstate(ios_base::failbit);
|
williamr@4
|
219 |
else
|
williamr@4
|
220 |
__val = __tmp;
|
williamr@4
|
221 |
return *this;
|
williamr@4
|
222 |
}
|
williamr@4
|
223 |
|
williamr@4
|
224 |
template <class _CharT, class _Traits>
|
williamr@4
|
225 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (int& __val) {
|
williamr@4
|
226 |
long __lval;
|
williamr@4
|
227 |
_STLP_PRIV __get_num(*this, __lval);
|
williamr@4
|
228 |
if ( this->fail() ) {
|
williamr@4
|
229 |
return *this;
|
williamr@4
|
230 |
}
|
williamr@4
|
231 |
int __tmp = __lval;
|
williamr@4
|
232 |
unsigned int __uval = __lval;
|
williamr@4
|
233 |
// check if we lose digits
|
williamr@4
|
234 |
// if ((__val != __lval) && ((unsigned int)__val != __lval))
|
williamr@4
|
235 |
if ((__tmp != __lval) && ((long)__uval != __lval))
|
williamr@4
|
236 |
this->setstate(ios_base::failbit);
|
williamr@4
|
237 |
else
|
williamr@4
|
238 |
__val = __tmp;
|
williamr@4
|
239 |
return *this;
|
williamr@4
|
240 |
}
|
williamr@4
|
241 |
|
williamr@4
|
242 |
template <class _CharT, class _Traits>
|
williamr@4
|
243 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned short& __val) {
|
williamr@4
|
244 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
245 |
return *this;
|
williamr@4
|
246 |
}
|
williamr@4
|
247 |
|
williamr@4
|
248 |
template <class _CharT, class _Traits>
|
williamr@4
|
249 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned int& __val) {
|
williamr@4
|
250 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
251 |
return *this;
|
williamr@4
|
252 |
}
|
williamr@4
|
253 |
|
williamr@4
|
254 |
template <class _CharT, class _Traits>
|
williamr@4
|
255 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (long& __val) {
|
williamr@4
|
256 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
257 |
return *this;
|
williamr@4
|
258 |
}
|
williamr@4
|
259 |
|
williamr@4
|
260 |
template <class _CharT, class _Traits>
|
williamr@4
|
261 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned long& __val) {
|
williamr@4
|
262 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
263 |
return *this;
|
williamr@4
|
264 |
}
|
williamr@4
|
265 |
|
williamr@4
|
266 |
#if defined (_STLP_LONG_LONG)
|
williamr@4
|
267 |
template <class _CharT, class _Traits>
|
williamr@4
|
268 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (_STLP_LONG_LONG& __val) {
|
williamr@4
|
269 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
270 |
return *this;
|
williamr@4
|
271 |
}
|
williamr@4
|
272 |
|
williamr@4
|
273 |
template <class _CharT, class _Traits>
|
williamr@4
|
274 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (unsigned _STLP_LONG_LONG& __val) {
|
williamr@4
|
275 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
276 |
return *this;
|
williamr@4
|
277 |
}
|
williamr@4
|
278 |
#endif
|
williamr@4
|
279 |
template <class _CharT, class _Traits>
|
williamr@4
|
280 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (float& __val) {
|
williamr@4
|
281 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
282 |
return *this;
|
williamr@4
|
283 |
}
|
williamr@4
|
284 |
template <class _CharT, class _Traits>
|
williamr@4
|
285 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (double& __val) {
|
williamr@4
|
286 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
287 |
return *this;
|
williamr@4
|
288 |
}
|
williamr@4
|
289 |
#if !defined (_STLP_NO_LONG_DOUBLE)
|
williamr@4
|
290 |
template <class _CharT, class _Traits>
|
williamr@4
|
291 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (long double& __val) {
|
williamr@4
|
292 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
293 |
return *this;
|
williamr@4
|
294 |
}
|
williamr@4
|
295 |
#endif
|
williamr@4
|
296 |
#if !defined (_STLP_NO_BOOL)
|
williamr@4
|
297 |
template <class _CharT, class _Traits>
|
williamr@4
|
298 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (bool& __val) {
|
williamr@4
|
299 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
300 |
return *this;
|
williamr@4
|
301 |
}
|
williamr@4
|
302 |
#endif
|
williamr@4
|
303 |
|
williamr@4
|
304 |
template <class _CharT, class _Traits>
|
williamr@4
|
305 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>> (void*& __val) {
|
williamr@4
|
306 |
_STLP_PRIV __get_num(*this, __val);
|
williamr@4
|
307 |
return *this;
|
williamr@4
|
308 |
}
|
williamr@4
|
309 |
|
williamr@4
|
310 |
// Unformatted input
|
williamr@4
|
311 |
|
williamr@4
|
312 |
template <class _CharT, class _Traits>
|
williamr@4
|
313 |
__BIS_int_type__
|
williamr@4
|
314 |
basic_istream<_CharT, _Traits>::peek() {
|
williamr@4
|
315 |
typename _Traits::int_type __tmp = _Traits::eof();
|
williamr@4
|
316 |
|
williamr@4
|
317 |
this->_M_gcount = 0;
|
williamr@4
|
318 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
319 |
|
williamr@4
|
320 |
if (__sentry) {
|
williamr@4
|
321 |
_STLP_TRY {
|
williamr@4
|
322 |
__tmp = this->rdbuf()->sgetc();
|
williamr@4
|
323 |
}
|
williamr@4
|
324 |
_STLP_CATCH_ALL {
|
williamr@4
|
325 |
this->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
326 |
}
|
williamr@4
|
327 |
if (this->_S_eof(__tmp))
|
williamr@4
|
328 |
this->setstate(ios_base::eofbit);
|
williamr@4
|
329 |
}
|
williamr@4
|
330 |
|
williamr@4
|
331 |
return __tmp;
|
williamr@4
|
332 |
}
|
williamr@4
|
333 |
|
williamr@4
|
334 |
|
williamr@4
|
335 |
template <class _CharT, class _Traits>
|
williamr@4
|
336 |
__BIS_int_type__
|
williamr@4
|
337 |
basic_istream<_CharT, _Traits>::get() {
|
williamr@4
|
338 |
typename _Traits::int_type __tmp = _Traits::eof();
|
williamr@4
|
339 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
340 |
this->_M_gcount = 0;
|
williamr@4
|
341 |
|
williamr@4
|
342 |
if (__sentry) {
|
williamr@4
|
343 |
_STLP_TRY {
|
williamr@4
|
344 |
__tmp = this->rdbuf()->sbumpc();
|
williamr@4
|
345 |
}
|
williamr@4
|
346 |
_STLP_CATCH_ALL {
|
williamr@4
|
347 |
this->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
348 |
}
|
williamr@4
|
349 |
|
williamr@4
|
350 |
if (!this->_S_eof(__tmp))
|
williamr@4
|
351 |
this->_M_gcount = 1;
|
williamr@4
|
352 |
}
|
williamr@4
|
353 |
|
williamr@4
|
354 |
if (_M_gcount == 0)
|
williamr@4
|
355 |
this->setstate(ios_base::eofbit | ios_base::failbit);
|
williamr@4
|
356 |
|
williamr@4
|
357 |
return __tmp;
|
williamr@4
|
358 |
}
|
williamr@4
|
359 |
|
williamr@4
|
360 |
template <class _CharT, class _Traits>
|
williamr@4
|
361 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
362 |
basic_istream<_CharT, _Traits>::get(_CharT& __c) {
|
williamr@4
|
363 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
364 |
this->_M_gcount = 0;
|
williamr@4
|
365 |
|
williamr@4
|
366 |
if (__sentry) {
|
williamr@4
|
367 |
typename _Traits::int_type __tmp = _Traits::eof();
|
williamr@4
|
368 |
_STLP_TRY {
|
williamr@4
|
369 |
__tmp = this->rdbuf()->sbumpc();
|
williamr@4
|
370 |
}
|
williamr@4
|
371 |
_STLP_CATCH_ALL {
|
williamr@4
|
372 |
this->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
373 |
}
|
williamr@4
|
374 |
|
williamr@4
|
375 |
if (!this->_S_eof(__tmp)) {
|
williamr@4
|
376 |
this->_M_gcount = 1;
|
williamr@4
|
377 |
__c = _Traits::to_char_type(__tmp);
|
williamr@4
|
378 |
}
|
williamr@4
|
379 |
}
|
williamr@4
|
380 |
|
williamr@4
|
381 |
if (this->_M_gcount == 0)
|
williamr@4
|
382 |
this->setstate(ios_base::eofbit | ios_base::failbit);
|
williamr@4
|
383 |
|
williamr@4
|
384 |
return *this;
|
williamr@4
|
385 |
}
|
williamr@4
|
386 |
|
williamr@4
|
387 |
|
williamr@4
|
388 |
// Read characters and discard them. The standard specifies a single
|
williamr@4
|
389 |
// function with two arguments, each with a default. We instead use
|
williamr@4
|
390 |
// three overloded functions, because it's possible to implement the
|
williamr@4
|
391 |
// first two more efficiently than the fully general third version.
|
williamr@4
|
392 |
template <class _CharT, class _Traits>
|
williamr@4
|
393 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore() {
|
williamr@4
|
394 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
395 |
this->_M_gcount = 0;
|
williamr@4
|
396 |
|
williamr@4
|
397 |
if (__sentry) {
|
williamr@4
|
398 |
int_type __c;
|
williamr@4
|
399 |
_STLP_TRY {
|
williamr@4
|
400 |
__c = this->rdbuf()->sbumpc();
|
williamr@4
|
401 |
}
|
williamr@4
|
402 |
_STLP_CATCH_ALL {
|
williamr@4
|
403 |
this->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
404 |
return *this;
|
williamr@4
|
405 |
}
|
williamr@4
|
406 |
|
williamr@4
|
407 |
if (!this->_S_eof(__c))
|
williamr@4
|
408 |
this->_M_gcount = 1;
|
williamr@4
|
409 |
else
|
williamr@4
|
410 |
this->setstate(ios_base::eofbit);
|
williamr@4
|
411 |
}
|
williamr@4
|
412 |
|
williamr@4
|
413 |
return *this;
|
williamr@4
|
414 |
}
|
williamr@4
|
415 |
|
williamr@4
|
416 |
// Putback
|
williamr@4
|
417 |
|
williamr@4
|
418 |
template <class _CharT, class _Traits>
|
williamr@4
|
419 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
420 |
basic_istream<_CharT, _Traits>::putback(_CharT __c) {
|
williamr@4
|
421 |
this->_M_gcount = 0;
|
williamr@4
|
422 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
423 |
|
williamr@4
|
424 |
if (__sentry) {
|
williamr@4
|
425 |
typename _Traits::int_type __tmp = _Traits::eof();
|
williamr@4
|
426 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
427 |
// if (!__buf || this->_S_eof(__buf->sputbackc(__c)))
|
williamr@4
|
428 |
if (__buf) {
|
williamr@4
|
429 |
_STLP_TRY {
|
williamr@4
|
430 |
__tmp = __buf->sputbackc(__c);
|
williamr@4
|
431 |
}
|
williamr@4
|
432 |
_STLP_CATCH_ALL {
|
williamr@4
|
433 |
this->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
434 |
}
|
williamr@4
|
435 |
}
|
williamr@4
|
436 |
if (this->_S_eof(__tmp))
|
williamr@4
|
437 |
this->setstate(ios_base::badbit);
|
williamr@4
|
438 |
}
|
williamr@4
|
439 |
else
|
williamr@4
|
440 |
this->setstate(ios_base::failbit);
|
williamr@4
|
441 |
|
williamr@4
|
442 |
return *this;
|
williamr@4
|
443 |
}
|
williamr@4
|
444 |
|
williamr@4
|
445 |
template <class _CharT, class _Traits>
|
williamr@4
|
446 |
basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
|
williamr@4
|
447 |
this->_M_gcount = 0;
|
williamr@4
|
448 |
|
williamr@4
|
449 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
450 |
|
williamr@4
|
451 |
if (__sentry) {
|
williamr@4
|
452 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
453 |
// if (!__buf || _Traits::eq_int_type(__buf->sungetc(), _Traits::eof()))
|
williamr@4
|
454 |
if (__buf) {
|
williamr@4
|
455 |
_STLP_TRY {
|
williamr@4
|
456 |
if (this->_S_eof(__buf->sungetc()))
|
williamr@4
|
457 |
this->setstate(ios_base::badbit);
|
williamr@4
|
458 |
}
|
williamr@4
|
459 |
_STLP_CATCH_ALL {
|
williamr@4
|
460 |
this->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
461 |
}
|
williamr@4
|
462 |
} else
|
williamr@4
|
463 |
this->setstate(ios_base::badbit);
|
williamr@4
|
464 |
}
|
williamr@4
|
465 |
else
|
williamr@4
|
466 |
this->setstate(ios_base::failbit);
|
williamr@4
|
467 |
|
williamr@4
|
468 |
return *this;
|
williamr@4
|
469 |
}
|
williamr@4
|
470 |
|
williamr@4
|
471 |
// Positioning and buffer control.
|
williamr@4
|
472 |
|
williamr@4
|
473 |
template <class _CharT, class _Traits>
|
williamr@4
|
474 |
int basic_istream<_CharT, _Traits>::sync() {
|
williamr@4
|
475 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
476 |
|
williamr@4
|
477 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
478 |
if (__buf) {
|
williamr@4
|
479 |
if (__buf->pubsync() == -1) {
|
williamr@4
|
480 |
this->setstate(ios_base::badbit);
|
williamr@4
|
481 |
return -1;
|
williamr@4
|
482 |
}
|
williamr@4
|
483 |
else
|
williamr@4
|
484 |
return 0;
|
williamr@4
|
485 |
}
|
williamr@4
|
486 |
else
|
williamr@4
|
487 |
return -1;
|
williamr@4
|
488 |
}
|
williamr@4
|
489 |
|
williamr@4
|
490 |
template <class _CharT, class _Traits>
|
williamr@4
|
491 |
__BIS_pos_type__
|
williamr@4
|
492 |
basic_istream<_CharT, _Traits>::tellg() {
|
williamr@4
|
493 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
494 |
|
williamr@4
|
495 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
496 |
return (__buf && !this->fail()) ? __buf->pubseekoff(0, ios_base::cur, ios_base::in)
|
williamr@4
|
497 |
: pos_type(-1);
|
williamr@4
|
498 |
}
|
williamr@4
|
499 |
|
williamr@4
|
500 |
template <class _CharT, class _Traits>
|
williamr@4
|
501 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
502 |
basic_istream<_CharT, _Traits>::seekg(pos_type __pos) {
|
williamr@4
|
503 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
504 |
|
williamr@4
|
505 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
506 |
if (!this->fail() && __buf) {
|
williamr@4
|
507 |
if (__buf->pubseekpos(__pos) == pos_type(-1)) {
|
williamr@4
|
508 |
this->setstate(ios_base::failbit);
|
williamr@4
|
509 |
}
|
williamr@4
|
510 |
}
|
williamr@4
|
511 |
return *this;
|
williamr@4
|
512 |
}
|
williamr@4
|
513 |
|
williamr@4
|
514 |
template <class _CharT, class _Traits>
|
williamr@4
|
515 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
516 |
basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) {
|
williamr@4
|
517 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
518 |
|
williamr@4
|
519 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
520 |
if (!this->fail() && __buf)
|
williamr@4
|
521 |
__buf->pubseekoff(__off, __dir);
|
williamr@4
|
522 |
return *this;
|
williamr@4
|
523 |
}
|
williamr@4
|
524 |
|
williamr@4
|
525 |
// Formatted input of characters and character arrays.
|
williamr@4
|
526 |
|
williamr@4
|
527 |
template <class _CharT, class _Traits>
|
williamr@4
|
528 |
void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c) {
|
williamr@4
|
529 |
// typename _Traits::int_type __tmp = _Traits::eof();
|
williamr@4
|
530 |
|
williamr@4
|
531 |
sentry __sentry(*this); // Skip whitespace.
|
williamr@4
|
532 |
|
williamr@4
|
533 |
if (__sentry) {
|
williamr@4
|
534 |
typename _Traits::int_type __tmp;// = _Traits::eof();
|
williamr@4
|
535 |
|
williamr@4
|
536 |
_STLP_TRY {
|
williamr@4
|
537 |
__tmp = this->rdbuf()->sbumpc();
|
williamr@4
|
538 |
}
|
williamr@4
|
539 |
_STLP_CATCH_ALL {
|
williamr@4
|
540 |
this->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
541 |
return;
|
williamr@4
|
542 |
}
|
williamr@4
|
543 |
|
williamr@4
|
544 |
if (!this->_S_eof(__tmp))
|
williamr@4
|
545 |
__c = _Traits::to_char_type(__tmp);
|
williamr@4
|
546 |
else
|
williamr@4
|
547 |
this->setstate(ios_base::eofbit | ios_base::failbit);
|
williamr@4
|
548 |
}
|
williamr@4
|
549 |
}
|
williamr@4
|
550 |
|
williamr@4
|
551 |
|
williamr@4
|
552 |
//---------------------------------------------------------------------------
|
williamr@4
|
553 |
// istream's helper functions.
|
williamr@4
|
554 |
|
williamr@4
|
555 |
// A generic function for unbuffered input. We stop when we reach EOF,
|
williamr@4
|
556 |
// or when we have extracted _Num characters, or when the function object
|
williamr@4
|
557 |
// __is_delim return true. In the last case, it extracts the character
|
williamr@4
|
558 |
// for which __is_delim is true, if and only if __extract_delim is true.
|
williamr@4
|
559 |
// It appends a null character to the end of the string; this means that
|
williamr@4
|
560 |
// it may store up to _Num + 1 characters.
|
williamr@4
|
561 |
//
|
williamr@4
|
562 |
// __is_getline governs two corner cases: reading _Num characters without
|
williamr@4
|
563 |
// encountering delim or eof (in which case failbit is set if __is_getline
|
williamr@4
|
564 |
// is true); and reading _Num characters where the _Num+1'st character is
|
williamr@4
|
565 |
// eof (in which case eofbit is set if __is_getline is true).
|
williamr@4
|
566 |
//
|
williamr@4
|
567 |
// It is assumed that __is_delim never throws.
|
williamr@4
|
568 |
//
|
williamr@4
|
569 |
// Return value is the number of characters extracted, including the
|
williamr@4
|
570 |
// delimiter if it is extracted. Note that the number of characaters
|
williamr@4
|
571 |
// extracted isn't necessarily the same as the number stored.
|
williamr@4
|
572 |
|
williamr@4
|
573 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
574 |
|
williamr@4
|
575 |
template < class _CharT, class _Traits, class _Is_Delim>
|
williamr@4
|
576 |
streamsize _STLP_CALL
|
williamr@4
|
577 |
__read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
|
williamr@4
|
578 |
streamsize _Num, _CharT* __s,
|
williamr@4
|
579 |
_Is_Delim __is_delim,
|
williamr@4
|
580 |
bool __extract_delim, bool __append_null,
|
williamr@4
|
581 |
bool __is_getline) {
|
williamr@4
|
582 |
streamsize __n = 0;
|
williamr@4
|
583 |
ios_base::iostate __status = 0;
|
williamr@4
|
584 |
|
williamr@4
|
585 |
typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
|
williamr@4
|
586 |
// The operations that can potentially throw are sbumpc, snextc, and sgetc.
|
williamr@4
|
587 |
_STLP_TRY {
|
williamr@4
|
588 |
for (;;) {
|
williamr@4
|
589 |
int_type __c = __buf->sbumpc(); // sschwarz
|
williamr@4
|
590 |
|
williamr@4
|
591 |
if (__that->_S_eof(__c)) {
|
williamr@4
|
592 |
if (__n < _Num || __is_getline)
|
williamr@4
|
593 |
__status |= ios_base::eofbit;
|
williamr@4
|
594 |
break;
|
williamr@4
|
595 |
}
|
williamr@4
|
596 |
else if (__is_delim(_Traits::to_char_type(__c))) {
|
williamr@4
|
597 |
if (__extract_delim) { // Extract and discard current character.
|
williamr@4
|
598 |
++__n;
|
williamr@4
|
599 |
} else if ( !__pushback(__buf, _Traits::to_char_type(__c)) ) { // leave delimiter
|
williamr@4
|
600 |
__status |= ios_base::failbit;
|
williamr@4
|
601 |
}
|
williamr@4
|
602 |
break;
|
williamr@4
|
603 |
}
|
williamr@4
|
604 |
else { // regular character
|
williamr@4
|
605 |
*__s++ = _Traits::to_char_type(__c);
|
williamr@4
|
606 |
++__n;
|
williamr@4
|
607 |
}
|
williamr@4
|
608 |
|
williamr@4
|
609 |
if (__n == _Num) {
|
williamr@4
|
610 |
if (__is_getline) // didn't find delimiter as one of the _Num chars
|
williamr@4
|
611 |
__status |= ios_base::failbit;
|
williamr@4
|
612 |
break;
|
williamr@4
|
613 |
}
|
williamr@4
|
614 |
}
|
williamr@4
|
615 |
}
|
williamr@4
|
616 |
_STLP_CATCH_ALL {
|
williamr@4
|
617 |
__that->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
618 |
*__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
|
williamr@4
|
619 |
return __n;
|
williamr@4
|
620 |
}
|
williamr@4
|
621 |
|
williamr@4
|
622 |
if (__append_null)
|
williamr@4
|
623 |
*__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
|
williamr@4
|
624 |
if (__status)
|
williamr@4
|
625 |
__that->setstate(__status); // This might throw.
|
williamr@4
|
626 |
return __n;
|
williamr@4
|
627 |
}
|
williamr@4
|
628 |
|
williamr@4
|
629 |
// Much like __read_unbuffered, but with one additional function object:
|
williamr@4
|
630 |
// __scan_delim(first, last) returns the first pointer p in [first, last)
|
williamr@4
|
631 |
// such that __is_delim(p) is true.
|
williamr@4
|
632 |
|
williamr@4
|
633 |
template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
|
williamr@4
|
634 |
streamsize _STLP_CALL
|
williamr@4
|
635 |
__read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
|
williamr@4
|
636 |
streamsize _Num, _CharT* __s,
|
williamr@4
|
637 |
_Is_Delim __is_delim, _Scan_Delim __scan_delim,
|
williamr@4
|
638 |
bool __extract_delim, bool __append_null,
|
williamr@4
|
639 |
bool __is_getline) {
|
williamr@4
|
640 |
streamsize __n = 0;
|
williamr@4
|
641 |
ios_base::iostate __status = 0;
|
williamr@4
|
642 |
bool __done = false;
|
williamr@4
|
643 |
|
williamr@4
|
644 |
_STLP_TRY {
|
williamr@4
|
645 |
while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
|
williamr@4
|
646 |
const _CharT* __first = __buf->_M_gptr();
|
williamr@4
|
647 |
const _CharT* __last = __buf->_M_egptr();
|
williamr@4
|
648 |
//casting numeric_limits<ptrdiff_t>::max to streamsize only works is ptrdiff_t is signed or streamsize representation
|
williamr@4
|
649 |
//is larger than ptrdiff_t one.
|
williamr@4
|
650 |
_STLP_STATIC_ASSERT((sizeof(streamsize) > sizeof(ptrdiff_t)) ||
|
williamr@4
|
651 |
(sizeof(streamsize) == sizeof(ptrdiff_t)) && numeric_limits<ptrdiff_t>::is_signed)
|
williamr@4
|
652 |
ptrdiff_t __request = __STATIC_CAST(ptrdiff_t, (min) (__STATIC_CAST(streamsize, (numeric_limits<ptrdiff_t>::max)()), _Num - __n));
|
williamr@4
|
653 |
|
williamr@4
|
654 |
const _CharT* __p = __scan_delim(__first, __last);
|
williamr@4
|
655 |
ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request);
|
williamr@4
|
656 |
_Traits::copy(__s, __first, __chunk);
|
williamr@4
|
657 |
__s += __chunk;
|
williamr@4
|
658 |
__n += __chunk;
|
williamr@4
|
659 |
__buf->_M_gbump((int)__chunk);
|
williamr@4
|
660 |
|
williamr@4
|
661 |
// We terminated by finding delim.
|
williamr@4
|
662 |
if (__p != __last && __p - __first <= __request) {
|
williamr@4
|
663 |
if (__extract_delim) {
|
williamr@4
|
664 |
__n += 1;
|
williamr@4
|
665 |
__buf->_M_gbump(1);
|
williamr@4
|
666 |
}
|
williamr@4
|
667 |
__done = true;
|
williamr@4
|
668 |
}
|
williamr@4
|
669 |
|
williamr@4
|
670 |
// We terminated by reading all the characters we were asked for.
|
williamr@4
|
671 |
else if (__n == _Num) {
|
williamr@4
|
672 |
|
williamr@4
|
673 |
// Find out if we have reached eof. This matters for getline.
|
williamr@4
|
674 |
if (__is_getline) {
|
williamr@4
|
675 |
if (__chunk == __last - __first) {
|
williamr@4
|
676 |
if (__that->_S_eof(__buf->sgetc()))
|
williamr@4
|
677 |
__status |= ios_base::eofbit;
|
williamr@4
|
678 |
}
|
williamr@4
|
679 |
else
|
williamr@4
|
680 |
__status |= ios_base::failbit;
|
williamr@4
|
681 |
}
|
williamr@4
|
682 |
__done = true;
|
williamr@4
|
683 |
}
|
williamr@4
|
684 |
|
williamr@4
|
685 |
// The buffer contained fewer than _Num - __n characters. Either we're
|
williamr@4
|
686 |
// at eof, or we should refill the buffer and try again.
|
williamr@4
|
687 |
else {
|
williamr@4
|
688 |
if (__that->_S_eof(__buf->sgetc())) {
|
williamr@4
|
689 |
__status |= ios_base::eofbit;
|
williamr@4
|
690 |
__done = true;
|
williamr@4
|
691 |
}
|
williamr@4
|
692 |
}
|
williamr@4
|
693 |
} // Close the while loop.
|
williamr@4
|
694 |
}
|
williamr@4
|
695 |
_STLP_CATCH_ALL {
|
williamr@4
|
696 |
__that->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
697 |
__done = true;
|
williamr@4
|
698 |
}
|
williamr@4
|
699 |
|
williamr@4
|
700 |
if (__done) {
|
williamr@4
|
701 |
if (__append_null)
|
williamr@4
|
702 |
*__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
|
williamr@4
|
703 |
if (__status != 0)
|
williamr@4
|
704 |
__that->setstate(__status); // This might throw.
|
williamr@4
|
705 |
return __n;
|
williamr@4
|
706 |
}
|
williamr@4
|
707 |
|
williamr@4
|
708 |
// If execution has reached this point, then we have an empty buffer but
|
williamr@4
|
709 |
// we have not reached eof. What that means is that the streambuf has
|
williamr@4
|
710 |
// decided to switch from buffered to unbuffered input. We switch to
|
williamr@4
|
711 |
// to __read_unbuffered.
|
williamr@4
|
712 |
|
williamr@4
|
713 |
return __n + __read_unbuffered(__that, __buf, _Num - __n, __s, __is_delim,
|
williamr@4
|
714 |
__extract_delim,__append_null,__is_getline);
|
williamr@4
|
715 |
}
|
williamr@4
|
716 |
|
williamr@4
|
717 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
718 |
|
williamr@4
|
719 |
template <class _CharT, class _Traits>
|
williamr@4
|
720 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
721 |
basic_istream<_CharT, _Traits>::get(_CharT* __s, streamsize __n,
|
williamr@4
|
722 |
_CharT __delim) {
|
williamr@4
|
723 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
724 |
this->_M_gcount = 0;
|
williamr@4
|
725 |
|
williamr@4
|
726 |
if (__sentry) {
|
williamr@4
|
727 |
if (__n > 0) {
|
williamr@4
|
728 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
729 |
|
williamr@4
|
730 |
if (__buf->egptr() != __buf->gptr())
|
williamr@4
|
731 |
this->_M_gcount =
|
williamr@4
|
732 |
_STLP_PRIV __read_buffered(this, __buf, __n - 1, __s,
|
williamr@4
|
733 |
_STLP_PRIV _Eq_char_bound<_Traits>(__delim),
|
williamr@4
|
734 |
_STLP_PRIV _Scan_for_char_val<_Traits>(__delim),
|
williamr@4
|
735 |
false, true, false);
|
williamr@4
|
736 |
else
|
williamr@4
|
737 |
this->_M_gcount =
|
williamr@4
|
738 |
_STLP_PRIV __read_unbuffered(this, __buf, __n - 1, __s,
|
williamr@4
|
739 |
_STLP_PRIV _Eq_char_bound<_Traits>(__delim),
|
williamr@4
|
740 |
false, true, false);
|
williamr@4
|
741 |
}
|
williamr@4
|
742 |
}
|
williamr@4
|
743 |
|
williamr@4
|
744 |
if (this->_M_gcount == 0)
|
williamr@4
|
745 |
this->setstate(ios_base::failbit);
|
williamr@4
|
746 |
|
williamr@4
|
747 |
return *this;
|
williamr@4
|
748 |
}
|
williamr@4
|
749 |
|
williamr@4
|
750 |
// Getline is essentially identical to get, except that it extracts
|
williamr@4
|
751 |
// the delimiter.
|
williamr@4
|
752 |
template <class _CharT, class _Traits>
|
williamr@4
|
753 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
754 |
basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n,
|
williamr@4
|
755 |
_CharT __delim) {
|
williamr@4
|
756 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
757 |
this->_M_gcount = 0;
|
williamr@4
|
758 |
|
williamr@4
|
759 |
if (__sentry) {
|
williamr@4
|
760 |
if (__n > 0) {
|
williamr@4
|
761 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
762 |
this->_M_gcount = __buf->egptr() != __buf->gptr()
|
williamr@4
|
763 |
? _STLP_PRIV __read_buffered(this, __buf, __n - 1, __s,
|
williamr@4
|
764 |
_STLP_PRIV _Eq_char_bound<_Traits>(__delim),
|
williamr@4
|
765 |
_STLP_PRIV _Scan_for_char_val<_Traits>(__delim),
|
williamr@4
|
766 |
true, true, true)
|
williamr@4
|
767 |
: _STLP_PRIV __read_unbuffered(this, __buf, __n - 1, __s,
|
williamr@4
|
768 |
_STLP_PRIV _Eq_char_bound<_Traits>(__delim),
|
williamr@4
|
769 |
true, true, true);
|
williamr@4
|
770 |
}
|
williamr@4
|
771 |
}
|
williamr@4
|
772 |
|
williamr@4
|
773 |
if (this->_M_gcount == 0)
|
williamr@4
|
774 |
this->setstate(ios_base::failbit);
|
williamr@4
|
775 |
|
williamr@4
|
776 |
return *this;
|
williamr@4
|
777 |
}
|
williamr@4
|
778 |
|
williamr@4
|
779 |
// Read n characters. We don't look for any delimiter, and we don't
|
williamr@4
|
780 |
// put in a terminating null character.
|
williamr@4
|
781 |
template <class _CharT, class _Traits>
|
williamr@4
|
782 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
783 |
basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) {
|
williamr@4
|
784 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
785 |
this->_M_gcount = 0;
|
williamr@4
|
786 |
|
williamr@4
|
787 |
if (__sentry && !this->eof()) {
|
williamr@4
|
788 |
basic_streambuf<_CharT, _Traits>*__buf = this->rdbuf();
|
williamr@4
|
789 |
if (__buf->gptr() != __buf->egptr())
|
williamr@4
|
790 |
_M_gcount
|
williamr@4
|
791 |
= _STLP_PRIV __read_buffered(this, __buf, __n, __s,
|
williamr@4
|
792 |
_STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
|
williamr@4
|
793 |
_STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
|
williamr@4
|
794 |
false, false, false);
|
williamr@4
|
795 |
else
|
williamr@4
|
796 |
_M_gcount
|
williamr@4
|
797 |
= _STLP_PRIV __read_unbuffered(this, __buf, __n, __s,
|
williamr@4
|
798 |
_STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
|
williamr@4
|
799 |
false, false, false);
|
williamr@4
|
800 |
}
|
williamr@4
|
801 |
else
|
williamr@4
|
802 |
this->setstate(ios_base::failbit);
|
williamr@4
|
803 |
|
williamr@4
|
804 |
if (this->eof())
|
williamr@4
|
805 |
this->setstate(ios_base::eofbit | ios_base::failbit);
|
williamr@4
|
806 |
|
williamr@4
|
807 |
return *this;
|
williamr@4
|
808 |
}
|
williamr@4
|
809 |
|
williamr@4
|
810 |
|
williamr@4
|
811 |
// Read n or fewer characters. We don't look for any delimiter, and
|
williamr@4
|
812 |
// we don't put in a terminating null character.
|
williamr@4
|
813 |
template <class _CharT, class _Traits>
|
williamr@4
|
814 |
streamsize
|
williamr@4
|
815 |
basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax) {
|
williamr@4
|
816 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
817 |
this->_M_gcount = 0;
|
williamr@4
|
818 |
|
williamr@4
|
819 |
if (__sentry && !this->eof() && __nmax >= 0) {
|
williamr@4
|
820 |
|
williamr@4
|
821 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
822 |
streamsize __avail = __buf->in_avail();
|
williamr@4
|
823 |
|
williamr@4
|
824 |
// fbp : isn't full-blown setstate required here ?
|
williamr@4
|
825 |
if (__avail == -1)
|
williamr@4
|
826 |
this->_M_setstate_nothrow(ios_base::eofbit);
|
williamr@4
|
827 |
|
williamr@4
|
828 |
else if (__avail != 0) {
|
williamr@4
|
829 |
|
williamr@4
|
830 |
if (__buf->gptr() != __buf->egptr())
|
williamr@4
|
831 |
_M_gcount
|
williamr@4
|
832 |
= _STLP_PRIV __read_buffered(this, __buf, (min) (__avail, __nmax), __s,
|
williamr@4
|
833 |
_STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
|
williamr@4
|
834 |
_STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
|
williamr@4
|
835 |
false, false, false);
|
williamr@4
|
836 |
else
|
williamr@4
|
837 |
_M_gcount
|
williamr@4
|
838 |
= _STLP_PRIV __read_unbuffered(this, __buf, (min) (__avail, __nmax), __s,
|
williamr@4
|
839 |
_STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
|
williamr@4
|
840 |
false, false, false);
|
williamr@4
|
841 |
}
|
williamr@4
|
842 |
}
|
williamr@4
|
843 |
else {
|
williamr@4
|
844 |
// fbp : changed so that failbit is set only there, to pass Dietmar's test
|
williamr@4
|
845 |
if (this->eof())
|
williamr@4
|
846 |
this->setstate(ios_base::eofbit | ios_base::failbit);
|
williamr@4
|
847 |
else
|
williamr@4
|
848 |
this->setstate(ios_base::failbit);
|
williamr@4
|
849 |
}
|
williamr@4
|
850 |
|
williamr@4
|
851 |
// if (this->eof())
|
williamr@4
|
852 |
// this->setstate(ios_base::eofbit | ios_base::failbit);
|
williamr@4
|
853 |
|
williamr@4
|
854 |
return _M_gcount;
|
williamr@4
|
855 |
}
|
williamr@4
|
856 |
|
williamr@4
|
857 |
template <class _CharT, class _Traits>
|
williamr@4
|
858 |
void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s) {
|
williamr@4
|
859 |
sentry __sentry(*this); // Skip whitespace.
|
williamr@4
|
860 |
|
williamr@4
|
861 |
if (__sentry) {
|
williamr@4
|
862 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
863 |
streamsize __nmax = this->width() > 0
|
williamr@4
|
864 |
? this->width() - 1
|
williamr@4
|
865 |
: ((numeric_limits<streamsize>::max)() / sizeof(_CharT)) - 1;
|
williamr@4
|
866 |
|
williamr@4
|
867 |
streamsize __n = __buf->gptr() != __buf->egptr()
|
williamr@4
|
868 |
? _STLP_PRIV __read_buffered(this, __buf, __nmax, __s,
|
williamr@4
|
869 |
_STLP_PRIV _Is_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
|
williamr@4
|
870 |
_STLP_PRIV _Scan_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
|
williamr@4
|
871 |
false, true, false)
|
williamr@4
|
872 |
: _STLP_PRIV __read_unbuffered(this, __buf, __nmax, __s,
|
williamr@4
|
873 |
_STLP_PRIV _Is_wspace_null<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
|
williamr@4
|
874 |
false, true, false);
|
williamr@4
|
875 |
if (__n == 0)
|
williamr@4
|
876 |
this->setstate(ios_base::failbit);
|
williamr@4
|
877 |
}
|
williamr@4
|
878 |
this->width(0);
|
williamr@4
|
879 |
}
|
williamr@4
|
880 |
|
williamr@4
|
881 |
// A generic unbuffered function for ignoring characters. We stop
|
williamr@4
|
882 |
// when we reach EOF, or when the function object __is_delim returns
|
williamr@4
|
883 |
// true. In the last case, it extracts the character for which
|
williamr@4
|
884 |
// __is_delim is true, if and only if __extract_delim is true.
|
williamr@4
|
885 |
|
williamr@4
|
886 |
template < class _CharT, class _Traits, class _Is_Delim>
|
williamr@4
|
887 |
void _STLP_CALL
|
williamr@4
|
888 |
_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
|
williamr@4
|
889 |
basic_streambuf<_CharT, _Traits>* __buf,
|
williamr@4
|
890 |
_Is_Delim __is_delim,
|
williamr@4
|
891 |
bool __extract_delim, bool __set_failbit) {
|
williamr@4
|
892 |
bool __done = false;
|
williamr@4
|
893 |
ios_base::iostate __status = 0;
|
williamr@4
|
894 |
typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
|
williamr@4
|
895 |
|
williamr@4
|
896 |
_STLP_TRY {
|
williamr@4
|
897 |
while (!__done) {
|
williamr@4
|
898 |
int_type __c = __buf->sbumpc();
|
williamr@4
|
899 |
|
williamr@4
|
900 |
if (__that->_S_eof(__c)) {
|
williamr@4
|
901 |
__done = true;
|
williamr@4
|
902 |
__status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
|
williamr@4
|
903 |
: ios_base::eofbit;
|
williamr@4
|
904 |
}
|
williamr@4
|
905 |
|
williamr@4
|
906 |
else if (__is_delim(_Traits::to_char_type(__c))) {
|
williamr@4
|
907 |
__done = true;
|
williamr@4
|
908 |
if (!__extract_delim)
|
williamr@4
|
909 |
if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
|
williamr@4
|
910 |
__status |= ios_base::failbit;
|
williamr@4
|
911 |
}
|
williamr@4
|
912 |
}
|
williamr@4
|
913 |
}
|
williamr@4
|
914 |
_STLP_CATCH_ALL {
|
williamr@4
|
915 |
__that->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
916 |
}
|
williamr@4
|
917 |
|
williamr@4
|
918 |
__that->setstate(__status);
|
williamr@4
|
919 |
}
|
williamr@4
|
920 |
|
williamr@4
|
921 |
// A generic buffered function for ignoring characters. Much like
|
williamr@4
|
922 |
// _M_ignore_unbuffered, but with one additional function object:
|
williamr@4
|
923 |
// __scan_delim(first, last) returns the first pointer p in [first,
|
williamr@4
|
924 |
// last) such that __is_delim(p) is true.
|
williamr@4
|
925 |
|
williamr@4
|
926 |
template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
|
williamr@4
|
927 |
void _STLP_CALL
|
williamr@4
|
928 |
_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
|
williamr@4
|
929 |
basic_streambuf<_CharT, _Traits>* __buf,
|
williamr@4
|
930 |
_Is_Delim __is_delim, _Scan_Delim __scan_delim,
|
williamr@4
|
931 |
bool __extract_delim, bool __set_failbit) {
|
williamr@4
|
932 |
bool __at_eof = false;
|
williamr@4
|
933 |
bool __found_delim = false;
|
williamr@4
|
934 |
|
williamr@4
|
935 |
_STLP_TRY {
|
williamr@4
|
936 |
while (__buf->_M_egptr() != __buf->_M_gptr() && !__at_eof && !__found_delim) {
|
williamr@4
|
937 |
const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
|
williamr@4
|
938 |
__buf->_M_gbump((int)(__p - __buf->_M_gptr()));
|
williamr@4
|
939 |
|
williamr@4
|
940 |
if (__p != __buf->_M_egptr()) { // We found delim, so we're done.
|
williamr@4
|
941 |
if (__extract_delim)
|
williamr@4
|
942 |
__buf->_M_gbump(1);
|
williamr@4
|
943 |
__found_delim = true;
|
williamr@4
|
944 |
}
|
williamr@4
|
945 |
|
williamr@4
|
946 |
else // No delim. Try to refil the buffer.
|
williamr@4
|
947 |
__at_eof = __that->_S_eof(__buf->sgetc());
|
williamr@4
|
948 |
} // Close the while loop.
|
williamr@4
|
949 |
}
|
williamr@4
|
950 |
_STLP_CATCH_ALL {
|
williamr@4
|
951 |
__that->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
952 |
return;
|
williamr@4
|
953 |
}
|
williamr@4
|
954 |
|
williamr@4
|
955 |
if (__at_eof) {
|
williamr@4
|
956 |
__that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
|
williamr@4
|
957 |
: ios_base::eofbit);
|
williamr@4
|
958 |
return;
|
williamr@4
|
959 |
}
|
williamr@4
|
960 |
if (__found_delim)
|
williamr@4
|
961 |
return;
|
williamr@4
|
962 |
|
williamr@4
|
963 |
// If execution has reached this point, then we have an empty buffer but
|
williamr@4
|
964 |
// we have not reached eof. What that means is that the streambuf has
|
williamr@4
|
965 |
// decided to switch from a buffered to an unbuffered mode. We switch
|
williamr@4
|
966 |
// to _M_ignore_unbuffered.
|
williamr@4
|
967 |
_M_ignore_unbuffered(__that, __buf, __is_delim, __extract_delim, __set_failbit);
|
williamr@4
|
968 |
}
|
williamr@4
|
969 |
|
williamr@4
|
970 |
// Overloaded versions of _M_ignore_unbuffered and _M_ignore_unbuffered
|
williamr@4
|
971 |
// with an explicit count _Num. Return value is the number of
|
williamr@4
|
972 |
// characters extracted.
|
williamr@4
|
973 |
//
|
williamr@4
|
974 |
// The function object __max_chars takes two arguments, _Num and __n
|
williamr@4
|
975 |
// (the latter being the number of characters we have already read),
|
williamr@4
|
976 |
// and returns the maximum number of characters to read from the buffer.
|
williamr@4
|
977 |
// We parameterize _M_ignore_buffered so that we can use it for both
|
williamr@4
|
978 |
// bounded and unbounded input; for the former the function object should
|
williamr@4
|
979 |
// be minus<>, and for the latter it should return a constant maximum value.
|
williamr@4
|
980 |
|
williamr@4
|
981 |
template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim>
|
williamr@4
|
982 |
streamsize _STLP_CALL
|
williamr@4
|
983 |
_M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
|
williamr@4
|
984 |
basic_streambuf<_CharT, _Traits>* __buf,
|
williamr@4
|
985 |
streamsize _Num, _Max_Chars __max_chars,
|
williamr@4
|
986 |
_Is_Delim __is_delim,
|
williamr@4
|
987 |
bool __extract_delim, bool __set_failbit) {
|
williamr@4
|
988 |
streamsize __n = 0;
|
williamr@4
|
989 |
ios_base::iostate __status = 0;
|
williamr@4
|
990 |
typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
|
williamr@4
|
991 |
|
williamr@4
|
992 |
_STLP_TRY {
|
williamr@4
|
993 |
while (__max_chars(_Num, __n) > 0) {
|
williamr@4
|
994 |
int_type __c = __buf->sbumpc();
|
williamr@4
|
995 |
|
williamr@4
|
996 |
if (__that->_S_eof(__c)) {
|
williamr@4
|
997 |
__status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
|
williamr@4
|
998 |
: ios_base::eofbit;
|
williamr@4
|
999 |
break;
|
williamr@4
|
1000 |
}
|
williamr@4
|
1001 |
|
williamr@4
|
1002 |
else if (__is_delim(_Traits::to_char_type(__c))) {
|
williamr@4
|
1003 |
if (__extract_delim)
|
williamr@4
|
1004 |
++__n;
|
williamr@4
|
1005 |
else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
|
williamr@4
|
1006 |
__status |= ios_base::failbit;
|
williamr@4
|
1007 |
|
williamr@4
|
1008 |
break;
|
williamr@4
|
1009 |
}
|
williamr@4
|
1010 |
// fbp : added counter increment to pass Dietmar's test
|
williamr@4
|
1011 |
++__n;
|
williamr@4
|
1012 |
}
|
williamr@4
|
1013 |
}
|
williamr@4
|
1014 |
_STLP_CATCH_ALL {
|
williamr@4
|
1015 |
__that->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
1016 |
}
|
williamr@4
|
1017 |
|
williamr@4
|
1018 |
if (__status)
|
williamr@4
|
1019 |
__that->setstate(__status); // This might throw.
|
williamr@4
|
1020 |
return __n;
|
williamr@4
|
1021 |
}
|
williamr@4
|
1022 |
|
williamr@4
|
1023 |
template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim, class _Scan_Delim>
|
williamr@4
|
1024 |
streamsize _STLP_CALL
|
williamr@4
|
1025 |
_M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
|
williamr@4
|
1026 |
basic_streambuf<_CharT, _Traits>* __buf,
|
williamr@4
|
1027 |
streamsize _Num,
|
williamr@4
|
1028 |
_Max_Chars __max_chars,
|
williamr@4
|
1029 |
_Is_Delim __is_delim, _Scan_Delim __scan_delim,
|
williamr@4
|
1030 |
bool __extract_delim, bool __set_failbit) {
|
williamr@4
|
1031 |
streamsize __n = 0;
|
williamr@4
|
1032 |
bool __at_eof = false;
|
williamr@4
|
1033 |
bool __done = false;
|
williamr@4
|
1034 |
|
williamr@4
|
1035 |
_STLP_TRY {
|
williamr@4
|
1036 |
while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
|
williamr@4
|
1037 |
ptrdiff_t __avail = __buf->_M_egptr() - __buf->_M_gptr();
|
williamr@4
|
1038 |
streamsize __m = __max_chars(_Num, __n);
|
williamr@4
|
1039 |
|
williamr@4
|
1040 |
if (__avail >= __m) { // We have more characters than we need.
|
williamr@4
|
1041 |
const _CharT* __last = __buf->_M_gptr() + __STATIC_CAST(ptrdiff_t, __m);
|
williamr@4
|
1042 |
const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last);
|
williamr@4
|
1043 |
ptrdiff_t __chunk = __p - __buf->_M_gptr();
|
williamr@4
|
1044 |
__n += __chunk;
|
williamr@4
|
1045 |
__buf->_M_gbump((int)__chunk);
|
williamr@4
|
1046 |
|
williamr@4
|
1047 |
if (__extract_delim && __p != __last) {
|
williamr@4
|
1048 |
__n += 1;
|
williamr@4
|
1049 |
__buf->_M_gbump(1);
|
williamr@4
|
1050 |
}
|
williamr@4
|
1051 |
|
williamr@4
|
1052 |
__done = true;
|
williamr@4
|
1053 |
}
|
williamr@4
|
1054 |
|
williamr@4
|
1055 |
else {
|
williamr@4
|
1056 |
const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
|
williamr@4
|
1057 |
ptrdiff_t __chunk = __p - __buf->_M_gptr();
|
williamr@4
|
1058 |
__n += __chunk;
|
williamr@4
|
1059 |
__buf->_M_gbump((int)__chunk);
|
williamr@4
|
1060 |
|
williamr@4
|
1061 |
if (__p != __buf->_M_egptr()) { // We found delim.
|
williamr@4
|
1062 |
if (__extract_delim) {
|
williamr@4
|
1063 |
__n += 1;
|
williamr@4
|
1064 |
__buf->_M_gbump(1);
|
williamr@4
|
1065 |
}
|
williamr@4
|
1066 |
|
williamr@4
|
1067 |
__done = true;
|
williamr@4
|
1068 |
}
|
williamr@4
|
1069 |
|
williamr@4
|
1070 |
// We didn't find delim. Try to refill the buffer.
|
williamr@4
|
1071 |
else if (__that->_S_eof(__buf->sgetc())) {
|
williamr@4
|
1072 |
__done = true;
|
williamr@4
|
1073 |
__at_eof = true;
|
williamr@4
|
1074 |
}
|
williamr@4
|
1075 |
}
|
williamr@4
|
1076 |
} // Close the while loop.
|
williamr@4
|
1077 |
}
|
williamr@4
|
1078 |
_STLP_CATCH_ALL {
|
williamr@4
|
1079 |
__that->_M_handle_exception(ios_base::badbit);
|
williamr@4
|
1080 |
return __n;
|
williamr@4
|
1081 |
}
|
williamr@4
|
1082 |
|
williamr@4
|
1083 |
if (__at_eof)
|
williamr@4
|
1084 |
__that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
|
williamr@4
|
1085 |
: ios_base::eofbit);
|
williamr@4
|
1086 |
|
williamr@4
|
1087 |
if (__done)
|
williamr@4
|
1088 |
return __n;
|
williamr@4
|
1089 |
|
williamr@4
|
1090 |
// If execution has reached this point, then we have an empty buffer but
|
williamr@4
|
1091 |
// we have not reached eof. What that means is that the streambuf has
|
williamr@4
|
1092 |
// decided to switch from buffered to unbuffered input. We switch to
|
williamr@4
|
1093 |
// to _M_ignore_unbuffered.
|
williamr@4
|
1094 |
|
williamr@4
|
1095 |
return __n + _M_ignore_unbuffered(__that, __buf, _Num, __max_chars,
|
williamr@4
|
1096 |
__is_delim, __extract_delim, __set_failbit);
|
williamr@4
|
1097 |
}
|
williamr@4
|
1098 |
|
williamr@4
|
1099 |
|
williamr@4
|
1100 |
template <class _CharT, class _Traits>
|
williamr@4
|
1101 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
1102 |
basic_istream<_CharT, _Traits>::ignore(streamsize __n) {
|
williamr@4
|
1103 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
1104 |
this->_M_gcount = 0;
|
williamr@4
|
1105 |
|
williamr@4
|
1106 |
if (__sentry) {
|
williamr@4
|
1107 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
1108 |
typedef _STLP_PRIV _Constant_unary_fun<bool, int_type> _Const_bool;
|
williamr@4
|
1109 |
typedef _STLP_PRIV _Constant_binary_fun<streamsize, streamsize, streamsize> _Const_streamsize;
|
williamr@4
|
1110 |
const streamsize __maxss = (numeric_limits<streamsize>::max)();
|
williamr@4
|
1111 |
|
williamr@4
|
1112 |
if (__n == (numeric_limits<int>::max)()) {
|
williamr@4
|
1113 |
if (__buf->gptr() != __buf->egptr())
|
williamr@4
|
1114 |
_M_gcount = _M_ignore_buffered(this, __buf,
|
williamr@4
|
1115 |
__maxss, _Const_streamsize(__maxss),
|
williamr@4
|
1116 |
_Const_bool(false),
|
williamr@4
|
1117 |
_STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
|
williamr@4
|
1118 |
false, false);
|
williamr@4
|
1119 |
else
|
williamr@4
|
1120 |
_M_gcount = _M_ignore_unbuffered(this, __buf,
|
williamr@4
|
1121 |
__maxss, _Const_streamsize(__maxss),
|
williamr@4
|
1122 |
_Const_bool(false), false, false);
|
williamr@4
|
1123 |
}
|
williamr@4
|
1124 |
else {
|
williamr@4
|
1125 |
if (__buf->gptr() != __buf->egptr())
|
williamr@4
|
1126 |
_M_gcount = _M_ignore_buffered(this, __buf,
|
williamr@4
|
1127 |
__n, minus<streamsize>(),
|
williamr@4
|
1128 |
_Const_bool(false),
|
williamr@4
|
1129 |
_STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
|
williamr@4
|
1130 |
false, false);
|
williamr@4
|
1131 |
else
|
williamr@4
|
1132 |
_M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(),
|
williamr@4
|
1133 |
_Const_bool(false), false, false);
|
williamr@4
|
1134 |
}
|
williamr@4
|
1135 |
}
|
williamr@4
|
1136 |
|
williamr@4
|
1137 |
return *this;
|
williamr@4
|
1138 |
}
|
williamr@4
|
1139 |
|
williamr@4
|
1140 |
template <class _CharT, class _Traits>
|
williamr@4
|
1141 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
1142 |
basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim) {
|
williamr@4
|
1143 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
1144 |
this->_M_gcount = 0;
|
williamr@4
|
1145 |
|
williamr@4
|
1146 |
if (__sentry) {
|
williamr@4
|
1147 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
1148 |
typedef _STLP_PRIV _Constant_unary_fun<bool, int_type> _Const_bool;
|
williamr@4
|
1149 |
typedef _STLP_PRIV _Constant_binary_fun<streamsize, streamsize, streamsize>
|
williamr@4
|
1150 |
_Const_streamsize;
|
williamr@4
|
1151 |
const streamsize __maxss = (numeric_limits<streamsize>::max)();
|
williamr@4
|
1152 |
|
williamr@4
|
1153 |
if (__n == (numeric_limits<int>::max)()) {
|
williamr@4
|
1154 |
if (__buf->gptr() != __buf->egptr())
|
williamr@4
|
1155 |
_M_gcount = _M_ignore_buffered(this, __buf,
|
williamr@4
|
1156 |
__maxss, _Const_streamsize(__maxss),
|
williamr@4
|
1157 |
_STLP_PRIV _Eq_int_bound<_Traits>(__delim),
|
williamr@4
|
1158 |
_STLP_PRIV _Scan_for_int_val<_Traits>(__delim),
|
williamr@4
|
1159 |
true, false);
|
williamr@4
|
1160 |
else
|
williamr@4
|
1161 |
_M_gcount = _M_ignore_unbuffered(this, __buf,
|
williamr@4
|
1162 |
__maxss, _Const_streamsize(__maxss),
|
williamr@4
|
1163 |
_STLP_PRIV _Eq_int_bound<_Traits>(__delim),
|
williamr@4
|
1164 |
true, false);
|
williamr@4
|
1165 |
}
|
williamr@4
|
1166 |
else {
|
williamr@4
|
1167 |
if (__buf->gptr() != __buf->egptr())
|
williamr@4
|
1168 |
_M_gcount = _M_ignore_buffered(this, __buf,
|
williamr@4
|
1169 |
__n, minus<streamsize>(),
|
williamr@4
|
1170 |
_STLP_PRIV _Eq_int_bound<_Traits>(__delim),
|
williamr@4
|
1171 |
_STLP_PRIV _Scan_for_int_val<_Traits>(__delim),
|
williamr@4
|
1172 |
true, false);
|
williamr@4
|
1173 |
else
|
williamr@4
|
1174 |
_M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(),
|
williamr@4
|
1175 |
_STLP_PRIV _Eq_int_bound<_Traits>(__delim),
|
williamr@4
|
1176 |
true, false);
|
williamr@4
|
1177 |
}
|
williamr@4
|
1178 |
}
|
williamr@4
|
1179 |
|
williamr@4
|
1180 |
return *this;
|
williamr@4
|
1181 |
}
|
williamr@4
|
1182 |
|
williamr@4
|
1183 |
// This member function does not construct a sentry object, because
|
williamr@4
|
1184 |
// it is called from sentry's constructor.
|
williamr@4
|
1185 |
template <class _CharT, class _Traits>
|
williamr@4
|
1186 |
void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit) {
|
williamr@4
|
1187 |
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
|
williamr@4
|
1188 |
if (!__buf)
|
williamr@4
|
1189 |
this->setstate(ios_base::badbit);
|
williamr@4
|
1190 |
else if (__buf->gptr() != __buf->egptr())
|
williamr@4
|
1191 |
_M_ignore_buffered(this, __buf,
|
williamr@4
|
1192 |
_STLP_PRIV _Is_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
|
williamr@4
|
1193 |
_STLP_PRIV _Scan_for_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
|
williamr@4
|
1194 |
false, __set_failbit);
|
williamr@4
|
1195 |
else
|
williamr@4
|
1196 |
_M_ignore_unbuffered(this, __buf,
|
williamr@4
|
1197 |
_STLP_PRIV _Is_not_wspace<_Traits>(__STATIC_CAST(const ctype<_CharT>*, this->_M_ctype_facet())),
|
williamr@4
|
1198 |
false, __set_failbit);
|
williamr@4
|
1199 |
}
|
williamr@4
|
1200 |
|
williamr@4
|
1201 |
|
williamr@4
|
1202 |
// This is a very simple loop that reads characters from __src and puts
|
williamr@4
|
1203 |
// them into __dest. It looks complicated because of the (standard-
|
williamr@4
|
1204 |
// mandated) exception handling policy.
|
williamr@4
|
1205 |
//
|
williamr@4
|
1206 |
// We stop when we get an exception, when we fail to insert into the
|
williamr@4
|
1207 |
// output streambuf, or when __is_delim is true.
|
williamr@4
|
1208 |
|
williamr@4
|
1209 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
1210 |
|
williamr@4
|
1211 |
template < class _CharT, class _Traits, class _Is_Delim>
|
williamr@4
|
1212 |
streamsize _STLP_CALL
|
williamr@4
|
1213 |
__copy_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
|
williamr@4
|
1214 |
basic_streambuf<_CharT, _Traits>* __dest,
|
williamr@4
|
1215 |
_Is_Delim __is_delim,
|
williamr@4
|
1216 |
bool __extract_delim, bool __rethrow) {
|
williamr@4
|
1217 |
streamsize __extracted = 0;
|
williamr@4
|
1218 |
ios_base::iostate __status = 0;
|
williamr@4
|
1219 |
typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
|
williamr@4
|
1220 |
int_type __c;
|
williamr@4
|
1221 |
|
williamr@4
|
1222 |
_STLP_TRY {
|
williamr@4
|
1223 |
for (;;) {
|
williamr@4
|
1224 |
// Get a character. If there's an exception, catch and (maybe) rethrow it.
|
williamr@4
|
1225 |
__c = __src->sbumpc();
|
williamr@4
|
1226 |
|
williamr@4
|
1227 |
// If we failed to get a character, then quit.
|
williamr@4
|
1228 |
if (__that->_S_eof(__c)) {
|
williamr@4
|
1229 |
__status |= ios_base::eofbit;
|
williamr@4
|
1230 |
break;
|
williamr@4
|
1231 |
}
|
williamr@4
|
1232 |
// If it's the delimiter, then quit.
|
williamr@4
|
1233 |
else if (__is_delim(_Traits::to_char_type(__c))) {
|
williamr@4
|
1234 |
if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c)))
|
williamr@4
|
1235 |
__status |= ios_base::failbit;
|
williamr@4
|
1236 |
break;
|
williamr@4
|
1237 |
}
|
williamr@4
|
1238 |
else {
|
williamr@4
|
1239 |
// Try to put the character in the output streambuf.
|
williamr@4
|
1240 |
bool __failed = false;
|
williamr@4
|
1241 |
_STLP_TRY {
|
williamr@4
|
1242 |
if (!__that->_S_eof(__dest->sputc(_Traits::to_char_type(__c))))
|
williamr@4
|
1243 |
++__extracted;
|
williamr@4
|
1244 |
else
|
williamr@4
|
1245 |
__failed = true;
|
williamr@4
|
1246 |
}
|
williamr@4
|
1247 |
_STLP_CATCH_ALL {
|
williamr@4
|
1248 |
__failed = true;
|
williamr@4
|
1249 |
}
|
williamr@4
|
1250 |
|
williamr@4
|
1251 |
// If we failed to put the character in the output streambuf, then
|
williamr@4
|
1252 |
// try to push it back to the input streambuf.
|
williamr@4
|
1253 |
if (__failed && !__pushback(__src, _Traits::to_char_type(__c)))
|
williamr@4
|
1254 |
__status |= ios_base::failbit;
|
williamr@4
|
1255 |
|
williamr@4
|
1256 |
// fbp : avoiding infinite loop in io-27-6-1-2-3.exp
|
williamr@4
|
1257 |
if (__failed)
|
williamr@4
|
1258 |
break;
|
williamr@4
|
1259 |
}
|
williamr@4
|
1260 |
|
williamr@4
|
1261 |
} /* for (;;) */
|
williamr@4
|
1262 |
|
williamr@4
|
1263 |
}
|
williamr@4
|
1264 |
// fbp : this try/catch moved here in reasonable assumption
|
williamr@4
|
1265 |
// __is_delim never throw (__pushback is guaranteed not to)
|
williamr@4
|
1266 |
_STLP_CATCH_ALL {
|
williamr@4
|
1267 |
// See 27.6.1.2.3, paragraph 13.
|
williamr@4
|
1268 |
if (__rethrow && __extracted == 0)
|
williamr@4
|
1269 |
__that->_M_handle_exception(ios_base::failbit);
|
williamr@4
|
1270 |
}
|
williamr@4
|
1271 |
__that->setstate(__status);
|
williamr@4
|
1272 |
return __extracted;
|
williamr@4
|
1273 |
}
|
williamr@4
|
1274 |
|
williamr@4
|
1275 |
// Buffered copying from one streambuf to another. We copy the characters
|
williamr@4
|
1276 |
// in chunks, rather than one at a time. We still have to worry about all
|
williamr@4
|
1277 |
// of the error conditions we checked in __copy_unbuffered, plus one more:
|
williamr@4
|
1278 |
// the streambuf might decide to switch from a buffered to an unbuffered mode.
|
williamr@4
|
1279 |
|
williamr@4
|
1280 |
template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
|
williamr@4
|
1281 |
streamsize _STLP_CALL
|
williamr@4
|
1282 |
__copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
|
williamr@4
|
1283 |
basic_streambuf<_CharT, _Traits>* __dest,
|
williamr@4
|
1284 |
_Scan_Delim __scan_delim, _Is_Delim __is_delim,
|
williamr@4
|
1285 |
bool __extract_delim, bool __rethrow) {
|
williamr@4
|
1286 |
streamsize __extracted = 0;
|
williamr@4
|
1287 |
ios_base::iostate __status = 0;
|
williamr@4
|
1288 |
typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
|
williamr@4
|
1289 |
//Borland compiler generates a warning if assignment because value is never used:
|
williamr@4
|
1290 |
int_type __c /*= _Traits::eof()*/;
|
williamr@4
|
1291 |
_CharT* __first = __src->_M_gptr();
|
williamr@4
|
1292 |
ptrdiff_t __avail = __src->_M_egptr() - __first;
|
williamr@4
|
1293 |
// fbp : introduced to move catch/try blocks out of the loop
|
williamr@4
|
1294 |
bool __do_handle_exceptions = false;
|
williamr@4
|
1295 |
|
williamr@4
|
1296 |
_STLP_TRY {
|
williamr@4
|
1297 |
for (;;) {
|
williamr@4
|
1298 |
const _CharT* __last = __scan_delim(__first, __src->_M_egptr());
|
williamr@4
|
1299 |
|
williamr@4
|
1300 |
// Try to copy the entire input buffer to the output buffer.
|
williamr@4
|
1301 |
streamsize __n = __dest->sputn(__first, __extract_delim && __last != __src->_M_egptr()
|
williamr@4
|
1302 |
? (__last - __first) + 1
|
williamr@4
|
1303 |
: (__last - __first));
|
williamr@4
|
1304 |
__src->_M_gbump((int)__n);
|
williamr@4
|
1305 |
__extracted += __n;
|
williamr@4
|
1306 |
|
williamr@4
|
1307 |
// from this on, catch() will call _M_handle_exceptions()
|
williamr@4
|
1308 |
__do_handle_exceptions = true;
|
williamr@4
|
1309 |
|
williamr@4
|
1310 |
if (__n < __avail) // We found the delimiter, or else failed to
|
williamr@4
|
1311 |
break; // copy some characters.
|
williamr@4
|
1312 |
|
williamr@4
|
1313 |
__c = __src->sgetc();
|
williamr@4
|
1314 |
|
williamr@4
|
1315 |
// Three possibilities: we succeeded in refilling the buffer, or
|
williamr@4
|
1316 |
// we got EOF, or the streambuf has switched to unbuffered mode.
|
williamr@4
|
1317 |
__first = __src->_M_gptr();
|
williamr@4
|
1318 |
__avail = __src->_M_egptr() - __first;
|
williamr@4
|
1319 |
|
williamr@4
|
1320 |
if (__avail > 0)
|
williamr@4
|
1321 |
{} // dwa 1/16/00 -- suppress a Metrowerks warning
|
williamr@4
|
1322 |
else if (__that->_S_eof(__c)) {
|
williamr@4
|
1323 |
__status |= ios_base::eofbit;
|
williamr@4
|
1324 |
break;
|
williamr@4
|
1325 |
}
|
williamr@4
|
1326 |
else {
|
williamr@4
|
1327 |
return __extracted + __copy_unbuffered(__that, __src, __dest, __is_delim,
|
williamr@4
|
1328 |
__extract_delim, __rethrow);
|
williamr@4
|
1329 |
}
|
williamr@4
|
1330 |
|
williamr@4
|
1331 |
__do_handle_exceptions = false;
|
williamr@4
|
1332 |
}
|
williamr@4
|
1333 |
}
|
williamr@4
|
1334 |
|
williamr@4
|
1335 |
_STLP_CATCH_ALL {
|
williamr@4
|
1336 |
// See 27.6.1.2.3, paragraph 13.
|
williamr@4
|
1337 |
if (__rethrow && __do_handle_exceptions && __extracted == 0)
|
williamr@4
|
1338 |
__that->_M_handle_exception(ios_base::failbit);
|
williamr@4
|
1339 |
}
|
williamr@4
|
1340 |
|
williamr@4
|
1341 |
if (__status)
|
williamr@4
|
1342 |
__that->setstate(__status); // This might throw.
|
williamr@4
|
1343 |
return __extracted;
|
williamr@4
|
1344 |
}
|
williamr@4
|
1345 |
|
williamr@4
|
1346 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
1347 |
|
williamr@4
|
1348 |
template <class _CharT, class _Traits>
|
williamr@4
|
1349 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
1350 |
basic_istream<_CharT, _Traits>
|
williamr@4
|
1351 |
::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim) {
|
williamr@4
|
1352 |
sentry __sentry(*this, _No_Skip_WS());
|
williamr@4
|
1353 |
this->_M_gcount = 0;
|
williamr@4
|
1354 |
|
williamr@4
|
1355 |
if (__sentry) {
|
williamr@4
|
1356 |
basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
|
williamr@4
|
1357 |
|
williamr@4
|
1358 |
if (__src)
|
williamr@4
|
1359 |
this->_M_gcount = __src->egptr() != __src->gptr()
|
williamr@4
|
1360 |
? _STLP_PRIV __copy_buffered(this, __src, &__dest,
|
williamr@4
|
1361 |
_STLP_PRIV _Scan_for_char_val<_Traits>(__delim),
|
williamr@4
|
1362 |
_STLP_PRIV _Eq_char_bound<_Traits>(__delim),
|
williamr@4
|
1363 |
false, false)
|
williamr@4
|
1364 |
: _STLP_PRIV __copy_unbuffered(this, __src, &__dest,
|
williamr@4
|
1365 |
_STLP_PRIV _Eq_char_bound<_Traits>(__delim),
|
williamr@4
|
1366 |
false, false);
|
williamr@4
|
1367 |
}
|
williamr@4
|
1368 |
|
williamr@4
|
1369 |
if (this->_M_gcount == 0)
|
williamr@4
|
1370 |
this->setstate(ios_base::failbit);
|
williamr@4
|
1371 |
|
williamr@4
|
1372 |
return *this;
|
williamr@4
|
1373 |
}
|
williamr@4
|
1374 |
|
williamr@4
|
1375 |
// Copying characters into a streambuf.
|
williamr@4
|
1376 |
template <class _CharT, class _Traits>
|
williamr@4
|
1377 |
basic_istream<_CharT, _Traits>&
|
williamr@4
|
1378 |
basic_istream<_CharT, _Traits>
|
williamr@4
|
1379 |
::operator>>(basic_streambuf<_CharT, _Traits>* __dest) {
|
williamr@4
|
1380 |
streamsize __n = 0;
|
williamr@4
|
1381 |
typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
|
williamr@4
|
1382 |
_Sentry __sentry(*this);
|
williamr@4
|
1383 |
if (__sentry) {
|
williamr@4
|
1384 |
basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
|
williamr@4
|
1385 |
if (__src && __dest)
|
williamr@4
|
1386 |
__n = __src->egptr() != __src->gptr()
|
williamr@4
|
1387 |
? _STLP_PRIV __copy_buffered(this, __src, __dest,
|
williamr@4
|
1388 |
_STLP_PRIV _Project2nd<const _CharT*, const _CharT*>(),
|
williamr@4
|
1389 |
_STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
|
williamr@4
|
1390 |
false, true)
|
williamr@4
|
1391 |
: _STLP_PRIV __copy_unbuffered(this, __src, __dest,
|
williamr@4
|
1392 |
_STLP_PRIV _Constant_unary_fun<bool, int_type>(false),
|
williamr@4
|
1393 |
false, true);
|
williamr@4
|
1394 |
}
|
williamr@4
|
1395 |
|
williamr@4
|
1396 |
if (__n == 0)
|
williamr@4
|
1397 |
this->setstate(ios_base::failbit);
|
williamr@4
|
1398 |
|
williamr@4
|
1399 |
return *this;
|
williamr@4
|
1400 |
}
|
williamr@4
|
1401 |
|
williamr@4
|
1402 |
// ----------------------------------------------------------------
|
williamr@4
|
1403 |
// basic_iostream<> class
|
williamr@4
|
1404 |
// ----------------------------------------------------------------
|
williamr@4
|
1405 |
|
williamr@4
|
1406 |
template <class _CharT, class _Traits>
|
williamr@4
|
1407 |
basic_iostream<_CharT, _Traits>
|
williamr@4
|
1408 |
::basic_iostream(basic_streambuf<_CharT, _Traits>* __buf)
|
williamr@4
|
1409 |
: basic_ios<_CharT, _Traits>(),
|
williamr@4
|
1410 |
basic_istream<_CharT, _Traits>(__buf),
|
williamr@4
|
1411 |
basic_ostream<_CharT, _Traits>(__buf) {
|
williamr@4
|
1412 |
this->init(__buf);
|
williamr@4
|
1413 |
}
|
williamr@4
|
1414 |
|
williamr@4
|
1415 |
template <class _CharT, class _Traits>
|
williamr@4
|
1416 |
basic_iostream<_CharT, _Traits>::~basic_iostream()
|
williamr@4
|
1417 |
{}
|
williamr@4
|
1418 |
|
williamr@4
|
1419 |
_STLP_END_NAMESPACE
|
williamr@4
|
1420 |
|
williamr@4
|
1421 |
#undef __BIS_int_type__
|
williamr@4
|
1422 |
#undef __BIS_pos_type__
|
williamr@4
|
1423 |
#undef __BIS_off_type__
|
williamr@4
|
1424 |
|
williamr@4
|
1425 |
#endif /* _STLP_ISTREAM_C */
|
williamr@4
|
1426 |
|
williamr@4
|
1427 |
// Local Variables:
|
williamr@4
|
1428 |
// mode:C++
|
williamr@4
|
1429 |
// End:
|