1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | #ifndef _STLP_ISTREAM_C |
19 | #define _STLP_ISTREAM_C |
20 | |
21 | # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION1) |
22 | |
23 | #ifndef _STLP_LIMITS_H |
24 | # include <stl/_limits.h> |
25 | #endif |
26 | |
27 | #ifndef _STLP_INTERNAL_NUM_GET_H |
28 | # include <stl/_num_get.h> |
29 | #endif |
30 | |
31 | # if defined ( _STLP_NESTED_TYPE_PARAM_BUG ) |
32 | |
33 | # define __BIS_int_type__ int |
34 | # define __BIS_pos_type__ streampos |
35 | # define __BIS_off_type__ streamoff |
36 | # else |
37 | # define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPEtypename basic_istream<_CharT, _Traits>::int_type |
38 | # define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPEtypename basic_istream<_CharT, _Traits>::pos_type |
39 | # define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPEtypename basic_istream<_CharT, _Traits>::off_type |
40 | # endif |
41 | |
42 | _STLP_BEGIN_NAMESPACEnamespace _STL { |
43 | |
44 | |
45 | |
46 | |
47 | template <class _Traits> |
48 | struct _Is_not_wspace { |
49 | typedef typename _Traits::char_type argument_type; |
50 | typedef bool result_type; |
51 | |
52 | const ctype<argument_type>* _M_ctype; |
53 | |
54 | _Is_not_wspace(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {} |
55 | bool operator()(argument_type __c) const |
56 | { return !_M_ctype->is(ctype_base::space, __c); } |
57 | }; |
58 | |
59 | template <class _Traits> |
60 | struct _Is_wspace_null { |
61 | typedef typename _Traits::char_type argument_type; |
62 | typedef bool result_type; |
63 | |
64 | const ctype<argument_type>* _M_ctype; |
65 | |
66 | _Is_wspace_null(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {} |
67 | bool operator()(argument_type __c) const { |
68 | return _Traits::eq(__c, argument_type()) || |
69 | _M_ctype->is(ctype_base::space, __c); |
70 | } |
71 | }; |
72 | |
73 | template <class _Traits> |
74 | struct _Scan_for_wspace { |
75 | typedef typename _Traits::char_type char_type; |
76 | typedef char_type* first_argument_type; |
77 | typedef char_type* second_argument_type; |
78 | typedef char_type* result_type; |
79 | |
80 | const ctype<char_type>* _M_ctype; |
81 | |
82 | _Scan_for_wspace(const ctype<char_type>* __ctype) : _M_ctype(__ctype) {} |
83 | const char_type* |
84 | operator()(const char_type* __first, const char_type* __last) const { |
85 | return _M_ctype->scan_is(ctype_base::space, __first, __last); |
86 | } |
87 | }; |
88 | |
89 | template <class _Traits> |
90 | struct _Scan_wspace_null { |
91 | typedef typename _Traits::char_type char_type; |
92 | typedef char_type* first_argument_type; |
93 | typedef char_type* second_argument_type; |
94 | typedef char_type* result_type; |
95 | |
96 | const ctype<char_type>* _M_ctype; |
97 | |
98 | _Scan_wspace_null(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {} |
99 | const char_type* |
100 | operator()(const char_type* __first, const char_type* __last) const { |
101 | __last = find_if(__first, __last, |
102 | _Eq_char_bound<_Traits>(char_type())); |
103 | return _M_ctype->scan_is(ctype_base::space, __first, __last); |
104 | } |
105 | }; |
106 | |
107 | template <class _Traits> |
108 | struct _Scan_for_not_wspace { |
109 | typedef typename _Traits::char_type char_type; |
110 | typedef char_type* first_argument_type; |
111 | typedef char_type* second_argument_type; |
112 | typedef char_type* result_type; |
113 | |
114 | const ctype<char_type>* _M_ctype; |
115 | |
116 | _Scan_for_not_wspace(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {} |
117 | const char_type* |
118 | operator()(const char_type* __first, const char_type* __last) const { |
119 | return _M_ctype->scan_not(ctype_base::space, __first, __last); |
120 | } |
121 | }; |
122 | |
123 | template <class _Traits> |
124 | struct _Scan_for_char_val |
125 | { |
126 | typedef typename _Traits::char_type char_type; |
127 | typedef char_type* first_argument_type; |
128 | typedef char_type* second_argument_type; |
129 | typedef char_type* result_type; |
130 | |
131 | char_type _M_val; |
132 | |
133 | _Scan_for_char_val(char_type __value) : _M_val(__value) {} |
134 | |
135 | const char_type* |
136 | operator()(const char_type* __first, const char_type* __last) const { |
137 | return find_if(__first, __last, _Eq_char_bound<_Traits>(_M_val)); |
138 | } |
139 | }; |
140 | |
141 | template <class _Traits> |
142 | struct _Scan_for_int_val |
143 | { |
144 | typedef typename _Traits::char_type char_type; |
145 | typedef typename _Traits::int_type int_type; |
146 | typedef char_type* first_argument_type; |
147 | typedef char_type* second_argument_type; |
148 | typedef char_type* result_type; |
149 | |
150 | int_type _M_val; |
151 | |
152 | _Scan_for_int_val(int_type __value) : _M_val(__value) {} |
153 | |
154 | const char_type* |
155 | operator()(const char_type* __first, const char_type* __last) const { |
156 | return find_if(__first, __last, |
157 | _Eq_int_bound<_Traits>(_M_val)); |
158 | } |
159 | }; |
160 | |
161 | |
162 | |
163 | |
164 | template <class _CharT, class _Traits> |
165 | bool _STLP_CALL |
166 | __pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c) |
167 | { |
168 | bool ret; |
169 | _STLP_TRYtry { |
170 | const typename _Traits::int_type __eof = _Traits::eof(); |
171 | ret = !_Traits::eq_int_type(__buf->sputbackc(__c), __eof); |
172 | } |
173 | _STLP_CATCH_ALLcatch(...) { |
174 | ret = false; |
175 | } |
176 | return ret; |
177 | } |
178 | |
179 | template <class _CharT, class _Traits> |
180 | basic_istream<_CharT, _Traits>& _STLP_CALL |
181 | ws(basic_istream<_CharT, _Traits>& __is) |
182 | { |
183 | typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry; |
184 | _Sentry __sentry(__is, _No_Skip_WS()); |
185 | if (__sentry) |
186 | __is._M_skip_whitespace(false); |
187 | return __is; |
188 | } |
189 | |
190 | |
191 | template <class _CharT, class _Traits> |
192 | bool |
193 | _M_init_skip(basic_istream<_CharT, _Traits>& __is) { |
194 | if (__is.good()) { |
195 | if (__is.tie()) |
196 | __is.tie()->flush(); |
197 | |
198 | __is._M_skip_whitespace(true); |
199 | } |
200 | |
201 | if (!__is.good()) { |
202 | __is.setstate(ios_base::failbit); |
203 | return false; |
204 | } else |
205 | return true; |
206 | } |
207 | |
208 | template <class _CharT, class _Traits> |
209 | bool |
210 | _M_init_noskip(basic_istream<_CharT, _Traits>& __is){ |
211 | if (__is.good()) { |
212 | if (__is.tie()) |
213 | __is.tie()->flush(); |
214 | |
215 | if (!__is.rdbuf()) |
216 | __is.setstate(ios_base::badbit); |
217 | } |
218 | else |
219 | __is.setstate(ios_base::failbit); |
220 | return __is.good(); |
221 | } |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | template <class _CharT, class _Traits, class _Number> |
228 | ios_base::iostate _STLP_CALL |
229 | _M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val) |
230 | { |
231 | typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry; |
232 | ios_base::iostate __err = 0; |
233 | _Sentry __sentry( __that ); |
234 | if (__sentry) { |
235 | typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > _Num_get; |
236 | _STLP_TRYtry { |
237 | ((const _Num_get&)use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()), |
238 | 0, __that, __err, __val); |
239 | } |
240 | _STLP_CATCH_ALLcatch(...) { |
241 | __that._M_handle_exception(ios_base::badbit); |
242 | } |
243 | if (__err) __that.setstate(__err); |
244 | } |
245 | return __err; |
246 | } |
247 | |
248 | |
249 | |
250 | |
251 | template <class _CharT, class _Traits> |
252 | __BIS_int_type__ |
253 | basic_istream<_CharT, _Traits>::peek() |
254 | { |
255 | typename _Traits::int_type __tmp = _Traits::eof(); |
256 | |
257 | this->_M_gcount = 0; |
258 | sentry __sentry(*this, _No_Skip_WS()); |
259 | |
260 | if (__sentry) { |
261 | _STLP_TRYtry { |
262 | __tmp = this->rdbuf()->sgetc(); |
263 | } |
264 | _STLP_CATCH_ALLcatch(...) { |
265 | this->_M_handle_exception(ios_base::badbit); |
266 | } |
267 | if (this->_S_eof(__tmp)) |
268 | this->setstate(ios_base::eofbit); |
269 | } |
270 | |
271 | return __tmp; |
272 | } |
273 | |
274 | |
275 | template <class _CharT, class _Traits> |
276 | __BIS_int_type__ |
277 | basic_istream<_CharT, _Traits>::get() |
278 | { |
279 | typename _Traits::int_type __tmp = _Traits::eof(); |
280 | sentry __sentry(*this, _No_Skip_WS()); |
281 | this->_M_gcount = 0; |
282 | |
283 | if (__sentry) { |
284 | _STLP_TRYtry { |
285 | __tmp = this->rdbuf()->sbumpc(); |
286 | } |
287 | _STLP_CATCH_ALLcatch(...) { |
288 | this->_M_handle_exception(ios_base::badbit); |
289 | } |
290 | |
291 | if (!this->_S_eof(__tmp)) |
292 | this->_M_gcount = 1; |
293 | } |
294 | |
295 | if (_M_gcount == 0) |
296 | this->setstate(ios_base::eofbit | ios_base::failbit); |
297 | |
298 | return __tmp; |
299 | } |
300 | |
301 | template <class _CharT, class _Traits> |
302 | basic_istream<_CharT, _Traits>& |
303 | basic_istream<_CharT, _Traits>::get(_CharT& __c) |
304 | { |
305 | sentry __sentry(*this, _No_Skip_WS()); |
306 | this->_M_gcount = 0; |
307 | |
308 | if (__sentry) { |
309 | typename _Traits::int_type __tmp = _Traits::eof(); |
310 | _STLP_TRYtry { |
311 | __tmp = this->rdbuf()->sbumpc(); |
312 | } |
313 | _STLP_CATCH_ALLcatch(...) { |
314 | this->_M_handle_exception(ios_base::badbit); |
315 | } |
316 | |
317 | if (!this->_S_eof(__tmp)) { |
318 | this->_M_gcount = 1; |
319 | __c = _Traits::to_char_type(__tmp); |
320 | } |
321 | } |
322 | |
323 | if (this->_M_gcount == 0) |
324 | this->setstate(ios_base::eofbit | ios_base::failbit); |
325 | |
326 | return *this; |
327 | } |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | |
335 | template <class _CharT, class _Traits> |
336 | basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore() |
337 | { |
338 | sentry __sentry(*this, _No_Skip_WS()); |
339 | this->_M_gcount = 0; |
340 | |
341 | if (__sentry) { |
342 | int_type __c; |
343 | _STLP_TRYtry { |
344 | __c = this->rdbuf()->sbumpc(); |
345 | } |
346 | _STLP_CATCH_ALLcatch(...) { |
347 | this->_M_handle_exception(ios_base::badbit); |
348 | return *this; |
349 | } |
350 | |
351 | if (!this->_S_eof(__c)) |
352 | this->_M_gcount = 1; |
353 | else |
354 | this->setstate(ios_base::eofbit); |
355 | } |
356 | |
357 | return *this; |
358 | } |
359 | |
360 | |
361 | |
362 | template <class _CharT, class _Traits> |
363 | basic_istream<_CharT, _Traits>& |
364 | basic_istream<_CharT, _Traits>::putback(_CharT __c) { |
365 | this->_M_gcount = 0; |
366 | sentry __sentry(*this, _No_Skip_WS()); |
367 | |
368 | if (__sentry) { |
369 | typename _Traits::int_type __tmp = _Traits::eof(); |
370 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
371 | |
372 | if (__buf) { |
373 | _STLP_TRYtry { |
374 | __tmp = __buf->sputbackc(__c); |
375 | } |
376 | _STLP_CATCH_ALLcatch(...) { |
377 | this->_M_handle_exception(ios_base::badbit); |
378 | } |
379 | } |
380 | if (this->_S_eof(__tmp)) |
381 | this->setstate(ios_base::badbit); |
382 | } |
383 | else |
384 | this->setstate(ios_base::failbit); |
385 | |
386 | return *this; |
387 | } |
388 | |
389 | template <class _CharT, class _Traits> |
390 | basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() { |
391 | this->_M_gcount = 0; |
392 | |
393 | sentry __sentry(*this, _No_Skip_WS()); |
394 | |
395 | if (__sentry) { |
396 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
397 | |
398 | if (__buf) { |
399 | _STLP_TRYtry { |
400 | _CharT __tmp; |
401 | __tmp = __buf->sungetc(); |
402 | if (this->_S_eof(__tmp)) |
403 | this->setstate(ios_base::badbit); |
404 | } |
405 | _STLP_CATCH_ALLcatch(...) { |
406 | this->_M_handle_exception(ios_base::badbit); |
407 | } |
408 | } else |
409 | this->setstate(ios_base::badbit); |
410 | } |
411 | else |
412 | this->setstate(ios_base::failbit); |
413 | |
414 | return *this; |
415 | } |
416 | |
417 | |
418 | |
419 | template <class _CharT, class _Traits> |
420 | int basic_istream<_CharT, _Traits>::sync() { |
421 | sentry __sentry(*this, _No_Skip_WS()); |
422 | |
423 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
424 | if (__buf) { |
425 | if (__buf->pubsync() == -1) { |
426 | this->setstate(ios_base::badbit); |
427 | return -1; |
428 | } |
429 | else |
430 | return 0; |
431 | } |
432 | else |
433 | return -1; |
434 | } |
435 | |
436 | template <class _CharT, class _Traits> |
437 | __BIS_pos_type__ |
438 | basic_istream<_CharT, _Traits>::tellg() { |
439 | |
440 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
441 | return (__buf && !this->fail()) ? __buf->pubseekoff(0, ios_base::cur, ios_base::in) |
442 | : pos_type(-1); |
443 | } |
444 | |
445 | template <class _CharT, class _Traits> |
446 | basic_istream<_CharT, _Traits>& |
447 | basic_istream<_CharT, _Traits>::seekg(pos_type __pos) { |
448 | sentry __sentry(*this, _No_Skip_WS()); |
449 | |
450 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
451 | if (!this->fail() && __buf) |
452 | __buf->pubseekpos(__pos, ios_base::in); |
453 | return *this; |
454 | } |
455 | |
456 | template <class _CharT, class _Traits> |
457 | basic_istream<_CharT, _Traits>& |
458 | basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) |
459 | { |
460 | sentry __sentry(*this, _No_Skip_WS()); |
461 | |
462 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
463 | if (!this->fail() && __buf) |
464 | __buf->pubseekoff(__off, __dir, ios_base::in); |
465 | return *this; |
466 | } |
467 | |
468 | |
469 | |
470 | template <class _CharT, class _Traits> |
471 | void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c) |
472 | { |
473 | |
474 | |
475 | sentry __sentry(*this); |
476 | |
477 | if (__sentry) { |
478 | typename _Traits::int_type __tmp = _Traits::eof(); |
479 | |
480 | _STLP_TRYtry { |
481 | __tmp = this->rdbuf()->sbumpc(); |
482 | } |
483 | _STLP_CATCH_ALLcatch(...) { |
484 | this->_M_handle_exception(ios_base::badbit); |
485 | return; |
486 | } |
487 | |
488 | if (!this->_S_eof(__tmp)) |
489 | __c = _Traits::to_char_type(__tmp); |
490 | else |
491 | this->setstate(ios_base::eofbit | ios_base::failbit); |
492 | } |
493 | } |
494 | |
495 | |
496 | |
497 | |
498 | |
499 | |
500 | |
501 | |
502 | |
503 | |
504 | |
505 | |
506 | |
507 | |
508 | |
509 | |
510 | |
511 | |
512 | |
513 | |
514 | |
515 | |
516 | |
517 | template < class _CharT, class _Traits, class _Is_Delim> |
518 | streamsize _STLP_CALL |
519 | _M_read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf, |
520 | streamsize _Num, _CharT* __s, |
521 | _Is_Delim __is_delim, |
522 | bool __extract_delim, bool __append_null, |
523 | bool __is_getline) |
524 | { |
525 | streamsize __n = 0; |
526 | ios_base::iostate __status = 0; |
527 | |
528 | typedef typename basic_istream<_CharT, _Traits>::int_type int_type; |
529 | |
530 | _STLP_TRYtry { |
531 | int_type __c = __buf->sgetc(); |
532 | while (true) { |
533 | if (__that->_S_eof(__c)) { |
534 | if (__n < _Num || __is_getline) |
535 | __status |= ios_base::eofbit; |
536 | break; |
537 | } |
538 | |
539 | else if (__is_delim(__c)) { |
540 | if (__extract_delim) { |
541 | __buf->sbumpc(); |
542 | ++__n; |
543 | } |
544 | break; |
545 | } |
546 | |
547 | else if (__n == _Num) { |
548 | if (__is_getline) |
549 | __status |= ios_base::failbit; |
550 | break; |
551 | } |
552 | |
553 | *__s++ = _Traits::to_char_type(__c); |
554 | ++__n; |
555 | __c = __buf->snextc(); |
556 | } |
557 | } |
558 | _STLP_CATCH_ALLcatch(...) { |
559 | __that->_M_handle_exception(ios_base::badbit); |
560 | *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT)_CharT(); |
561 | return __n; |
562 | } |
563 | |
564 | if (__append_null) |
565 | *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT)_CharT(); |
566 | if (__status) |
567 | __that->setstate(__status); |
568 | return __n; |
569 | } |
570 | |
571 | |
572 | |
573 | |
574 | |
575 | template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim> |
576 | streamsize _STLP_CALL |
577 | _M_read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf, |
578 | streamsize _Num, _CharT* __s, |
579 | _Is_Delim __is_delim, _Scan_Delim __scan_delim, |
580 | bool __extract_delim, bool __append_null, |
581 | bool __is_getline) |
582 | { |
583 | streamsize __n = 0; |
584 | ios_base::iostate __status = 0; |
585 | bool __done = false; |
586 | |
587 | _STLP_TRYtry { |
588 | while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) { |
589 | const _CharT* __first = __buf->_M_gptr(); |
590 | const _CharT* __last = __buf->_M_egptr(); |
591 | ptrdiff_t __request = _Num - __n; |
592 | |
593 | const _CharT* __p = __scan_delim(__first, __last); |
594 | ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request); |
595 | _Traits::copy(__s, __first, __chunk); |
596 | __s += __chunk; |
597 | __n += __chunk; |
598 | __buf->_M_gbump((int)__chunk); |
599 | |
600 | |
601 | if (__p != __last && __p - __first <= __request) { |
602 | if (__extract_delim) { |
603 | __n += 1; |
604 | __buf->_M_gbump(1); |
605 | } |
606 | __done = true; |
607 | } |
608 | |
609 | |
610 | else if(__n == _Num) { |
611 | |
612 | |
613 | if (__is_getline) { |
614 | if (__chunk == __last - __first) { |
615 | if (__that->_S_eof(__buf->sgetc())) |
616 | __status |= ios_base::eofbit; |
617 | } |
618 | else |
619 | __status |= ios_base::failbit; |
620 | } |
621 | __done = true; |
622 | } |
623 | |
624 | |
625 | |
626 | else { |
627 | if (__that->_S_eof(__buf->sgetc())) { |
628 | __status |= ios_base::eofbit; |
629 | __done = true; |
630 | } |
631 | } |
632 | } |
633 | } |
634 | _STLP_CATCH_ALLcatch(...) { |
635 | __that->_M_handle_exception(ios_base::badbit); |
636 | __done = true; |
637 | } |
638 | |
639 | if (__done) { |
640 | if (__append_null) |
641 | *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT)_CharT(); |
642 | if (__status != 0) |
643 | __that->setstate(__status); |
644 | return __n; |
645 | } |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | |
652 | return __n + _M_read_unbuffered(__that, __buf, _Num - __n, __s, __is_delim, |
653 | __extract_delim,__append_null,__is_getline); |
654 | } |
655 | |
656 | |
657 | |
658 | |
659 | template <class _CharT, class _Traits> |
660 | basic_istream<_CharT, _Traits>& |
661 | basic_istream<_CharT, _Traits>::get(_CharT* __s, streamsize __n, |
662 | _CharT __delim) { |
663 | sentry __sentry(*this, _No_Skip_WS()); |
664 | this->_M_gcount = 0; |
665 | |
666 | if (__sentry) { |
667 | if (__n > 0) { |
668 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
669 | |
670 | if (__buf->egptr() != __buf->gptr()) |
671 | this->_M_gcount = |
672 | _M_read_buffered(this, __buf, __n - 1, __s, |
673 | _Eq_char_bound<_Traits>(__delim), |
674 | _Scan_for_char_val<_Traits>(__delim), |
675 | false, true, false); |
676 | else |
677 | this->_M_gcount = |
678 | _M_read_unbuffered(this, __buf, __n - 1, __s, |
679 | _Eq_char_bound<_Traits>(__delim), |
680 | false, true, false); |
681 | } |
682 | } |
683 | |
684 | if (this->_M_gcount == 0) |
685 | this->setstate(ios_base::failbit); |
686 | |
687 | return *this; |
688 | } |
689 | |
690 | |
691 | |
692 | template <class _CharT, class _Traits> |
693 | basic_istream<_CharT, _Traits>& |
694 | basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n, |
695 | _CharT __delim) { |
696 | sentry __sentry(*this, _No_Skip_WS()); |
697 | this->_M_gcount = 0; |
698 | |
699 | if (__sentry) { |
700 | if (__n > 0) { |
701 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
702 | this->_M_gcount = __buf->egptr() != __buf->gptr() |
703 | ? _M_read_buffered(this, __buf, __n - 1, __s, |
704 | _Eq_char_bound<_Traits>(__delim), |
705 | _Scan_for_char_val<_Traits>(__delim), |
706 | true, true, true) |
707 | : _M_read_unbuffered(this, __buf, __n - 1, __s, |
708 | _Eq_char_bound<_Traits>(__delim), |
709 | true, true, true); |
710 | } |
711 | } |
712 | |
713 | if (this->_M_gcount == 0) |
714 | this->setstate(ios_base::failbit); |
715 | |
716 | return *this; |
717 | } |
718 | |
719 | |
720 | |
721 | template <class _CharT, class _Traits> |
722 | basic_istream<_CharT, _Traits>& |
723 | basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) |
724 | { |
725 | sentry __sentry(*this, _No_Skip_WS()); |
726 | this->_M_gcount = 0; |
727 | |
728 | if (__sentry && !this->eof()) { |
729 | basic_streambuf<_CharT, _Traits>*__buf = this->rdbuf(); |
730 | if (__buf->gptr() != __buf->egptr()) |
731 | _M_gcount |
732 | = _M_read_buffered(this, __buf, __n, __s, |
733 | _Constant_unary_fun<bool, int_type>(false), |
734 | _Project2nd<const _CharT*, const _CharT*>(), |
735 | false, false, false); |
736 | else |
737 | _M_gcount |
738 | = _M_read_unbuffered(this, __buf, __n, __s, |
739 | _Constant_unary_fun<bool, int_type>(false), |
740 | false, false, false); |
741 | } |
742 | else |
743 | this->setstate(ios_base::failbit); |
744 | |
745 | if (this->eof()) |
746 | this->setstate(ios_base::eofbit | ios_base::failbit); |
747 | |
748 | return *this; |
749 | } |
750 | |
751 | |
752 | |
753 | |
754 | template <class _CharT, class _Traits> |
755 | streamsize |
756 | basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax) |
757 | { |
758 | sentry __sentry(*this, _No_Skip_WS()); |
759 | this->_M_gcount = 0; |
760 | |
761 | if (__sentry && !this->eof() && __nmax >= 0) { |
762 | |
763 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
764 | streamsize __avail = __buf->in_avail(); |
765 | |
766 | |
767 | if (__avail == -1) |
768 | this->_M_setstate_nothrow(ios_base::eofbit); |
769 | |
770 | else if (__avail != 0) { |
771 | |
772 | if (__buf->gptr() != __buf->egptr()) |
773 | _M_gcount |
774 | = _M_read_buffered(this, __buf, (min) (__avail, __nmax), __s, |
775 | _Constant_unary_fun<bool, int_type>(false), |
776 | _Project2nd<const _CharT*, const _CharT*>(), |
777 | false, false, false); |
778 | else |
779 | _M_gcount |
780 | = _M_read_unbuffered(this, __buf, (min) (__avail, __nmax), __s, |
781 | _Constant_unary_fun<bool, int_type>(false), |
782 | false, false, false); |
783 | } |
784 | } |
785 | else { |
786 | |
787 | if (this->eof()) |
788 | this->setstate(ios_base::eofbit | ios_base::failbit); |
789 | else |
790 | this->setstate(ios_base::failbit); |
791 | } |
792 | |
793 | |
794 | |
795 | |
796 | return _M_gcount; |
797 | } |
798 | |
799 | template <class _CharT, class _Traits> |
800 | void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s) |
801 | { |
802 | sentry __sentry(*this); |
803 | |
804 | if (__sentry) { |
805 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
806 | streamsize __nmax = this->width() > 0 |
807 | ? this->width() - 1 |
808 | : (numeric_limits<streamsize>::max)() / sizeof(_CharT) - 1; |
809 | |
810 | streamsize __n = __buf->gptr() != __buf->egptr() |
811 | ? _M_read_buffered(this, __buf, __nmax, __s, |
812 | _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), |
813 | _Scan_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), |
814 | false, true, false) |
815 | : _M_read_unbuffered(this, __buf, __nmax, __s, |
816 | _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), |
817 | false, true, false); |
818 | if (__n == 0) |
819 | this->setstate(ios_base::failbit); |
820 | } |
821 | this->width(0); |
822 | } |
823 | |
824 | |
825 | |
826 | |
827 | |
828 | |
829 | template < class _CharT, class _Traits, class _Is_Delim> |
830 | void _STLP_CALL |
831 | _M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that, |
832 | basic_streambuf<_CharT, _Traits>* __buf, |
833 | _Is_Delim __is_delim, |
834 | bool __extract_delim, bool __set_failbit) |
835 | { |
836 | bool __done = false; |
837 | ios_base::iostate __status = 0; |
838 | typedef typename basic_istream<_CharT, _Traits>::int_type int_type; |
839 | |
840 | _STLP_TRYtry { |
841 | while (!__done) { |
842 | int_type __c = __buf->sbumpc(); |
843 | |
844 | if (__that->_S_eof(__c)) { |
845 | __done = true; |
846 | __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit |
847 | : ios_base::eofbit; |
848 | } |
849 | |
850 | else if (__is_delim(__c)) { |
851 | __done = true; |
| Value stored to '__done' is never read |
852 | if (!__extract_delim) |
853 | if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c)))) |
854 | __status |= ios_base::failbit; |
855 | } |
856 | } |
857 | } |
858 | _STLP_CATCH_ALLcatch(...) { |
859 | __that->_M_handle_exception(ios_base::badbit); |
860 | } |
861 | |
862 | __that->setstate(__status); |
863 | } |
864 | |
865 | |
866 | |
867 | |
868 | |
869 | |
870 | template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim> |
871 | void _STLP_CALL |
872 | _M_ignore_buffered(basic_istream<_CharT, _Traits>* __that, |
873 | basic_streambuf<_CharT, _Traits>* __buf, |
874 | _Is_Delim __is_delim, _Scan_Delim __scan_delim, |
875 | bool __extract_delim, bool __set_failbit) |
876 | { |
877 | bool __at_eof = false; |
878 | bool __found_delim = false; |
879 | |
880 | _STLP_TRYtry { |
881 | while (__buf->_M_egptr() != __buf->_M_gptr() && !__at_eof && !__found_delim) { |
882 | const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr()); |
883 | __buf->_M_gbump((int)(__p - __buf->_M_gptr())); |
884 | |
885 | if (__p != __buf->_M_egptr()) { |
886 | if (__extract_delim) |
887 | __buf->_M_gbump(1); |
888 | __found_delim = true; |
889 | } |
890 | |
891 | else |
892 | __at_eof = __that->_S_eof(__buf->sgetc()); |
893 | } |
894 | } |
895 | _STLP_CATCH_ALLcatch(...) { |
896 | __that->_M_handle_exception(ios_base::badbit); |
897 | return; |
898 | } |
899 | |
900 | if (__at_eof) { |
901 | __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit |
902 | : ios_base::eofbit); |
903 | return; |
904 | } |
905 | if (__found_delim) |
906 | return; |
907 | |
908 | |
909 | |
910 | |
911 | |
912 | _M_ignore_unbuffered(__that, __buf, __is_delim, __extract_delim, __set_failbit); |
913 | } |
914 | |
915 | |
916 | |
917 | |
918 | |
919 | |
920 | |
921 | |
922 | |
923 | |
924 | |
925 | |
926 | template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim> |
927 | streamsize _STLP_CALL |
928 | _M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that, |
929 | basic_streambuf<_CharT, _Traits>* __buf, |
930 | streamsize _Num, _Max_Chars __max_chars, |
931 | _Is_Delim __is_delim, |
932 | bool __extract_delim, bool __set_failbit) |
933 | { |
934 | streamsize __n = 0; |
935 | ios_base::iostate __status = 0; |
936 | typedef typename basic_istream<_CharT, _Traits>::int_type int_type; |
937 | |
938 | _STLP_TRYtry { |
939 | while (__max_chars(_Num, __n) > 0) { |
940 | int_type __c = __buf->sbumpc(); |
941 | |
942 | if (__that->_S_eof(__c)) { |
943 | __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit |
944 | : ios_base::eofbit; |
945 | break; |
946 | } |
947 | |
948 | else if (__is_delim(__c)) { |
949 | if (__extract_delim) |
950 | ++__n; |
951 | else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c)))) |
952 | __status |= ios_base::failbit; |
953 | |
954 | break; |
955 | } |
956 | |
957 | ++__n; |
958 | } |
959 | } |
960 | _STLP_CATCH_ALLcatch(...) { |
961 | __that->_M_handle_exception(ios_base::badbit); |
962 | } |
963 | |
964 | if (__status) |
965 | __that->setstate(__status); |
966 | return __n; |
967 | } |
968 | |
969 | template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim, class _Scan_Delim> |
970 | streamsize _STLP_CALL |
971 | _M_ignore_buffered(basic_istream<_CharT, _Traits>* __that, |
972 | basic_streambuf<_CharT, _Traits>* __buf, |
973 | streamsize _Num, |
974 | _Max_Chars __max_chars, |
975 | _Is_Delim __is_delim, _Scan_Delim __scan_delim, |
976 | bool __extract_delim, bool __set_failbit) |
977 | { |
978 | streamsize __n = 0; |
979 | bool __at_eof = false; |
980 | bool __done = false; |
981 | |
982 | _STLP_TRYtry { |
983 | while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) { |
984 | ptrdiff_t __avail = __buf->_M_egptr() - __buf->_M_gptr(); |
985 | streamsize __m = __max_chars(_Num, __n); |
986 | |
987 | if (__avail >= __m) { |
988 | const _CharT* __last = __buf->_M_gptr() + __m; |
989 | const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last); |
990 | ptrdiff_t __chunk = __p - __buf->_M_gptr(); |
991 | __n += __chunk; |
992 | __buf->_M_gbump((int)__chunk); |
993 | |
994 | if (__extract_delim && __p != __last) { |
995 | __n += 1; |
996 | __buf->_M_gbump(1); |
997 | } |
998 | |
999 | __done = true; |
1000 | } |
1001 | |
1002 | else { |
1003 | const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr()); |
1004 | ptrdiff_t __chunk = __p - __buf->_M_gptr(); |
1005 | __n += __chunk; |
1006 | __buf->_M_gbump((int)__chunk); |
1007 | |
1008 | if (__p != __buf->_M_egptr()) { |
1009 | if (__extract_delim) { |
1010 | __n += 1; |
1011 | __buf->_M_gbump(1); |
1012 | } |
1013 | |
1014 | __done = true; |
1015 | } |
1016 | |
1017 | |
1018 | else if (__that->_S_eof(__buf->sgetc())) { |
1019 | __done = true; |
1020 | __at_eof = true; |
1021 | } |
1022 | } |
1023 | } |
1024 | } |
1025 | _STLP_CATCH_ALLcatch(...) { |
1026 | __that->_M_handle_exception(ios_base::badbit); |
1027 | return __n; |
1028 | } |
1029 | |
1030 | if (__at_eof) |
1031 | __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit |
1032 | : ios_base::eofbit); |
1033 | |
1034 | if (__done) |
1035 | return __n; |
1036 | |
1037 | |
1038 | |
1039 | |
1040 | |
1041 | |
1042 | return __n + _M_ignore_unbuffered( __that, __buf, _Num, __max_chars, |
1043 | __is_delim, __extract_delim, __set_failbit); |
1044 | } |
1045 | |
1046 | |
1047 | template <class _CharT, class _Traits> |
1048 | basic_istream<_CharT, _Traits>& |
1049 | basic_istream<_CharT, _Traits>::ignore(streamsize __n) |
1050 | { |
1051 | sentry __sentry(*this, _No_Skip_WS()); |
1052 | this->_M_gcount = 0; |
1053 | |
1054 | if (__sentry) { |
1055 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
1056 | typedef _Constant_unary_fun<bool, int_type> _Const_bool; |
1057 | typedef _Constant_binary_fun<streamsize, streamsize, streamsize> |
1058 | _Const_streamsize; |
1059 | const streamsize __maxss = (numeric_limits<streamsize>::max)(); |
1060 | |
1061 | if (__n == (numeric_limits<int>::max)()) { |
1062 | if (__buf->gptr() != __buf->egptr()) |
1063 | _M_gcount |
1064 | = _M_ignore_buffered(this, __buf, |
1065 | __maxss, _Const_streamsize(__maxss), |
1066 | _Const_bool(false), |
1067 | _Project2nd<const _CharT*, const _CharT*>(), |
1068 | false, false); |
1069 | else |
1070 | _M_gcount = _M_ignore_unbuffered(this, __buf, |
1071 | __maxss, _Const_streamsize(__maxss), |
1072 | _Const_bool(false), false, false); |
1073 | } |
1074 | else { |
1075 | if (__buf->gptr() != __buf->egptr()) |
1076 | _M_gcount |
1077 | = _M_ignore_buffered(this, __buf, |
1078 | __n, minus<streamsize>(), |
1079 | _Const_bool(false), |
1080 | _Project2nd<const _CharT*, const _CharT*>(), |
1081 | false, false); |
1082 | else |
1083 | _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(), |
1084 | _Const_bool(false), false, false); |
1085 | } |
1086 | } |
1087 | |
1088 | return *this; |
1089 | } |
1090 | |
1091 | template <class _CharT, class _Traits> |
1092 | basic_istream<_CharT, _Traits>& |
1093 | basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim) |
1094 | { |
1095 | sentry __sentry(*this, _No_Skip_WS()); |
1096 | this->_M_gcount = 0; |
1097 | |
1098 | if (__sentry) { |
1099 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
1100 | typedef _Constant_unary_fun<bool, int_type> _Const_bool; |
1101 | typedef _Constant_binary_fun<streamsize, streamsize, streamsize> |
1102 | _Const_streamsize; |
1103 | const streamsize __maxss = (numeric_limits<streamsize>::max)(); |
1104 | |
1105 | if (__n == (numeric_limits<int>::max)()) { |
1106 | if (__buf->gptr() != __buf->egptr()) |
1107 | _M_gcount = _M_ignore_buffered(this, __buf, |
1108 | __maxss, _Const_streamsize(__maxss), |
1109 | _Eq_int_bound<_Traits>(__delim), |
1110 | _Scan_for_int_val<_Traits>(__delim), |
1111 | true, false); |
1112 | else |
1113 | _M_gcount = _M_ignore_unbuffered(this, __buf, |
1114 | __maxss, _Const_streamsize(__maxss), |
1115 | _Eq_int_bound<_Traits>(__delim), |
1116 | true, false); |
1117 | } |
1118 | else { |
1119 | if (__buf->gptr() != __buf->egptr()) |
1120 | _M_gcount = _M_ignore_buffered(this, __buf, |
1121 | __n, minus<streamsize>(), |
1122 | _Eq_int_bound<_Traits>( |
1123 | __delim), |
1124 | _Scan_for_int_val<_Traits>(__delim), |
1125 | true, false); |
1126 | else |
1127 | _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(), |
1128 | _Eq_int_bound<_Traits>(__delim), |
1129 | true, false); |
1130 | } |
1131 | } |
1132 | |
1133 | return *this; |
1134 | } |
1135 | |
1136 | |
1137 | |
1138 | template <class _CharT, class _Traits> |
1139 | void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit) |
1140 | { |
1141 | basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf(); |
1142 | if (!__buf) |
1143 | this->setstate(ios_base::badbit); |
1144 | else if (__buf->gptr() != __buf->egptr()) |
1145 | _M_ignore_buffered(this, __buf, |
1146 | _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), |
1147 | _Scan_for_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), |
1148 | false, __set_failbit); |
1149 | else |
1150 | _M_ignore_unbuffered(this, __buf, |
1151 | _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()), |
1152 | false, __set_failbit); |
1153 | } |
1154 | |
1155 | |
1156 | |
1157 | |
1158 | |
1159 | |
1160 | |
1161 | |
1162 | |
1163 | template < class _CharT, class _Traits, class _Is_Delim> |
1164 | streamsize _STLP_CALL |
1165 | _M_copy_unbuffered( basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src, |
1166 | basic_streambuf<_CharT, _Traits>* __dest, |
1167 | _Is_Delim __is_delim, |
1168 | bool __extract_delim, bool __rethrow) |
1169 | { |
1170 | streamsize __extracted = 0; |
1171 | ios_base::iostate __status = 0; |
1172 | typedef typename basic_istream<_CharT, _Traits>::int_type int_type; |
1173 | int_type __c; |
1174 | |
1175 | _STLP_TRYtry { |
1176 | |
1177 | while (true) { |
1178 | |
1179 | |
1180 | __c = __src->sbumpc(); |
1181 | |
1182 | |
1183 | if (__that->_S_eof(__c)) { |
1184 | __status |= ios_base::eofbit; |
1185 | break; |
1186 | } |
1187 | |
1188 | else if (__is_delim(__c)) { |
1189 | if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c))) |
1190 | __status |= ios_base::failbit; |
1191 | break; |
1192 | } |
1193 | |
1194 | else { |
1195 | |
1196 | |
1197 | bool __failed = false; |
1198 | _STLP_TRYtry { |
1199 | if (!__that->_S_eof(__dest->sputc(__c))) |
1200 | ++__extracted; |
1201 | else |
1202 | __failed = true; |
1203 | } |
1204 | _STLP_CATCH_ALLcatch(...) { |
1205 | __failed = true; |
1206 | } |
1207 | |
1208 | |
1209 | |
1210 | if (__failed && !__pushback(__src, _Traits::to_char_type(__c))) |
1211 | __status |= ios_base::failbit; |
1212 | |
1213 | |
1214 | if (__failed) |
1215 | break; |
1216 | } |
1217 | |
1218 | } |
1219 | |
1220 | } |
1221 | |
1222 | |
1223 | _STLP_CATCH_ALLcatch(...) { |
1224 | |
1225 | if (__rethrow && __extracted == 0) |
1226 | __that->_M_handle_exception(ios_base::failbit); |
1227 | } |
1228 | __that->setstate(__status); |
1229 | return __extracted; |
1230 | } |
1231 | |
1232 | |
1233 | |
1234 | |
1235 | |
1236 | |
1237 | template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim> |
1238 | streamsize _STLP_CALL |
1239 | _M_copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src, |
1240 | basic_streambuf<_CharT, _Traits>* __dest, |
1241 | _Scan_Delim __scan_delim, _Is_Delim __is_delim, |
1242 | bool __extract_delim, bool __rethrow) |
1243 | { |
1244 | streamsize __extracted = 0; |
1245 | ios_base::iostate __status = 0; |
1246 | typedef typename basic_istream<_CharT, _Traits>::int_type int_type; |
1247 | int_type __c = _Traits::eof(); |
1248 | _CharT* __first = __src->_M_gptr(); |
1249 | ptrdiff_t __avail = __src->_M_egptr() - __first; |
1250 | |
1251 | bool __do_handle_exceptions; |
1252 | |
1253 | _STLP_TRYtry { |
1254 | while (true) { |
1255 | __do_handle_exceptions = false ; |
1256 | const _CharT* __last = __scan_delim(__first, __src->_M_egptr()); |
1257 | |
1258 | |
1259 | streamsize __n = __dest->sputn(__first, __extract_delim && __last != __src->_M_egptr() |
1260 | ? (__last - __first) + 1 |
1261 | : (__last - __first)); |
1262 | __src->_M_gbump((int)__n); |
1263 | __extracted += __n; |
1264 | |
1265 | |
1266 | __do_handle_exceptions = true; |
1267 | |
1268 | if (__n < __avail) |
1269 | break; |
1270 | |
1271 | __c = __src->sgetc(); |
1272 | |
1273 | |
1274 | |
1275 | __first = __src->_M_gptr(); |
1276 | __avail = __src->_M_egptr() - __first; |
1277 | |
1278 | if (__avail > 0) |
1279 | {} |
1280 | else if (__that->_S_eof(__c)) { |
1281 | __status |= ios_base::eofbit; |
1282 | break; |
1283 | } |
1284 | else |
1285 | return __extracted + _M_copy_unbuffered(__that, __src, __dest, __is_delim, |
1286 | __extract_delim, __rethrow); |
1287 | } |
1288 | } |
1289 | |
1290 | _STLP_CATCH_ALLcatch(...) { |
1291 | |
1292 | if (__rethrow && __do_handle_exceptions && __extracted == 0) |
1293 | __that->_M_handle_exception(ios_base::failbit); |
1294 | } |
1295 | |
1296 | if (__status) |
1297 | __that->setstate(__status); |
1298 | return __extracted; |
1299 | } |
1300 | |
1301 | |
1302 | |
1303 | template <class _CharT, class _Traits> |
1304 | basic_istream<_CharT, _Traits>& |
1305 | basic_istream<_CharT, _Traits> |
1306 | ::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim) |
1307 | { |
1308 | sentry __sentry(*this, _No_Skip_WS()); |
1309 | this->_M_gcount = 0; |
1310 | |
1311 | if (__sentry) { |
1312 | basic_streambuf<_CharT, _Traits>* __src = this->rdbuf(); |
1313 | |
1314 | if (__src) |
1315 | this->_M_gcount = __src->egptr() != __src->gptr() |
1316 | ? _M_copy_buffered(this, __src, &__dest, |
1317 | _Scan_for_char_val<_Traits>(__delim), |
1318 | _Eq_char_bound<_Traits>(__delim), |
1319 | false, false) |
1320 | : _M_copy_unbuffered(this, __src, &__dest, |
1321 | _Eq_char_bound<_Traits>(__delim), |
1322 | false, false); |
1323 | } |
1324 | |
1325 | if (this->_M_gcount == 0) |
1326 | this->setstate(ios_base::failbit); |
1327 | |
1328 | return *this; |
1329 | } |
1330 | |
1331 | |
1332 | template <class _CharT, class _Traits> |
1333 | basic_istream<_CharT, _Traits>& |
1334 | basic_istream<_CharT, _Traits> |
1335 | ::operator>>(basic_streambuf<_CharT, _Traits>* __dest) |
1336 | { |
1337 | streamsize __n = 0; |
1338 | typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry; |
1339 | _Sentry __sentry(*this); |
1340 | if (__sentry) { |
1341 | basic_streambuf<_CharT, _Traits>* __src = this->rdbuf(); |
1342 | if (__src && __dest) |
1343 | __n = __src->egptr() != __src->gptr() |
1344 | ? _M_copy_buffered(this, __src, __dest, |
1345 | _Project2nd<const _CharT*, const _CharT*>(), |
1346 | _Constant_unary_fun<bool, int_type>(false), |
1347 | false, true) |
1348 | : _M_copy_unbuffered(this, __src, __dest, |
1349 | _Constant_unary_fun<bool, int_type>(false), |
1350 | false, true); |
1351 | } |
1352 | |
1353 | if (__n == 0) |
1354 | this->setstate(ios_base::failbit); |
1355 | |
1356 | return *this; |
1357 | } |
1358 | |
1359 | |
1360 | |
1361 | |
1362 | |
1363 | template <class _CharT, class _Traits> |
1364 | basic_iostream<_CharT, _Traits> |
1365 | ::basic_iostream(basic_streambuf<_CharT, _Traits>* __buf) |
1366 | : basic_ios<_CharT, _Traits>(), |
1367 | basic_istream<_CharT, _Traits>(__buf), |
1368 | basic_ostream<_CharT, _Traits>(__buf) |
1369 | { |
1370 | this->init(__buf); |
1371 | } |
1372 | |
1373 | template <class _CharT, class _Traits> |
1374 | basic_iostream<_CharT, _Traits>::~basic_iostream() |
1375 | {} |
1376 | |
1377 | _STLP_END_NAMESPACE} |
1378 | |
1379 | # undef __BIS_int_type__ |
1380 | # undef __BIS_pos_type__ |
1381 | # undef __BIS_off_type__ |
1382 | |
1383 | # endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */ |
1384 | |
1385 | #endif /* _STLP_ISTREAM_C */ |