34template <
class _CharT,
class _Traits,
class _NativeType>
35_STD::basic_istream<_CharT, _Traits>&
36__rw_extract (_STD::basic_istream<_CharT, _Traits> &__strm,
41 typedef _STD::istreambuf_iterator<_CharT, _Traits> _Iter;
42 typedef _STD::num_get<_CharT, _Iter> _NumGet;
44 _STD::ios_base::iostate __err = _STD::ios_base::goodbit;
47 const typename _STD::basic_istream<_CharT, _Traits>::sentry
53 .get (_Iter (__strm), _Iter (), __strm, __err, __val);
56 __strm.setstate (__strm.badbit | _RW::__rw_rethrow);
60 if (_STD::ios_base::goodbit != __err)
61 __strm.setstate (__err);
73template<
class _CharT,
class _Traits>
74basic_istream<_CharT, _Traits>&
75basic_istream<_CharT, _Traits>::
76_C_ipfx (
bool __noskipws, ios_base::iostate __errbits)
82 if (ios_base::goodbit != this->rdstate ()) {
83 this->setstate (ios_base::failbit);
87 ios_base::iostate __state = ios_base::goodbit;
91 this->
tie ()->flush ();
93 if ( ios_base::eofbit == __errbits
94 || !__noskipws && this->
flags () & ios_base::skipws) {
98 basic_streambuf<char_type, traits_type>*
const __rdbuf =
103 const ctype<char_type> &__ctp =
104 _USE_FACET (ctype<char_type>, this->getloc ());
108 const char_type*
const __gptr = __rdbuf->gptr ();
109 const char_type*
const __egptr = __rdbuf->egptr ();
111 if (__gptr < __egptr) {
114 const streamsize __nskip =
115 __ctp.scan_not (__ctp.space, __gptr, __egptr)
118 __rdbuf->gbump (__nskip);
120 if (__nskip < __egptr - __gptr)
125 const int_type __c (__rdbuf->sgetc ());
127 if (traits_type::eq_int_type (__c, traits_type::eof ())) {
132 if (!__ctp.is (__ctp.space,
133 traits_type::to_char_type (__c)))
142 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
146 this->setstate (__state);
152template<
class _CharT,
class _Traits>
153typename basic_istream<_CharT, _Traits>::int_type
154basic_istream<_CharT, _Traits>::
155_C_unsafe_get (streamsize *__cnt ,
161 ios_base::iostate __err = ios_base::goodbit;
164 int_type __c (traits_type::eof ());
169 __c = this->rdbuf ()->sgetc ();
173 if (traits_type::eq_int_type (__c, traits_type::eof ()))
174 __err = ios_base::eofbit
176 else if ( ( _C_eatdelim & __flags
177 || !traits_type::eq_int_type (__c, __delim))
178 && ( _C_eatnull & __flags
179 || !traits_type::eq (traits_type::to_char_type (__c),
181 && ( !(_C_wsterm & __flags)
182 || !
_USE_FACET (ctype<char_type>, this->getloc ())
183 .is (ctype_base::space,
184 traits_type::to_char_type (__c)))) {
185 if (traits_type::eq_int_type (this->rdbuf ()->sbumpc (),
186 traits_type::eof ()))
187 __err = ios_base::failbit;
193 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
197 this->setstate (__err);
203template<
class _CharT,
class _Traits>
204basic_istream<_CharT, _Traits>&
205basic_istream<_CharT, _Traits>::
206_C_get (basic_streambuf<char_type, traits_type> &__sb, int_type __delim)
210 ios_base::iostate __err = ios_base::goodbit;
212 const sentry __ipfx (*
this,
true );
220 int_type __c (this->rdbuf ()->sgetc ());
222 if (traits_type::eq_int_type (__c, traits_type::eof ())) {
223 __err = ios_base::eofbit;
227 if (traits_type::eq_int_type (__c, __delim))
231 __c = __sb.sputc (traits_type::to_char_type (__c));
240 __err = ios_base::failbit | _RW::__rw_rethrow;
244 this->setstate (__err);
248 if (traits_type::eq_int_type (__c, traits_type::eof ())) {
249 __err = ios_base::failbit;
254 this->rdbuf ()->sbumpc ();
261 if (ios_base::goodbit == __err)
262 __err = ios_base::badbit;
264 this->setstate (__err | _RW::__rw_rethrow);
270 __err |= ios_base::failbit;
273 this->setstate (__err);
279template<
class _CharT,
class _Traits>
280basic_istream<_CharT, _Traits>&
281basic_istream<_CharT, _Traits>::
282read (char_type *__s, streamsize __n, int_type __delim,
int __flags)
289 const char_type __eos = char_type ();
291 const bool __getline = (_C_failend | _C_nullterm)
292 == ((_C_failend | _C_nullterm) & __flags);
297 traits_type::assign (*__s, __eos);
300 const sentry __ipfx (*
this, !(_C_skipws & __flags));
311 if (0 == --__n && _C_nullterm & __flags) {
315 const int_type __c (this->rdbuf ()->sgetc ());
317 if ( !traits_type::eq_int_type (__c, traits_type::eof ())
318 && !traits_type::eq_int_type (__c, __delim))
321 __flags &= ~_C_failend;
327 const int_type __c (_C_unsafe_get (&_C_gcount, __delim, __flags));
330 if ( traits_type::eq_int_type (__c, traits_type::eof())
331 || traits_type::eq_int_type (__c, __delim))
334 const char_type __ch = traits_type::to_char_type (__c);
337 if ( !(_C_eatnull & __flags) && traits_type::eq (__ch, __eos)
338 || _C_wsterm & __flags
339 &&
_USE_FACET (ctype<char_type>, this->getloc ())
340 .is (ctype_base::space, __ch))
345 traits_type::assign (*__s++, __ch);
348 if (_C_nullterm & __flags && __s)
349 traits_type::assign (*__s, __eos);
353 if ( _C_failnoi & __flags && !gcount ()
354 || _C_failend & __flags && !__n)
355 this->setstate (ios_base::failbit);
362template<
class _CharT,
class _Traits>
363basic_istream<_CharT, _Traits>&
364basic_istream<_CharT, _Traits>::
365read (char_type *__s, streamsize __n)
371 const sentry __ipfx (*
this,
true );
378 streamsize __nread = 0;
381 __nread = this->rdbuf ()->sgetn (__s, __n);
387 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
391 this->setstate (ios_base::eofbit | ios_base::failbit);
398template<
class _CharT,
class _Traits>
400basic_istream<_CharT, _Traits>::
401readsome (char_type *__s, streamsize __n)
407 const sentry __ipfx (*
this,
true );
413 streamsize __nread = 0;
417 const streamsize __in_avail = this->rdbuf ()->in_avail ();
422 if (__n > __in_avail)
426 __nread = __n >= 0 ? this->rdbuf ()->sgetn (__s, __n) : -1;
432 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
436 this->setstate (ios_base::eofbit);
443 this->setstate (ios_base::failbit);
449template<
class _CharT,
class _Traits>
450typename basic_istream<_CharT, _Traits>::pos_type
451basic_istream<_CharT, _Traits>::
456 const sentry __ipfx (*
this,
true );
458 if (__ipfx && !this->
fail ()) {
461 return this->rdbuf ()->pubseekoff (0, ios_base::cur, ios_base::in);
464 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
468 return off_type (-1);
472template<
class _CharT,
class _Traits>
473basic_istream<_CharT, _Traits>&
474basic_istream<_CharT, _Traits>::
475putback (char_type __c)
477 const sentry __ipfx (*
this,
true );
481 if (this->rdbuf ()) {
483 if (!traits_type::eq_int_type (this->rdbuf ()->sputbackc (__c),
484 traits_type::eof ()))
488 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
492 this->setstate (ios_base::badbit);
499template<
class _CharT,
class _Traits>
500basic_istream<_CharT, _Traits>&
501basic_istream<_CharT, _Traits>::
504 const sentry __ipfx (*
this,
true );
508 if (this->rdbuf ()) {
512 if (!traits_type::eq_int_type (this->rdbuf ()->sungetc (),
513 traits_type::eof ()))
517 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
521 this->setstate (ios_base::badbit);
528template<
class _CharT,
class _Traits>
530basic_istream<_CharT, _Traits>::
533 const sentry __ipfx (*
this,
true );
535 if (__ipfx && this->rdbuf ()) {
538 if (-1 != this->rdbuf ()->pubsync ())
542 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
545 this->setstate (ios_base::badbit);
552template<
class _CharT,
class _Traits>
553basic_istream<_CharT, _Traits>&
554basic_istream<_CharT, _Traits>::
555get (char_type *__s, streamsize __n, char_type __delim)
562 traits_type::assign (__s [0], char_type ());
565 const sentry __ipfx (*
this,
true );
567 ios_base::iostate __err = ios_base::goodbit;
575 basic_streambuf<char_type, traits_type>*
const __rdbuf =
580 streamsize __navail =
581 streamsize (__rdbuf->egptr () - __rdbuf->gptr ());
583 if (__n - 1 < __navail)
588 char_type*
const __gptr = __rdbuf->gptr ();
590 const char_type*
const __pdelim =
591 traits_type::find (__gptr, __navail, __delim);
594 __navail = streamsize (__pdelim - __gptr);
600 traits_type::copy (__s + _C_gcount, __gptr, __navail);
602 __rdbuf->gbump (__navail);
604 _C_gcount += __navail;
609 const int_type __c (__rdbuf->sgetc ());
611 if (traits_type::eq_int_type (__c, traits_type::eof ())) {
612 __err = ios_base::eofbit;
616 const char_type __ch = traits_type::to_char_type (__c);
618 if (traits_type::eq (__ch, __delim))
621 traits_type::assign (__s [_C_gcount++], __ch);
628 traits_type::assign (__s [_C_gcount], char_type ());
631 __err |= ios_base::failbit;
634 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
638 if (ios_base::goodbit != __err)
639 this->setstate (__err);
645template<
class _CharT,
class _Traits>
646basic_istream<_CharT, _Traits>&
647basic_istream<_CharT, _Traits>::
648getline (char_type *__line, streamsize __size, char_type __delim)
659 traits_type::assign (__line [0], char_type ());
669 const sentry __ipfx (*
this,
true );
671 ios_base::iostate __err = ios_base::goodbit;
677 basic_streambuf<char_type, traits_type>*
const __rdbuf =
684 const char_type*
const __gptr = __rdbuf->gptr ();
685 const char_type*
const __egptr = __rdbuf->egptr ();
689 streamsize __navail = __egptr - __gptr;
690 if (__size < __navail)
696 const char_type*
const __pdel =
697 traits_type::find (__gptr, __navail, __delim);
700 __navail = __pdel - __gptr + 1;
701 __size -= __navail - 1;
703 else if (__size == __navail)
704 __size -= --__navail;
710 traits_type::copy (__line + _C_gcount, __gptr, __navail);
712 _C_gcount += __navail;
715 __rdbuf->gbump (__navail);
718 traits_type::assign (__line [_C_gcount - 1],
723 if (2 > __size && __egptr - __gptr != __navail) {
724 traits_type::assign (__line [_C_gcount], char_type ());
725 __err = ios_base::failbit;
733 const int_type __c (__rdbuf->sgetc ());
735 if (traits_type::eq_int_type (__c, traits_type::eof ())) {
736 traits_type::assign (__line [_C_gcount], char_type ());
737 __err = ios_base::eofbit;
741 const char_type __ch = traits_type::to_char_type (__c);
742 if (traits_type::eq (__ch, __delim)) {
743 traits_type::assign (__line [_C_gcount], char_type ());
750 traits_type::assign (__line [_C_gcount], char_type ());
751 __err = ios_base::failbit;
755 traits_type::assign (__line [_C_gcount], __ch);
769 this->setstate (ios_base::badbit | _RW::__rw_rethrow);
774 __err |= ios_base::failbit;
777 this->setstate (__err);
783#ifdef _RWSTD_NO_UNDEFINED_TEMPLATES
785template <
class _CharT,
class _Traits>
786basic_istream<_CharT, _Traits>::sentry::
787sentry (
const sentry&)
788 : _RW::__rw_guard (0)
793template <
class _CharT,
class _Traits>
795basic_istream<_CharT, _Traits>::sentry::
796operator= (
const sentry&)
void tie(std::ostringstream *ps, std::size_t n)
#define _RWSTD_NAMESPACE(name)
#define _STD_USE_FACET(type, arg)
#define _USE_FACET(type, arg)
#define _RWSTD_ASSERT(ignore)