Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
4 * Silicon Graphics Computer Systems, Inc.
9 * This material is provided "as is", with absolutely no warranty expressed
10 * or implied. Any use is at your own risk.
12 * Permission to use or copy this software for any purpose is hereby granted
13 * without fee, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
19 #ifndef _STLP_ISTREAM_C
20 #define _STLP_ISTREAM_C
22 #ifndef _STLP_INTERNAL_ISTREAM_H
23 # include <stl/_istream.h>
26 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
28 #ifndef _STLP_LIMITS_H
29 # include <stl/_limits.h>
32 #ifndef _STLP_INTERNAL_NUM_GET_H
33 # include <stl/_num_get.h>
36 # if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
37 // no wchar_t is supported for this mode
38 # define __BIS_int_type__ int
39 # define __BIS_pos_type__ streampos
40 # define __BIS_off_type__ streamoff
42 # define __BIS_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::int_type
43 # define __BIS_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::pos_type
44 # define __BIS_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_istream<_CharT, _Traits>::off_type
49 //----------------------------------------------------------------------
50 // Function object structs used by some member functions.
52 template <class _Traits>
53 struct _Is_not_wspace {
54 typedef typename _Traits::char_type argument_type;
55 typedef bool result_type;
57 const ctype<argument_type>* _M_ctype;
59 _Is_not_wspace(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
60 bool operator()(argument_type __c) const
61 { return !_M_ctype->is(ctype_base::space, __c); }
64 template <class _Traits>
65 struct _Is_wspace_null {
66 typedef typename _Traits::char_type argument_type;
67 typedef bool result_type;
69 const ctype<argument_type>* _M_ctype;
71 _Is_wspace_null(const ctype<argument_type>* __c_type) : _M_ctype(__c_type) {}
72 bool operator()(argument_type __c) const {
73 return _Traits::eq(__c, argument_type()) ||
74 _M_ctype->is(ctype_base::space, __c);
78 template <class _Traits>
79 struct _Scan_for_wspace {
80 typedef typename _Traits::char_type char_type;
81 typedef char_type* first_argument_type;
82 typedef char_type* second_argument_type;
83 typedef char_type* result_type;
85 const ctype<char_type>* _M_ctype;
87 _Scan_for_wspace(const ctype<char_type>* __ctype) : _M_ctype(__ctype) {}
89 operator()(const char_type* __first, const char_type* __last) const {
90 return _M_ctype->scan_is(ctype_base::space, __first, __last);
94 template <class _Traits>
95 struct _Scan_wspace_null {
96 typedef typename _Traits::char_type char_type;
97 typedef char_type* first_argument_type;
98 typedef char_type* second_argument_type;
99 typedef char_type* result_type;
101 const ctype<char_type>* _M_ctype;
103 _Scan_wspace_null(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
105 operator()(const char_type* __first, const char_type* __last) const {
106 __last = find_if(__first, __last,
107 _Eq_char_bound<_Traits>(char_type()));
108 return _M_ctype->scan_is(ctype_base::space, __first, __last);
112 template <class _Traits>
113 struct _Scan_for_not_wspace {
114 typedef typename _Traits::char_type char_type;
115 typedef char_type* first_argument_type;
116 typedef char_type* second_argument_type;
117 typedef char_type* result_type;
119 const ctype<char_type>* _M_ctype;
121 _Scan_for_not_wspace(const ctype<char_type>* __c_type) : _M_ctype(__c_type) {}
123 operator()(const char_type* __first, const char_type* __last) const {
124 return _M_ctype->scan_not(ctype_base::space, __first, __last);
128 template <class _Traits>
129 struct _Scan_for_char_val
131 typedef typename _Traits::char_type char_type;
132 typedef char_type* first_argument_type;
133 typedef char_type* second_argument_type;
134 typedef char_type* result_type;
138 _Scan_for_char_val(char_type __val) : _M_val(__val) {}
141 operator()(const char_type* __first, const char_type* __last) const {
142 return find_if(__first, __last, _Eq_char_bound<_Traits>(_M_val));
146 template <class _Traits>
147 struct _Scan_for_int_val
149 typedef typename _Traits::char_type char_type;
150 typedef typename _Traits::int_type int_type;
151 typedef char_type* first_argument_type;
152 typedef char_type* second_argument_type;
153 typedef char_type* result_type;
157 _Scan_for_int_val(int_type __val) : _M_val(__val) {}
160 operator()(const char_type* __first, const char_type* __last) const {
161 return find_if(__first, __last,
162 _Eq_int_bound<_Traits>(_M_val));
166 // Helper function: try to push back a character to a streambuf,
167 // return true if the pushback succeeded. Does not throw.
169 template <class _CharT, class _Traits>
171 __pushback(basic_streambuf<_CharT, _Traits>* __buf, _CharT __c)
175 const typename _Traits::int_type __eof = _Traits::eof();
176 ret = !_Traits::eq_int_type(__buf->sputbackc(__c), __eof);
184 template <class _CharT, class _Traits>
185 basic_istream<_CharT, _Traits>& _STLP_CALL
186 ws(basic_istream<_CharT, _Traits>& __is)
188 typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
189 _Sentry __sentry(__is, _No_Skip_WS()); // Don't skip whitespace.
191 __is._M_skip_whitespace(false);
195 // Helper functions for istream<>::sentry constructor.
196 template <class _CharT, class _Traits>
198 _M_init_skip(basic_istream<_CharT, _Traits>& __is) {
203 __is._M_skip_whitespace(true);
207 __is.setstate(ios_base::failbit);
213 template <class _CharT, class _Traits>
215 _M_init_noskip(basic_istream<_CharT, _Traits>& __is){
221 __is.setstate(ios_base::badbit);
224 __is.setstate(ios_base::failbit);
228 //----------------------------------------------------------------------
229 // Definitions of basic_istream<>'s noninline member functions.
231 // Helper function for formatted input of numbers.
232 template <class _CharT, class _Traits, class _Number>
233 ios_base::iostate _STLP_CALL
234 _M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val)
236 typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
237 ios_base::iostate __err = 0;
238 _Sentry __sentry( __that ); // Skip whitespace.
240 typedef num_get<_CharT, istreambuf_iterator<_CharT, _Traits> > _Num_get;
242 ((const _Num_get&)use_facet<_Num_get>(__that.getloc())).get(istreambuf_iterator<_CharT, _Traits>(__that.rdbuf()),
243 0, __that, __err, __val);
246 __that._M_handle_exception(ios_base::badbit);
248 if (__err) __that.setstate(__err);
256 template <class _CharT, class _Traits>
258 basic_istream<_CharT, _Traits>::peek()
260 typename _Traits::int_type __tmp = _Traits::eof();
263 sentry __sentry(*this, _No_Skip_WS());
267 __tmp = this->rdbuf()->sgetc();
270 this->_M_handle_exception(ios_base::badbit);
275 if (this->_S_eof(__tmp))
278 this->setstate(ios_base::eofbit);
285 template <class _CharT, class _Traits>
287 basic_istream<_CharT, _Traits>::get()
289 typename _Traits::int_type __tmp = _Traits::eof();
290 sentry __sentry(*this, _No_Skip_WS());
295 __tmp = this->rdbuf()->sbumpc();
298 this->_M_handle_exception(ios_base::badbit);
301 if (!this->_S_eof(__tmp))
306 this->setstate(ios_base::eofbit | ios_base::failbit);
311 template <class _CharT, class _Traits>
312 basic_istream<_CharT, _Traits>&
313 basic_istream<_CharT, _Traits>::get(_CharT& __c)
315 sentry __sentry(*this, _No_Skip_WS());
319 typename _Traits::int_type __tmp = _Traits::eof();
321 __tmp = this->rdbuf()->sbumpc();
324 this->_M_handle_exception(ios_base::badbit);
327 if (!this->_S_eof(__tmp)) {
329 __c = _Traits::to_char_type(__tmp);
333 if (this->_M_gcount == 0)
334 this->setstate(ios_base::eofbit | ios_base::failbit);
341 // Read characters and discard them. The standard specifies a single
342 // function with two arguments, each with a default. We instead use
343 // three overloded functions, because it's possible to implement the
344 // first two more efficiently than the fully general third version.
345 template <class _CharT, class _Traits>
346 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore()
348 sentry __sentry(*this, _No_Skip_WS());
354 __c = this->rdbuf()->sbumpc();
357 this->_M_handle_exception(ios_base::badbit);
361 if (!this->_S_eof(__c))
364 this->setstate(ios_base::eofbit);
372 template <class _CharT, class _Traits>
373 basic_istream<_CharT, _Traits>&
374 basic_istream<_CharT, _Traits>::putback(_CharT __c) {
376 sentry __sentry(*this, _No_Skip_WS());
379 typename _Traits::int_type __tmp = _Traits::eof();
380 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
381 // if (!__buf || this->_S_eof(__buf->sputbackc(__c)))
384 __tmp = __buf->sputbackc(__c);
387 this->_M_handle_exception(ios_base::badbit);
390 if (this->_S_eof(__tmp))
391 this->setstate(ios_base::badbit);
394 this->setstate(ios_base::failbit);
399 template <class _CharT, class _Traits>
400 basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() {
403 sentry __sentry(*this, _No_Skip_WS());
406 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
407 // if (!__buf || _Traits::eq_int_type(__buf->sungetc(), _Traits::eof()))
411 __tmp = __buf->sungetc();
413 if (__tmp == (_CharT)-1) //chek for eof
415 if (this->_S_eof(__tmp))
417 this->setstate(ios_base::badbit);
420 this->_M_handle_exception(ios_base::badbit);
423 this->setstate(ios_base::badbit);
426 this->setstate(ios_base::failbit);
431 // Positioning and buffer control.
433 template <class _CharT, class _Traits>
434 int basic_istream<_CharT, _Traits>::sync() {
435 sentry __sentry(*this, _No_Skip_WS());
437 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
439 if (__buf->pubsync() == -1) {
440 this->setstate(ios_base::badbit);
450 template <class _CharT, class _Traits>
452 basic_istream<_CharT, _Traits>::tellg() {
453 #ifndef __SYMBIAN32__
454 sentry __sentry(*this, _No_Skip_WS());
456 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
457 return (__buf && !this->fail()) ? __buf->pubseekoff(0, ios_base::cur, ios_base::in)
461 template <class _CharT, class _Traits>
462 basic_istream<_CharT, _Traits>&
463 basic_istream<_CharT, _Traits>::seekg(pos_type __pos) {
464 #ifndef __SYMBIAN32__
465 sentry __sentry(*this, _No_Skip_WS());
467 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
468 if (!this->fail() && __buf)
470 pos_type pos = __buf->pubseekpos(__pos, ios_base::in);
471 if(pos == pos_type(off_type(-1)))
472 this->setstate(ios_base::failbit);
477 template <class _CharT, class _Traits>
478 basic_istream<_CharT, _Traits>&
479 basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
481 #ifndef __SYMBIAN32__
482 sentry __sentry(*this, _No_Skip_WS());
484 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
485 if (!this->fail() && __buf)
488 pos_type pos = __buf->pubseekoff(__off, __dir, ios_base::in);
489 if(pos == pos_type(off_type(-1)))
490 this->setstate(ios_base::failbit);
495 // Formatted input of characters and character arrays.
497 template <class _CharT, class _Traits>
498 void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT& __c)
500 // typename _Traits::int_type __tmp = _Traits::eof();
502 sentry __sentry(*this); // Skip whitespace.
505 typename _Traits::int_type __tmp = _Traits::eof();
508 __tmp = this->rdbuf()->sbumpc();
511 this->_M_handle_exception(ios_base::badbit);
515 if (!this->_S_eof(__tmp))
516 __c = _Traits::to_char_type(__tmp);
518 this->setstate(ios_base::eofbit | ios_base::failbit);
523 //---------------------------------------------------------------------------
524 // istream's helper functions.
526 // A generic function for unbuffered input. We stop when we reach EOF,
527 // or when we have extracted _Num characters, or when the function object
528 // __is_delim return true. In the last case, it extracts the character
529 // for which __is_delim is true, if and only if __extract_delim is true.
530 // It appends a null character to the end of the string; this means that
531 // it may store up to _Num + 1 characters.
533 // __is_getline governs two corner cases: reading _Num characters without
534 // encountering delim or eof (in which case failbit is set if __is_getline
535 // is true); and reading _Num characters where the _Num+1'st character is
536 // eof (in which case eofbit is set if __is_getline is true).
538 // It is assumed that __is_delim never throws.
540 // Return value is the number of characters extracted, including the
541 // delimiter if it is extracted. Note that the number of characaters
542 // extracted isn't necessarily the same as the number stored.
544 template < class _CharT, class _Traits, class _Is_Delim>
545 streamsize _STLP_CALL
546 _M_read_unbuffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
547 streamsize _Num, _CharT* __s,
548 _Is_Delim __is_delim,
549 bool __extract_delim, bool __append_null,
553 ios_base::iostate __status = 0;
555 typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
556 // The operations that can potentially throw are sbumpc, snextc, and sgetc.
559 int_type __c = __buf->sgetc();
561 if (__that->_S_eof(__c)) {
562 if (__n < _Num || __is_getline)
563 __status |= ios_base::eofbit;
567 else if (__is_delim(__c)) {
568 if (__extract_delim) { // Extract and discard current character.
575 else if (__n == _Num) {
577 __status |= ios_base::failbit;
581 *__s++ = _Traits::to_char_type(__c);
583 __c = __buf->snextc();
586 // int_type __c = __buf->sbumpc(); // __buf->sgetc();
589 int_type __c = __buf->sbumpc(); // sschwarz
591 if (__that->_S_eof(__c)) {
592 if (__n < _Num || __is_getline)
593 __status |= ios_base::eofbit;
597 else if (__is_delim(__c)) {
598 if (__extract_delim) { // Extract and discard current character.
605 else { // regular character
607 *__s++ = _Traits::to_char_type(__c);
613 if (__is_getline) // didn't find delimiter as one of the _Num chars
614 __status |= ios_base::failbit;
618 // *__s++ = _Traits::to_char_type(__c);
627 __that->_M_handle_exception(ios_base::badbit);
628 *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
633 *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
635 __that->setstate(__status); // This might throw.
639 // Much like _M_read_unbuffered, but with one additional function object:
640 // __scan_delim(first, last) returns the first pointer p in [first, last)
641 // such that __is_delim(p) is true.
643 template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
644 streamsize _STLP_CALL
645 _M_read_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __buf,
646 streamsize _Num, _CharT* __s,
647 _Is_Delim __is_delim, _Scan_Delim __scan_delim,
648 bool __extract_delim, bool __append_null,
652 ios_base::iostate __status = 0;
656 while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
657 const _CharT* __first = __buf->_M_gptr();
658 const _CharT* __last = __buf->_M_egptr();
659 ptrdiff_t __request = _Num - __n;
661 const _CharT* __p = __scan_delim(__first, __last);
662 ptrdiff_t __chunk = (min) (ptrdiff_t(__p - __first), __request);
663 _Traits::copy(__s, __first, __chunk);
666 __buf->_M_gbump((int)__chunk);
668 // We terminated by finding delim.
669 if (__p != __last && __p - __first <= __request) {
670 if (__extract_delim) {
677 // We terminated by reading all the characters we were asked for.
678 else if(__n == _Num) {
680 // Find out if we have reached eof. This matters for getline.
682 if (__chunk == __last - __first) {
683 if (__that->_S_eof(__buf->sgetc()))
684 __status |= ios_base::eofbit;
687 __status |= ios_base::failbit;
692 // The buffer contained fewer than _Num - __n characters. Either we're
693 // at eof, or we should refill the buffer and try again.
695 if (__that->_S_eof(__buf->sgetc())) {
696 __status |= ios_base::eofbit;
700 } // Close the while loop.
703 __that->_M_handle_exception(ios_base::badbit);
709 *__s = _STLP_DEFAULT_CONSTRUCTED(_CharT);
711 __that->setstate(__status); // This might throw.
715 // If execution has reached this point, then we have an empty buffer but
716 // we have not reached eof. What that means is that the streambuf has
717 // decided to switch from buffered to unbuffered input. We switch to
718 // to _M_read_unbuffered.
720 return __n + _M_read_unbuffered(__that, __buf, _Num - __n, __s, __is_delim,
721 __extract_delim,__append_null,__is_getline);
727 template <class _CharT, class _Traits>
728 basic_istream<_CharT, _Traits>&
729 basic_istream<_CharT, _Traits>::get(_CharT* __s, streamsize __n,
731 sentry __sentry(*this, _No_Skip_WS());
736 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
738 if (__buf->egptr() != __buf->gptr())
740 _M_read_buffered(this, __buf, __n - 1, __s,
741 _Eq_char_bound<_Traits>(__delim),
742 _Scan_for_char_val<_Traits>(__delim),
746 _M_read_unbuffered(this, __buf, __n - 1, __s,
747 _Eq_char_bound<_Traits>(__delim),
752 *(__s + this->_M_gcount) = _STLP_DEFAULT_CONSTRUCTED(_CharT);
753 #endif //__SYMBIAN32__
754 if (this->_M_gcount == 0)
755 this->setstate(ios_base::failbit);
760 // Getline is essentially identical to get, except that it extracts
762 template <class _CharT, class _Traits>
763 basic_istream<_CharT, _Traits>&
764 basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n,
766 sentry __sentry(*this, _No_Skip_WS());
771 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
772 this->_M_gcount = __buf->egptr() != __buf->gptr()
773 ? _M_read_buffered(this, __buf, __n - 1, __s,
774 _Eq_char_bound<_Traits>(__delim),
775 _Scan_for_char_val<_Traits>(__delim),
777 : _M_read_unbuffered(this, __buf, __n - 1, __s,
778 _Eq_char_bound<_Traits>(__delim),
783 if (this->_M_gcount == 0)
784 this->setstate(ios_base::failbit);
789 // Read n characters. We don't look for any delimiter, and we don't
790 // put in a terminating null character.
791 template <class _CharT, class _Traits>
792 basic_istream<_CharT, _Traits>&
793 basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
795 sentry __sentry(*this, _No_Skip_WS());
798 if (__sentry && !this->eof()) {
799 basic_streambuf<_CharT, _Traits>*__buf = this->rdbuf();
800 if (__buf->gptr() != __buf->egptr())
802 = _M_read_buffered(this, __buf, __n, __s,
803 _Constant_unary_fun<bool, int_type>(false),
804 _Project2nd<const _CharT*, const _CharT*>(),
805 false, false, false);
808 = _M_read_unbuffered(this, __buf, __n, __s,
809 _Constant_unary_fun<bool, int_type>(false),
810 false, false, false);
813 this->setstate(ios_base::failbit);
816 this->setstate(ios_base::eofbit | ios_base::failbit);
822 // Read n or fewer characters. We don't look for any delimiter, and
823 // we don't put in a terminating null character.
824 template <class _CharT, class _Traits>
826 basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __nmax)
828 sentry __sentry(*this, _No_Skip_WS());
831 if (__sentry && !this->eof() && __nmax >= 0) {
833 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
834 streamsize __avail = __buf->in_avail();
836 // fbp : isn't full-blown setstate required here ?
838 this->_M_setstate_nothrow(ios_base::eofbit);
840 else if (__avail != 0) {
842 if (__buf->gptr() != __buf->egptr())
844 = _M_read_buffered(this, __buf, (min) (__avail, __nmax), __s,
845 _Constant_unary_fun<bool, int_type>(false),
846 _Project2nd<const _CharT*, const _CharT*>(),
847 false, false, false);
850 = _M_read_unbuffered(this, __buf, (min) (__avail, __nmax), __s,
851 _Constant_unary_fun<bool, int_type>(false),
852 false, false, false);
856 // fbp : changed so that failbit is set only there, to pass Dietmar's test
858 this->setstate(ios_base::eofbit | ios_base::failbit);
863 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
864 streamsize __avail = __buf->in_avail();
866 this->setstate(ios_base::eofbit);
869 this->setstate(ios_base::failbit);
874 // this->setstate(ios_base::eofbit | ios_base::failbit);
879 template <class _CharT, class _Traits>
880 void basic_istream<_CharT, _Traits>::_M_formatted_get(_CharT* __s)
882 sentry __sentry(*this); // Skip whitespace.
885 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
886 streamsize __nmax = this->width() > 0
888 : (numeric_limits<streamsize>::max)() / sizeof(_CharT) - 1;
890 streamsize __n = __buf->gptr() != __buf->egptr()
891 ? _M_read_buffered(this, __buf, __nmax, __s,
892 _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
893 _Scan_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
895 : _M_read_unbuffered(this, __buf, __nmax, __s,
896 _Is_wspace_null<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
899 this->setstate(ios_base::failbit);
904 // A generic unbuffered function for ignoring characters. We stop
905 // when we reach EOF, or when the function object __is_delim returns
906 // true. In the last case, it extracts the character for which
907 // __is_delim is true, if and only if __extract_delim is true.
909 template < class _CharT, class _Traits, class _Is_Delim>
911 _M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
912 basic_streambuf<_CharT, _Traits>* __buf,
913 _Is_Delim __is_delim,
914 bool __extract_delim, bool __set_failbit)
917 ios_base::iostate __status = 0;
918 typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
922 int_type __c = __buf->sgetc();
925 if (__that->_S_eof(__c)) {
927 __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
932 else if (__is_delim(__c)) {
939 __c = __buf->snextc();
943 int_type __c = __buf->sbumpc();
945 if (__that->_S_eof(__c)) {
947 __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
951 else if (__is_delim(__c)) {
953 if (!__extract_delim)
954 if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
955 __status |= ios_base::failbit;
961 __that->_M_handle_exception(ios_base::badbit);
964 __that->setstate(__status);
967 // A generic buffered function for ignoring characters. Much like
968 // _M_ignore_unbuffered, but with one additional function object:
969 // __scan_delim(first, last) returns the first pointer p in [first,
970 // last) such that __is_delim(p) is true.
972 template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
974 _M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
975 basic_streambuf<_CharT, _Traits>* __buf,
976 _Is_Delim __is_delim, _Scan_Delim __scan_delim,
977 bool __extract_delim, bool __set_failbit)
979 bool __at_eof = false;
980 bool __found_delim = false;
983 while (__buf->_M_egptr() != __buf->_M_gptr() && !__at_eof && !__found_delim) {
984 const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
985 __buf->_M_gbump((int)(__p - __buf->_M_gptr()));
987 if (__p != __buf->_M_egptr()) { // We found delim, so we're done.
990 __found_delim = true;
993 else // No delim. Try to refil the buffer.
994 __at_eof = __that->_S_eof(__buf->sgetc());
995 } // Close the while loop.
998 __that->_M_handle_exception(ios_base::badbit);
1003 __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
1004 : ios_base::eofbit);
1010 // If execution has reached this point, then we have an empty buffer but
1011 // we have not reached eof. What that means is that the streambuf has
1012 // decided to switch from a buffered to an unbuffered mode. We switch
1013 // to _M_ignore_unbuffered.
1014 _M_ignore_unbuffered(__that, __buf, __is_delim, __extract_delim, __set_failbit);
1017 // Overloaded versions of _M_ignore_unbuffered and _M_ignore_unbuffered
1018 // with an explicit count _Num. Return value is the number of
1019 // characters extracted.
1021 // The function object __max_chars takes two arguments, _Num and __n
1022 // (the latter being the number of characters we have already read),
1023 // and returns the maximum number of characters to read from the buffer.
1024 // We parameterize _M_ignore_buffered so that we can use it for both
1025 // bounded and unbounded input; for the former the function object should
1026 // be minus<>, and for the latter it should return a constant maximum value.
1028 template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim>
1029 streamsize _STLP_CALL
1030 _M_ignore_unbuffered(basic_istream<_CharT, _Traits>* __that,
1031 basic_streambuf<_CharT, _Traits>* __buf,
1032 streamsize _Num, _Max_Chars __max_chars,
1033 _Is_Delim __is_delim,
1034 bool __extract_delim, bool __set_failbit)
1037 ios_base::iostate __status = 0;
1038 typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1041 while (__max_chars(_Num, __n) > 0) {
1042 int_type __c = __buf->sbumpc();
1044 if (__that->_S_eof(__c)) {
1045 __status |= __set_failbit ? ios_base::eofbit | ios_base::failbit
1050 else if (__is_delim(__c)) {
1051 if (__extract_delim)
1053 else if (__that->_S_eof(__buf->sputbackc(_Traits::to_char_type(__c))))
1054 __status |= ios_base::failbit;
1058 // fbp : added counter increment to pass Dietmar's test
1063 __that->_M_handle_exception(ios_base::badbit);
1067 __that->setstate(__status); // This might throw.
1071 template < class _CharT, class _Traits, class _Max_Chars, class _Is_Delim, class _Scan_Delim>
1072 streamsize _STLP_CALL
1073 _M_ignore_buffered(basic_istream<_CharT, _Traits>* __that,
1074 basic_streambuf<_CharT, _Traits>* __buf,
1076 _Max_Chars __max_chars,
1077 _Is_Delim __is_delim, _Scan_Delim __scan_delim,
1078 bool __extract_delim, bool __set_failbit)
1081 bool __at_eof = false;
1082 bool __done = false;
1085 while (__buf->_M_egptr() != __buf->_M_gptr() && !__done) {
1086 ptrdiff_t __avail = __buf->_M_egptr() - __buf->_M_gptr();
1087 streamsize __m = __max_chars(_Num, __n);
1089 if (__avail >= __m) { // We have more characters than we need.
1090 const _CharT* __last = __buf->_M_gptr() + __m;
1091 const _CharT* __p = __scan_delim(__buf->_M_gptr(), __last);
1092 ptrdiff_t __chunk = __p - __buf->_M_gptr();
1094 __buf->_M_gbump((int)__chunk);
1096 if (__extract_delim && __p != __last) {
1105 const _CharT* __p = __scan_delim(__buf->_M_gptr(), __buf->_M_egptr());
1106 ptrdiff_t __chunk = __p - __buf->_M_gptr();
1108 __buf->_M_gbump((int)__chunk);
1110 if (__p != __buf->_M_egptr()) { // We found delim.
1111 if (__extract_delim) {
1119 // We didn't find delim. Try to refill the buffer.
1120 else if (__that->_S_eof(__buf->sgetc())) {
1125 } // Close the while loop.
1128 __that->_M_handle_exception(ios_base::badbit);
1133 __that->setstate(__set_failbit ? ios_base::eofbit | ios_base::failbit
1134 : ios_base::eofbit);
1139 // If execution has reached this point, then we have an empty buffer but
1140 // we have not reached eof. What that means is that the streambuf has
1141 // decided to switch from buffered to unbuffered input. We switch to
1142 // to _M_ignore_unbuffered.
1144 return __n + _M_ignore_unbuffered( __that, __buf, _Num, __max_chars,
1145 __is_delim, __extract_delim, __set_failbit);
1149 template <class _CharT, class _Traits>
1150 basic_istream<_CharT, _Traits>&
1151 basic_istream<_CharT, _Traits>::ignore(streamsize __n)
1153 sentry __sentry(*this, _No_Skip_WS());
1154 this->_M_gcount = 0;
1157 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1158 typedef _Constant_unary_fun<bool, int_type> _Const_bool;
1159 typedef _Constant_binary_fun<streamsize, streamsize, streamsize>
1161 const streamsize __maxss = (numeric_limits<streamsize>::max)();
1163 if (__n == (numeric_limits<int>::max)()) {
1164 if (__buf->gptr() != __buf->egptr())
1166 = _M_ignore_buffered(this, __buf,
1167 __maxss, _Const_streamsize(__maxss),
1169 _Project2nd<const _CharT*, const _CharT*>(),
1172 _M_gcount = _M_ignore_unbuffered(this, __buf,
1173 __maxss, _Const_streamsize(__maxss),
1174 _Const_bool(false), false, false);
1177 if (__buf->gptr() != __buf->egptr())
1179 = _M_ignore_buffered(this, __buf,
1180 __n, minus<streamsize>(),
1182 _Project2nd<const _CharT*, const _CharT*>(),
1185 _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(),
1186 _Const_bool(false), false, false);
1193 template <class _CharT, class _Traits>
1194 basic_istream<_CharT, _Traits>&
1195 basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __delim)
1197 sentry __sentry(*this, _No_Skip_WS());
1198 this->_M_gcount = 0;
1201 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1202 typedef _Constant_unary_fun<bool, int_type> _Const_bool;
1203 typedef _Constant_binary_fun<streamsize, streamsize, streamsize>
1205 const streamsize __maxss = (numeric_limits<streamsize>::max)();
1207 if (__n == (numeric_limits<int>::max)()) {
1208 if (__buf->gptr() != __buf->egptr())
1209 _M_gcount = _M_ignore_buffered(this, __buf,
1210 __maxss, _Const_streamsize(__maxss),
1211 _Eq_int_bound<_Traits>(__delim),
1212 _Scan_for_int_val<_Traits>(__delim),
1215 _M_gcount = _M_ignore_unbuffered(this, __buf,
1216 __maxss, _Const_streamsize(__maxss),
1217 _Eq_int_bound<_Traits>(__delim),
1221 if (__buf->gptr() != __buf->egptr())
1222 _M_gcount = _M_ignore_buffered(this, __buf,
1223 __n, minus<streamsize>(),
1224 _Eq_int_bound<_Traits>(
1226 _Scan_for_int_val<_Traits>(__delim),
1229 _M_gcount = _M_ignore_unbuffered(this, __buf, __n, minus<streamsize>(),
1230 _Eq_int_bound<_Traits>(__delim),
1238 // This member function does not construct a sentry object, because
1239 // it is called from sentry's constructor.
1240 template <class _CharT, class _Traits>
1241 void basic_istream<_CharT, _Traits>::_M_skip_whitespace(bool __set_failbit)
1243 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
1245 this->setstate(ios_base::badbit);
1246 else if (__buf->gptr() != __buf->egptr())
1247 _M_ignore_buffered(this, __buf,
1248 _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1249 _Scan_for_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1250 false, __set_failbit);
1252 _M_ignore_unbuffered(this, __buf,
1253 _Is_not_wspace<_Traits>((const ctype<_CharT>*)this->_M_ctype_facet()),
1254 false, __set_failbit);
1258 // This is a very simple loop that reads characters from __src and puts
1259 // them into __dest. It looks complicated because of the (standard-
1260 // mandated) exception handling policy.
1262 // We stop when we get an exception, when we fail to insert into the
1263 // output streambuf, or when __is_delim is true.
1265 template < class _CharT, class _Traits, class _Is_Delim>
1266 streamsize _STLP_CALL
1267 _M_copy_unbuffered( basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
1268 basic_streambuf<_CharT, _Traits>* __dest,
1269 _Is_Delim __is_delim,
1270 bool __extract_delim, bool __rethrow)
1272 streamsize __extracted = 0;
1273 ios_base::iostate __status = 0;
1274 typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1278 #ifdef __SYMBIAN32__
1279 __c = __src->sgetc();
1280 for(;; __c = __src->snextc()){
1282 // If we failed to get a character, then quit.
1283 if (__that->_S_eof(__c)) {
1284 __status |= ios_base::eofbit;
1287 // If it's the delimiter, then quit.
1288 else if (__is_delim(__c)) {
1289 if (!__extract_delim)
1290 __status |= ios_base::failbit;
1296 // Try to put the character in the output streambuf.
1298 if (!__that->_S_eof(__dest->sputc(__c)))
1304 __status |= ios_base::failbit;
1310 } /* while (true) */
1314 // Get a character. If there's an exception, catch and (maybe) rethrow it.
1315 __c = __src->sbumpc();
1317 // If we failed to get a character, then quit.
1318 if (__that->_S_eof(__c)) {
1319 __status |= ios_base::eofbit;
1322 // If it's the delimiter, then quit.
1323 else if (__is_delim(__c)) {
1324 if (!__extract_delim && !__pushback(__src, _Traits::to_char_type(__c)))
1325 __status |= ios_base::failbit;
1331 // Try to put the character in the output streambuf.
1332 bool __failed = false;
1334 if (!__that->_S_eof(__dest->sputc(__c)))
1343 // If we failed to put the character in the output streambuf, then
1344 // try to push it back to the input streambuf.
1345 if (__failed && !__pushback(__src, _Traits::to_char_type(__c)))
1346 __status |= ios_base::failbit;
1348 // fbp : avoiding infinite loop in io-27-6-1-2-3.exp
1353 } /* while (true) */
1356 // fbp : this try/catch moved here in reasonable assumption
1357 // __is_delim never throw (__pushback is guaranteed not to)
1359 // See 27.6.1.2.3, paragraph 13.
1360 if (__rethrow && __extracted == 0)
1361 __that->_M_handle_exception(ios_base::failbit);
1363 __that->setstate(__status);
1367 // Buffered copying from one streambuf to another. We copy the characters
1368 // in chunks, rather than one at a time. We still have to worry about all
1369 // of the error conditions we checked in _M_copy_unbuffered, plus one more:
1370 // the streambuf might decide to switch from a buffered to an unbuffered mode.
1372 template < class _CharT, class _Traits, class _Is_Delim, class _Scan_Delim>
1373 streamsize _STLP_CALL
1374 _M_copy_buffered(basic_istream<_CharT, _Traits>* __that, basic_streambuf<_CharT, _Traits>* __src,
1375 basic_streambuf<_CharT, _Traits>* __dest,
1376 _Scan_Delim __scan_delim, _Is_Delim __is_delim,
1377 bool __extract_delim, bool __rethrow)
1379 streamsize __extracted = 0;
1380 ios_base::iostate __status = 0;
1381 typedef typename basic_istream<_CharT, _Traits>::int_type int_type;
1382 int_type __c = _Traits::eof();
1383 _CharT* __first = __src->_M_gptr();
1384 ptrdiff_t __avail = __src->_M_egptr() - __first;
1385 // fbp : introduced to move catch/try blocks out of the loop
1386 bool __do_handle_exceptions;
1390 __do_handle_exceptions = false ;
1391 const _CharT* __last = __scan_delim(__first, __src->_M_egptr());
1393 // Try to copy the entire input buffer to the output buffer.
1394 streamsize __n = __dest->sputn(__first, __extract_delim && __last != __src->_M_egptr()
1395 ? (__last - __first) + 1
1396 : (__last - __first));
1397 __src->_M_gbump((int)__n);
1400 // from this on, catch() will call _M_handle_exceptions()
1401 __do_handle_exceptions = true;
1403 if (__n < __avail) // We found the delimiter, or else failed to
1404 break; // copy some characters.
1406 __c = __src->sgetc();
1408 // Three possibilities: we succeeded in refilling the buffer, or
1409 // we got EOF, or the streambuf has switched to unbuffered mode.
1410 __first = __src->_M_gptr();
1411 __avail = __src->_M_egptr() - __first;
1414 {} // dwa 1/16/00 -- suppress a Metrowerks warning
1415 else if (__that->_S_eof(__c)) {
1416 __status |= ios_base::eofbit;
1420 return __extracted + _M_copy_unbuffered(__that, __src, __dest, __is_delim,
1421 __extract_delim, __rethrow);
1426 // See 27.6.1.2.3, paragraph 13.
1427 if (__rethrow && __do_handle_exceptions && __extracted == 0)
1428 __that->_M_handle_exception(ios_base::failbit);
1432 __that->setstate(__status); // This might throw.
1438 template <class _CharT, class _Traits>
1439 basic_istream<_CharT, _Traits>&
1440 basic_istream<_CharT, _Traits>
1441 ::get(basic_streambuf<_CharT, _Traits>& __dest, _CharT __delim)
1443 sentry __sentry(*this, _No_Skip_WS());
1444 this->_M_gcount = 0;
1447 basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
1450 this->_M_gcount = __src->egptr() != __src->gptr()
1451 ? _M_copy_buffered(this, __src, &__dest,
1452 _Scan_for_char_val<_Traits>(__delim),
1453 _Eq_char_bound<_Traits>(__delim),
1455 : _M_copy_unbuffered(this, __src, &__dest,
1456 _Eq_char_bound<_Traits>(__delim),
1460 if (this->_M_gcount == 0)
1461 this->setstate(ios_base::failbit);
1466 // Copying characters into a streambuf.
1467 template <class _CharT, class _Traits>
1468 basic_istream<_CharT, _Traits>&
1469 basic_istream<_CharT, _Traits>
1470 ::operator>>(basic_streambuf<_CharT, _Traits>* __dest)
1473 typedef typename basic_istream<_CharT, _Traits>::sentry _Sentry;
1474 _Sentry __sentry(*this);
1476 basic_streambuf<_CharT, _Traits>* __src = this->rdbuf();
1477 if (__src && __dest)
1478 __n = __src->egptr() != __src->gptr()
1479 ? _M_copy_buffered(this, __src, __dest,
1480 _Project2nd<const _CharT*, const _CharT*>(),
1481 _Constant_unary_fun<bool, int_type>(false),
1483 : _M_copy_unbuffered(this, __src, __dest,
1484 _Constant_unary_fun<bool, int_type>(false),
1489 this->setstate(ios_base::failbit);
1494 // ----------------------------------------------------------------
1495 // basic_iostream<> class
1496 // ----------------------------------------------------------------
1498 template <class _CharT, class _Traits>
1499 _STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits>
1500 ::basic_iostream(basic_streambuf<_CharT, _Traits>* __buf)
1501 : basic_ios<_CharT, _Traits>(),
1502 basic_istream<_CharT, _Traits>(__buf),
1503 basic_ostream<_CharT, _Traits>(__buf)
1508 template <class _CharT, class _Traits>
1509 _STLP_EXP_DECLSPEC basic_iostream<_CharT, _Traits>::~basic_iostream()
1513 template <class _CharT, class _Traits>
1514 _STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits>
1515 ::basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
1516 basic_ios<_CharT, _Traits>(), _M_gcount(0) {
1520 template <class _CharT, class _Traits>
1521 _STLP_EXP_DECLSPEC basic_istream<_CharT, _Traits>
1522 ::~basic_istream() {}
1528 # undef __BIS_int_type__
1529 # undef __BIS_pos_type__
1530 # undef __BIS_off_type__
1532 # endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
1534 #endif /* _STLP_ISTREAM_C */