35 #define _ISTREAM_TCC 1
37 #pragma GCC system_header
41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 template<
typename _CharT,
typename _Traits>
46 basic_istream<_CharT, _Traits>::sentry::
47 sentry(basic_istream<_CharT, _Traits>& __in,
bool __noskip) : _M_ok(false)
56 const __int_type __eof = traits_type::eof();
57 __streambuf_type* __sb = __in.rdbuf();
58 __int_type __c = __sb->sgetc();
60 const __ctype_type& __ct = __check_facet(__in._M_ctype);
61 while (!traits_type::eq_int_type(__c, __eof)
62 && __ct.is(ctype_base::space,
63 traits_type::to_char_type(__c)))
69 if (traits_type::eq_int_type(__c, __eof))
83 template<
typename _CharT,
typename _Traits>
84 template<
typename _ValueT>
85 basic_istream<_CharT, _Traits>&
86 basic_istream<_CharT, _Traits>::
87 _M_extract(_ValueT& __v)
89 sentry __cerb(*
this,
false);
92 ios_base::iostate __err = ios_base::goodbit;
95 const __num_get_type& __ng = __check_facet(this->_M_num_get);
96 __ng.get(*
this, 0, *
this, __err, __v);
100 this->_M_setstate(ios_base::badbit);
101 __throw_exception_again;
104 { this->_M_setstate(ios_base::badbit); }
106 this->setstate(__err);
111 template<
typename _CharT,
typename _Traits>
112 basic_istream<_CharT, _Traits>&
113 basic_istream<_CharT, _Traits>::
114 operator>>(
short& __n)
118 sentry __cerb(*
this,
false);
121 ios_base::iostate __err = ios_base::goodbit;
125 const __num_get_type& __ng = __check_facet(this->_M_num_get);
126 __ng.get(*
this, 0, *
this, __err, __l);
130 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
132 __err |= ios_base::failbit;
133 __n = __gnu_cxx::__numeric_traits<short>::__min;
135 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
137 __err |= ios_base::failbit;
138 __n = __gnu_cxx::__numeric_traits<short>::__max;
145 this->_M_setstate(ios_base::badbit);
146 __throw_exception_again;
149 { this->_M_setstate(ios_base::badbit); }
151 this->setstate(__err);
156 template<
typename _CharT,
typename _Traits>
157 basic_istream<_CharT, _Traits>&
158 basic_istream<_CharT, _Traits>::
163 sentry __cerb(*
this,
false);
166 ios_base::iostate __err = ios_base::goodbit;
170 const __num_get_type& __ng = __check_facet(this->_M_num_get);
171 __ng.get(*
this, 0, *
this, __err, __l);
175 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
177 __err |= ios_base::failbit;
178 __n = __gnu_cxx::__numeric_traits<int>::__min;
180 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
182 __err |= ios_base::failbit;
183 __n = __gnu_cxx::__numeric_traits<int>::__max;
190 this->_M_setstate(ios_base::badbit);
191 __throw_exception_again;
194 { this->_M_setstate(ios_base::badbit); }
196 this->setstate(__err);
201 template<
typename _CharT,
typename _Traits>
202 basic_istream<_CharT, _Traits>&
203 basic_istream<_CharT, _Traits>::
204 operator>>(__streambuf_type* __sbout)
206 ios_base::iostate __err = ios_base::goodbit;
207 sentry __cerb(*
this,
false);
208 if (__cerb && __sbout)
213 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
214 __err |= ios_base::failbit;
216 __err |= ios_base::eofbit;
220 this->_M_setstate(ios_base::failbit);
221 __throw_exception_again;
224 { this->_M_setstate(ios_base::failbit); }
227 __err |= ios_base::failbit;
229 this->setstate(__err);
233 template<
typename _CharT,
typename _Traits>
234 typename basic_istream<_CharT, _Traits>::int_type
235 basic_istream<_CharT, _Traits>::
238 const int_type __eof = traits_type::eof();
239 int_type __c = __eof;
241 ios_base::iostate __err = ios_base::goodbit;
242 sentry __cerb(*
this,
true);
247 __c = this->rdbuf()->sbumpc();
249 if (!traits_type::eq_int_type(__c, __eof))
252 __err |= ios_base::eofbit;
256 this->_M_setstate(ios_base::badbit);
257 __throw_exception_again;
260 { this->_M_setstate(ios_base::badbit); }
263 __err |= ios_base::failbit;
265 this->setstate(__err);
269 template<
typename _CharT,
typename _Traits>
270 basic_istream<_CharT, _Traits>&
271 basic_istream<_CharT, _Traits>::
275 ios_base::iostate __err = ios_base::goodbit;
276 sentry __cerb(*
this,
true);
281 const int_type __cb = this->rdbuf()->sbumpc();
283 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
286 __c = traits_type::to_char_type(__cb);
289 __err |= ios_base::eofbit;
293 this->_M_setstate(ios_base::badbit);
294 __throw_exception_again;
297 { this->_M_setstate(ios_base::badbit); }
300 __err |= ios_base::failbit;
302 this->setstate(__err);
306 template<
typename _CharT,
typename _Traits>
307 basic_istream<_CharT, _Traits>&
308 basic_istream<_CharT, _Traits>::
309 get(char_type* __s,
streamsize __n, char_type __delim)
312 ios_base::iostate __err = ios_base::goodbit;
313 sentry __cerb(*
this,
true);
318 const int_type __idelim = traits_type::to_int_type(__delim);
319 const int_type __eof = traits_type::eof();
320 __streambuf_type* __sb = this->rdbuf();
321 int_type __c = __sb->sgetc();
323 while (_M_gcount + 1 < __n
324 && !traits_type::eq_int_type(__c, __eof)
325 && !traits_type::eq_int_type(__c, __idelim))
327 *__s++ = traits_type::to_char_type(__c);
329 __c = __sb->snextc();
331 if (traits_type::eq_int_type(__c, __eof))
332 __err |= ios_base::eofbit;
336 this->_M_setstate(ios_base::badbit);
337 __throw_exception_again;
340 { this->_M_setstate(ios_base::badbit); }
347 __err |= ios_base::failbit;
349 this->setstate(__err);
353 template<
typename _CharT,
typename _Traits>
354 basic_istream<_CharT, _Traits>&
355 basic_istream<_CharT, _Traits>::
356 get(__streambuf_type& __sb, char_type __delim)
359 ios_base::iostate __err = ios_base::goodbit;
360 sentry __cerb(*
this,
true);
365 const int_type __idelim = traits_type::to_int_type(__delim);
366 const int_type __eof = traits_type::eof();
367 __streambuf_type* __this_sb = this->rdbuf();
368 int_type __c = __this_sb->sgetc();
369 char_type __c2 = traits_type::to_char_type(__c);
371 while (!traits_type::eq_int_type(__c, __eof)
372 && !traits_type::eq_int_type(__c, __idelim)
373 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
376 __c = __this_sb->snextc();
377 __c2 = traits_type::to_char_type(__c);
379 if (traits_type::eq_int_type(__c, __eof))
380 __err |= ios_base::eofbit;
384 this->_M_setstate(ios_base::badbit);
385 __throw_exception_again;
388 { this->_M_setstate(ios_base::badbit); }
391 __err |= ios_base::failbit;
393 this->setstate(__err);
397 template<
typename _CharT,
typename _Traits>
398 basic_istream<_CharT, _Traits>&
403 ios_base::iostate __err = ios_base::goodbit;
404 sentry __cerb(*
this,
true);
409 const int_type __idelim = traits_type::to_int_type(__delim);
410 const int_type __eof = traits_type::eof();
411 __streambuf_type* __sb = this->rdbuf();
412 int_type __c = __sb->sgetc();
414 while (_M_gcount + 1 < __n
415 && !traits_type::eq_int_type(__c, __eof)
416 && !traits_type::eq_int_type(__c, __idelim))
418 *__s++ = traits_type::to_char_type(__c);
419 __c = __sb->snextc();
422 if (traits_type::eq_int_type(__c, __eof))
423 __err |= ios_base::eofbit;
426 if (traits_type::eq_int_type(__c, __idelim))
432 __err |= ios_base::failbit;
437 this->_M_setstate(ios_base::badbit);
438 __throw_exception_again;
441 { this->_M_setstate(ios_base::badbit); }
448 __err |= ios_base::failbit;
450 this->setstate(__err);
457 template<
typename _CharT,
typename _Traits>
458 basic_istream<_CharT, _Traits>&
459 basic_istream<_CharT, _Traits>::
463 sentry __cerb(*
this,
true);
466 ios_base::iostate __err = ios_base::goodbit;
469 const int_type __eof = traits_type::eof();
470 __streambuf_type* __sb = this->rdbuf();
472 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
473 __err |= ios_base::eofbit;
479 this->_M_setstate(ios_base::badbit);
480 __throw_exception_again;
483 { this->_M_setstate(ios_base::badbit); }
485 this->setstate(__err);
490 template<
typename _CharT,
typename _Traits>
491 basic_istream<_CharT, _Traits>&
492 basic_istream<_CharT, _Traits>::
496 sentry __cerb(*
this,
true);
497 if (__cerb && __n > 0)
499 ios_base::iostate __err = ios_base::goodbit;
502 const int_type __eof = traits_type::eof();
503 __streambuf_type* __sb = this->rdbuf();
504 int_type __c = __sb->sgetc();
513 bool __large_ignore =
false;
516 while (_M_gcount < __n
517 && !traits_type::eq_int_type(__c, __eof))
520 __c = __sb->snextc();
522 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
523 && !traits_type::eq_int_type(__c, __eof))
526 __gnu_cxx::__numeric_traits<streamsize>::__min;
527 __large_ignore =
true;
534 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
536 if (traits_type::eq_int_type(__c, __eof))
537 __err |= ios_base::eofbit;
541 this->_M_setstate(ios_base::badbit);
542 __throw_exception_again;
545 { this->_M_setstate(ios_base::badbit); }
547 this->setstate(__err);
552 template<
typename _CharT,
typename _Traits>
553 basic_istream<_CharT, _Traits>&
554 basic_istream<_CharT, _Traits>::
558 sentry __cerb(*
this,
true);
559 if (__cerb && __n > 0)
561 ios_base::iostate __err = ios_base::goodbit;
564 const int_type __eof = traits_type::eof();
565 __streambuf_type* __sb = this->rdbuf();
566 int_type __c = __sb->sgetc();
569 bool __large_ignore =
false;
572 while (_M_gcount < __n
573 && !traits_type::eq_int_type(__c, __eof)
574 && !traits_type::eq_int_type(__c, __delim))
577 __c = __sb->snextc();
579 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
580 && !traits_type::eq_int_type(__c, __eof)
581 && !traits_type::eq_int_type(__c, __delim))
584 __gnu_cxx::__numeric_traits<streamsize>::__min;
585 __large_ignore =
true;
592 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
594 if (traits_type::eq_int_type(__c, __eof))
595 __err |= ios_base::eofbit;
596 else if (traits_type::eq_int_type(__c, __delim))
599 < __gnu_cxx::__numeric_traits<streamsize>::__max)
606 this->_M_setstate(ios_base::badbit);
607 __throw_exception_again;
610 { this->_M_setstate(ios_base::badbit); }
612 this->setstate(__err);
617 template<
typename _CharT,
typename _Traits>
618 typename basic_istream<_CharT, _Traits>::int_type
619 basic_istream<_CharT, _Traits>::
622 int_type __c = traits_type::eof();
624 sentry __cerb(*
this,
true);
627 ios_base::iostate __err = ios_base::goodbit;
630 __c = this->rdbuf()->sgetc();
631 if (traits_type::eq_int_type(__c, traits_type::eof()))
632 __err |= ios_base::eofbit;
636 this->_M_setstate(ios_base::badbit);
637 __throw_exception_again;
640 { this->_M_setstate(ios_base::badbit); }
642 this->setstate(__err);
647 template<
typename _CharT,
typename _Traits>
648 basic_istream<_CharT, _Traits>&
649 basic_istream<_CharT, _Traits>::
653 sentry __cerb(*
this,
true);
656 ios_base::iostate __err = ios_base::goodbit;
659 _M_gcount = this->rdbuf()->sgetn(__s, __n);
660 if (_M_gcount != __n)
661 __err |= (ios_base::eofbit | ios_base::failbit);
665 this->_M_setstate(ios_base::badbit);
666 __throw_exception_again;
669 { this->_M_setstate(ios_base::badbit); }
671 this->setstate(__err);
676 template<
typename _CharT,
typename _Traits>
678 basic_istream<_CharT, _Traits>::
682 sentry __cerb(*
this,
true);
685 ios_base::iostate __err = ios_base::goodbit;
689 const streamsize __num = this->rdbuf()->in_avail();
691 _M_gcount = this->rdbuf()->sgetn(__s,
std::min(__num, __n));
692 else if (__num == -1)
693 __err |= ios_base::eofbit;
697 this->_M_setstate(ios_base::badbit);
698 __throw_exception_again;
701 { this->_M_setstate(ios_base::badbit); }
703 this->setstate(__err);
708 template<
typename _CharT,
typename _Traits>
709 basic_istream<_CharT, _Traits>&
710 basic_istream<_CharT, _Traits>::
711 putback(char_type __c)
717 this->clear(this->rdstate() & ~ios_base::eofbit);
718 sentry __cerb(*
this,
true);
721 ios_base::iostate __err = ios_base::goodbit;
724 const int_type __eof = traits_type::eof();
725 __streambuf_type* __sb = this->rdbuf();
727 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
728 __err |= ios_base::badbit;
732 this->_M_setstate(ios_base::badbit);
733 __throw_exception_again;
736 { this->_M_setstate(ios_base::badbit); }
738 this->setstate(__err);
743 template<
typename _CharT,
typename _Traits>
744 basic_istream<_CharT, _Traits>&
745 basic_istream<_CharT, _Traits>::
752 this->clear(this->rdstate() & ~ios_base::eofbit);
753 sentry __cerb(*
this,
true);
756 ios_base::iostate __err = ios_base::goodbit;
759 const int_type __eof = traits_type::eof();
760 __streambuf_type* __sb = this->rdbuf();
762 || traits_type::eq_int_type(__sb->sungetc(), __eof))
763 __err |= ios_base::badbit;
767 this->_M_setstate(ios_base::badbit);
768 __throw_exception_again;
771 { this->_M_setstate(ios_base::badbit); }
773 this->setstate(__err);
778 template<
typename _CharT,
typename _Traits>
780 basic_istream<_CharT, _Traits>::
786 sentry __cerb(*
this,
true);
789 ios_base::iostate __err = ios_base::goodbit;
792 __streambuf_type* __sb = this->rdbuf();
795 if (__sb->pubsync() == -1)
796 __err |= ios_base::badbit;
803 this->_M_setstate(ios_base::badbit);
804 __throw_exception_again;
807 { this->_M_setstate(ios_base::badbit); }
809 this->setstate(__err);
814 template<
typename _CharT,
typename _Traits>
815 typename basic_istream<_CharT, _Traits>::pos_type
816 basic_istream<_CharT, _Traits>::
821 pos_type __ret = pos_type(-1);
822 sentry __cerb(*
this,
true);
828 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
833 this->_M_setstate(ios_base::badbit);
834 __throw_exception_again;
837 { this->_M_setstate(ios_base::badbit); }
842 template<
typename _CharT,
typename _Traits>
843 basic_istream<_CharT, _Traits>&
844 basic_istream<_CharT, _Traits>::
845 seekg(pos_type __pos)
850 this->clear(this->rdstate() & ~ios_base::eofbit);
851 sentry __cerb(*
this,
true);
854 ios_base::iostate __err = ios_base::goodbit;
860 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
864 if (__p == pos_type(off_type(-1)))
865 __err |= ios_base::failbit;
870 this->_M_setstate(ios_base::badbit);
871 __throw_exception_again;
874 { this->_M_setstate(ios_base::badbit); }
876 this->setstate(__err);
881 template<
typename _CharT,
typename _Traits>
882 basic_istream<_CharT, _Traits>&
883 basic_istream<_CharT, _Traits>::
884 seekg(off_type __off, ios_base::seekdir __dir)
889 this->clear(this->rdstate() & ~ios_base::eofbit);
890 sentry __cerb(*
this,
true);
893 ios_base::iostate __err = ios_base::goodbit;
899 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
903 if (__p == pos_type(off_type(-1)))
904 __err |= ios_base::failbit;
909 this->_M_setstate(ios_base::badbit);
910 __throw_exception_again;
913 { this->_M_setstate(ios_base::badbit); }
915 this->setstate(__err);
921 template<
typename _CharT,
typename _Traits>
922 basic_istream<_CharT, _Traits>&
923 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
925 typedef basic_istream<_CharT, _Traits> __istream_type;
926 typedef typename __istream_type::int_type __int_type;
928 typename __istream_type::sentry __cerb(__in,
false);
931 ios_base::iostate __err = ios_base::goodbit;
934 const __int_type __cb = __in.rdbuf()->sbumpc();
935 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
936 __c = _Traits::to_char_type(__cb);
938 __err |= (ios_base::eofbit | ios_base::failbit);
942 __in._M_setstate(ios_base::badbit);
943 __throw_exception_again;
946 { __in._M_setstate(ios_base::badbit); }
948 __in.setstate(__err);
953 template<
typename _CharT,
typename _Traits>
954 basic_istream<_CharT, _Traits>&
955 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
957 typedef basic_istream<_CharT, _Traits> __istream_type;
958 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
959 typedef typename _Traits::int_type int_type;
960 typedef _CharT char_type;
961 typedef ctype<_CharT> __ctype_type;
964 ios_base::iostate __err = ios_base::goodbit;
965 typename __istream_type::sentry __cerb(__in,
false);
973 __num = __gnu_cxx::__numeric_traits<streamsize>::__max;
975 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
977 const int_type __eof = _Traits::eof();
978 __streambuf_type* __sb = __in.rdbuf();
979 int_type __c = __sb->sgetc();
981 while (__extracted < __num - 1
982 && !_Traits::eq_int_type(__c, __eof)
983 && !__ct.is(ctype_base::space,
984 _Traits::to_char_type(__c)))
986 *__s++ = _Traits::to_char_type(__c);
988 __c = __sb->snextc();
990 if (_Traits::eq_int_type(__c, __eof))
991 __err |= ios_base::eofbit;
1000 __in._M_setstate(ios_base::badbit);
1001 __throw_exception_again;
1004 { __in._M_setstate(ios_base::badbit); }
1007 __err |= ios_base::failbit;
1009 __in.setstate(__err);
1014 template<
typename _CharT,
typename _Traits>
1015 basic_istream<_CharT, _Traits>&
1016 ws(basic_istream<_CharT, _Traits>& __in)
1018 typedef basic_istream<_CharT, _Traits> __istream_type;
1019 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1020 typedef typename __istream_type::int_type __int_type;
1021 typedef ctype<_CharT> __ctype_type;
1023 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1024 const __int_type __eof = _Traits::eof();
1025 __streambuf_type* __sb = __in.rdbuf();
1026 __int_type __c = __sb->sgetc();
1028 while (!_Traits::eq_int_type(__c, __eof)
1029 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1030 __c = __sb->snextc();
1032 if (_Traits::eq_int_type(__c, __eof))
1033 __in.setstate(ios_base::eofbit);
1039 #if _GLIBCXX_EXTERN_TEMPLATE
1040 extern template class basic_istream<char>;
1041 extern template istream& ws(istream&);
1042 extern template istream&
operator>>(istream&,
char&);
1043 extern template istream&
operator>>(istream&,
char*);
1044 extern template istream&
operator>>(istream&,
unsigned char&);
1045 extern template istream&
operator>>(istream&,
signed char&);
1046 extern template istream&
operator>>(istream&,
unsigned char*);
1047 extern template istream&
operator>>(istream&,
signed char*);
1049 extern template istream& istream::_M_extract(
unsigned short&);
1050 extern template istream& istream::_M_extract(
unsigned int&);
1051 extern template istream& istream::_M_extract(
long&);
1052 extern template istream& istream::_M_extract(
unsigned long&);
1053 extern template istream& istream::_M_extract(
bool&);
1054 #ifdef _GLIBCXX_USE_LONG_LONG
1055 extern template istream& istream::_M_extract(
long long&);
1056 extern template istream& istream::_M_extract(
unsigned long long&);
1058 extern template istream& istream::_M_extract(
float&);
1059 extern template istream& istream::_M_extract(
double&);
1060 extern template istream& istream::_M_extract(
long double&);
1061 extern template istream& istream::_M_extract(
void*&);
1063 extern template class basic_iostream<char>;
1065 #ifdef _GLIBCXX_USE_WCHAR_T
1066 extern template class basic_istream<wchar_t>;
1067 extern template wistream& ws(wistream&);
1068 extern template wistream&
operator>>(wistream&,
wchar_t&);
1069 extern template wistream&
operator>>(wistream&,
wchar_t*);
1071 extern template wistream& wistream::_M_extract(
unsigned short&);
1072 extern template wistream& wistream::_M_extract(
unsigned int&);
1073 extern template wistream& wistream::_M_extract(
long&);
1074 extern template wistream& wistream::_M_extract(
unsigned long&);
1075 extern template wistream& wistream::_M_extract(
bool&);
1076 #ifdef _GLIBCXX_USE_LONG_LONG
1077 extern template wistream& wistream::_M_extract(
long long&);
1078 extern template wistream& wistream::_M_extract(
unsigned long long&);
1080 extern template wistream& wistream::_M_extract(
float&);
1081 extern template wistream& wistream::_M_extract(
double&);
1082 extern template wistream& wistream::_M_extract(
long double&);
1083 extern template wistream& wistream::_M_extract(
void*&);
1085 extern template class basic_iostream<wchar_t>;
1089 _GLIBCXX_END_NAMESPACE_VERSION
static const iostate eofbit
Indicates that an input operation reached the end of an input sequence.
basic_istream< _CharT, _Traits > & operator>>(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str)
Read stream into a string.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
basic_istream< _CharT, _Traits > & getline(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str, _CharT __delim)
Read a line from stream into a string.
ISO C++ entities toplevel namespace is std.
static const iostate goodbit
Indicates all is well.
_Ios_Iostate iostate
This is a bitmask type.
static const fmtflags skipws
Skips leading white space before certain input operations.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...