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)
57 const __int_type __eof = traits_type::eof();
58 __streambuf_type* __sb = __in.rdbuf();
59 __int_type __c = __sb->sgetc();
61 const __ctype_type& __ct = __check_facet(__in._M_ctype);
62 while (!traits_type::eq_int_type(__c, __eof)
63 && __ct.is(ctype_base::space,
64 traits_type::to_char_type(__c)))
70 if (traits_type::eq_int_type(__c, __eof))
77 __throw_exception_again;
91 template<
typename _CharT,
typename _Traits>
92 template<
typename _ValueT>
93 basic_istream<_CharT, _Traits>&
94 basic_istream<_CharT, _Traits>::
95 _M_extract(_ValueT& __v)
97 sentry __cerb(*
this,
false);
100 ios_base::iostate __err = ios_base::goodbit;
103 const __num_get_type& __ng = __check_facet(this->_M_num_get);
104 __ng.get(*
this, 0, *
this, __err, __v);
108 this->_M_setstate(ios_base::badbit);
109 __throw_exception_again;
112 { this->_M_setstate(ios_base::badbit); }
114 this->setstate(__err);
119 template<
typename _CharT,
typename _Traits>
120 basic_istream<_CharT, _Traits>&
121 basic_istream<_CharT, _Traits>::
122 operator>>(
short& __n)
126 sentry __cerb(*
this,
false);
129 ios_base::iostate __err = ios_base::goodbit;
133 const __num_get_type& __ng = __check_facet(this->_M_num_get);
134 __ng.get(*
this, 0, *
this, __err, __l);
138 if (__l < __gnu_cxx::__numeric_traits<short>::__min)
140 __err |= ios_base::failbit;
141 __n = __gnu_cxx::__numeric_traits<short>::__min;
143 else if (__l > __gnu_cxx::__numeric_traits<short>::__max)
145 __err |= ios_base::failbit;
146 __n = __gnu_cxx::__numeric_traits<short>::__max;
153 this->_M_setstate(ios_base::badbit);
154 __throw_exception_again;
157 { this->_M_setstate(ios_base::badbit); }
159 this->setstate(__err);
164 template<
typename _CharT,
typename _Traits>
165 basic_istream<_CharT, _Traits>&
166 basic_istream<_CharT, _Traits>::
171 sentry __cerb(*
this,
false);
174 ios_base::iostate __err = ios_base::goodbit;
178 const __num_get_type& __ng = __check_facet(this->_M_num_get);
179 __ng.get(*
this, 0, *
this, __err, __l);
183 if (__l < __gnu_cxx::__numeric_traits<int>::__min)
185 __err |= ios_base::failbit;
186 __n = __gnu_cxx::__numeric_traits<int>::__min;
188 else if (__l > __gnu_cxx::__numeric_traits<int>::__max)
190 __err |= ios_base::failbit;
191 __n = __gnu_cxx::__numeric_traits<int>::__max;
198 this->_M_setstate(ios_base::badbit);
199 __throw_exception_again;
202 { this->_M_setstate(ios_base::badbit); }
204 this->setstate(__err);
209 template<
typename _CharT,
typename _Traits>
210 basic_istream<_CharT, _Traits>&
211 basic_istream<_CharT, _Traits>::
212 operator>>(__streambuf_type* __sbout)
214 ios_base::iostate __err = ios_base::goodbit;
215 sentry __cerb(*
this,
false);
216 if (__cerb && __sbout)
221 if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof))
222 __err |= ios_base::failbit;
224 __err |= ios_base::eofbit;
228 this->_M_setstate(ios_base::failbit);
229 __throw_exception_again;
232 { this->_M_setstate(ios_base::failbit); }
235 __err |= ios_base::failbit;
237 this->setstate(__err);
241 template<
typename _CharT,
typename _Traits>
242 typename basic_istream<_CharT, _Traits>::int_type
243 basic_istream<_CharT, _Traits>::
246 const int_type __eof = traits_type::eof();
247 int_type __c = __eof;
249 ios_base::iostate __err = ios_base::goodbit;
250 sentry __cerb(*
this,
true);
255 __c = this->rdbuf()->sbumpc();
257 if (!traits_type::eq_int_type(__c, __eof))
260 __err |= ios_base::eofbit;
264 this->_M_setstate(ios_base::badbit);
265 __throw_exception_again;
268 { this->_M_setstate(ios_base::badbit); }
271 __err |= ios_base::failbit;
273 this->setstate(__err);
277 template<
typename _CharT,
typename _Traits>
278 basic_istream<_CharT, _Traits>&
279 basic_istream<_CharT, _Traits>::
283 ios_base::iostate __err = ios_base::goodbit;
284 sentry __cerb(*
this,
true);
289 const int_type __cb = this->rdbuf()->sbumpc();
291 if (!traits_type::eq_int_type(__cb, traits_type::eof()))
294 __c = traits_type::to_char_type(__cb);
297 __err |= ios_base::eofbit;
301 this->_M_setstate(ios_base::badbit);
302 __throw_exception_again;
305 { this->_M_setstate(ios_base::badbit); }
308 __err |= ios_base::failbit;
310 this->setstate(__err);
314 template<
typename _CharT,
typename _Traits>
315 basic_istream<_CharT, _Traits>&
316 basic_istream<_CharT, _Traits>::
317 get(char_type* __s,
streamsize __n, char_type __delim)
320 ios_base::iostate __err = ios_base::goodbit;
321 sentry __cerb(*
this,
true);
326 const int_type __idelim = traits_type::to_int_type(__delim);
327 const int_type __eof = traits_type::eof();
328 __streambuf_type* __sb = this->rdbuf();
329 int_type __c = __sb->sgetc();
331 while (_M_gcount + 1 < __n
332 && !traits_type::eq_int_type(__c, __eof)
333 && !traits_type::eq_int_type(__c, __idelim))
335 *__s++ = traits_type::to_char_type(__c);
337 __c = __sb->snextc();
339 if (traits_type::eq_int_type(__c, __eof))
340 __err |= ios_base::eofbit;
344 this->_M_setstate(ios_base::badbit);
345 __throw_exception_again;
348 { this->_M_setstate(ios_base::badbit); }
355 __err |= ios_base::failbit;
357 this->setstate(__err);
361 template<
typename _CharT,
typename _Traits>
362 basic_istream<_CharT, _Traits>&
363 basic_istream<_CharT, _Traits>::
364 get(__streambuf_type& __sb, char_type __delim)
367 ios_base::iostate __err = ios_base::goodbit;
368 sentry __cerb(*
this,
true);
373 const int_type __idelim = traits_type::to_int_type(__delim);
374 const int_type __eof = traits_type::eof();
375 __streambuf_type* __this_sb = this->rdbuf();
376 int_type __c = __this_sb->sgetc();
377 char_type __c2 = traits_type::to_char_type(__c);
379 while (!traits_type::eq_int_type(__c, __eof)
380 && !traits_type::eq_int_type(__c, __idelim)
381 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
384 __c = __this_sb->snextc();
385 __c2 = traits_type::to_char_type(__c);
387 if (traits_type::eq_int_type(__c, __eof))
388 __err |= ios_base::eofbit;
392 this->_M_setstate(ios_base::badbit);
393 __throw_exception_again;
396 { this->_M_setstate(ios_base::badbit); }
399 __err |= ios_base::failbit;
401 this->setstate(__err);
405 template<
typename _CharT,
typename _Traits>
406 basic_istream<_CharT, _Traits>&
411 ios_base::iostate __err = ios_base::goodbit;
412 sentry __cerb(*
this,
true);
417 const int_type __idelim = traits_type::to_int_type(__delim);
418 const int_type __eof = traits_type::eof();
419 __streambuf_type* __sb = this->rdbuf();
420 int_type __c = __sb->sgetc();
422 while (_M_gcount + 1 < __n
423 && !traits_type::eq_int_type(__c, __eof)
424 && !traits_type::eq_int_type(__c, __idelim))
426 *__s++ = traits_type::to_char_type(__c);
427 __c = __sb->snextc();
430 if (traits_type::eq_int_type(__c, __eof))
431 __err |= ios_base::eofbit;
434 if (traits_type::eq_int_type(__c, __idelim))
440 __err |= ios_base::failbit;
445 this->_M_setstate(ios_base::badbit);
446 __throw_exception_again;
449 { this->_M_setstate(ios_base::badbit); }
456 __err |= ios_base::failbit;
458 this->setstate(__err);
465 template<
typename _CharT,
typename _Traits>
466 basic_istream<_CharT, _Traits>&
467 basic_istream<_CharT, _Traits>::
471 sentry __cerb(*
this,
true);
474 ios_base::iostate __err = ios_base::goodbit;
477 const int_type __eof = traits_type::eof();
478 __streambuf_type* __sb = this->rdbuf();
480 if (traits_type::eq_int_type(__sb->sbumpc(), __eof))
481 __err |= ios_base::eofbit;
487 this->_M_setstate(ios_base::badbit);
488 __throw_exception_again;
491 { this->_M_setstate(ios_base::badbit); }
493 this->setstate(__err);
498 template<
typename _CharT,
typename _Traits>
499 basic_istream<_CharT, _Traits>&
500 basic_istream<_CharT, _Traits>::
504 sentry __cerb(*
this,
true);
505 if (__cerb && __n > 0)
507 ios_base::iostate __err = ios_base::goodbit;
510 const int_type __eof = traits_type::eof();
511 __streambuf_type* __sb = this->rdbuf();
512 int_type __c = __sb->sgetc();
521 bool __large_ignore =
false;
524 while (_M_gcount < __n
525 && !traits_type::eq_int_type(__c, __eof))
528 __c = __sb->snextc();
530 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
531 && !traits_type::eq_int_type(__c, __eof))
534 __gnu_cxx::__numeric_traits<streamsize>::__min;
535 __large_ignore =
true;
542 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
544 if (traits_type::eq_int_type(__c, __eof))
545 __err |= ios_base::eofbit;
549 this->_M_setstate(ios_base::badbit);
550 __throw_exception_again;
553 { this->_M_setstate(ios_base::badbit); }
555 this->setstate(__err);
560 template<
typename _CharT,
typename _Traits>
561 basic_istream<_CharT, _Traits>&
562 basic_istream<_CharT, _Traits>::
566 sentry __cerb(*
this,
true);
567 if (__cerb && __n > 0)
569 ios_base::iostate __err = ios_base::goodbit;
572 const int_type __eof = traits_type::eof();
573 __streambuf_type* __sb = this->rdbuf();
574 int_type __c = __sb->sgetc();
577 bool __large_ignore =
false;
580 while (_M_gcount < __n
581 && !traits_type::eq_int_type(__c, __eof)
582 && !traits_type::eq_int_type(__c, __delim))
585 __c = __sb->snextc();
587 if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max
588 && !traits_type::eq_int_type(__c, __eof)
589 && !traits_type::eq_int_type(__c, __delim))
592 __gnu_cxx::__numeric_traits<streamsize>::__min;
593 __large_ignore =
true;
600 _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max;
602 if (traits_type::eq_int_type(__c, __eof))
603 __err |= ios_base::eofbit;
604 else if (traits_type::eq_int_type(__c, __delim))
607 < __gnu_cxx::__numeric_traits<streamsize>::__max)
614 this->_M_setstate(ios_base::badbit);
615 __throw_exception_again;
618 { this->_M_setstate(ios_base::badbit); }
620 this->setstate(__err);
625 template<
typename _CharT,
typename _Traits>
626 typename basic_istream<_CharT, _Traits>::int_type
627 basic_istream<_CharT, _Traits>::
630 int_type __c = traits_type::eof();
632 sentry __cerb(*
this,
true);
635 ios_base::iostate __err = ios_base::goodbit;
638 __c = this->rdbuf()->sgetc();
639 if (traits_type::eq_int_type(__c, traits_type::eof()))
640 __err |= ios_base::eofbit;
644 this->_M_setstate(ios_base::badbit);
645 __throw_exception_again;
648 { this->_M_setstate(ios_base::badbit); }
650 this->setstate(__err);
655 template<
typename _CharT,
typename _Traits>
656 basic_istream<_CharT, _Traits>&
657 basic_istream<_CharT, _Traits>::
661 sentry __cerb(*
this,
true);
664 ios_base::iostate __err = ios_base::goodbit;
667 _M_gcount = this->rdbuf()->sgetn(__s, __n);
668 if (_M_gcount != __n)
669 __err |= (ios_base::eofbit | ios_base::failbit);
673 this->_M_setstate(ios_base::badbit);
674 __throw_exception_again;
677 { this->_M_setstate(ios_base::badbit); }
679 this->setstate(__err);
684 template<
typename _CharT,
typename _Traits>
686 basic_istream<_CharT, _Traits>::
690 sentry __cerb(*
this,
true);
693 ios_base::iostate __err = ios_base::goodbit;
697 const streamsize __num = this->rdbuf()->in_avail();
699 _M_gcount = this->rdbuf()->sgetn(__s,
std::min(__num, __n));
700 else if (__num == -1)
701 __err |= ios_base::eofbit;
705 this->_M_setstate(ios_base::badbit);
706 __throw_exception_again;
709 { this->_M_setstate(ios_base::badbit); }
711 this->setstate(__err);
716 template<
typename _CharT,
typename _Traits>
717 basic_istream<_CharT, _Traits>&
718 basic_istream<_CharT, _Traits>::
719 putback(char_type __c)
725 this->clear(this->rdstate() & ~ios_base::eofbit);
726 sentry __cerb(*
this,
true);
729 ios_base::iostate __err = ios_base::goodbit;
732 const int_type __eof = traits_type::eof();
733 __streambuf_type* __sb = this->rdbuf();
735 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
736 __err |= ios_base::badbit;
740 this->_M_setstate(ios_base::badbit);
741 __throw_exception_again;
744 { this->_M_setstate(ios_base::badbit); }
746 this->setstate(__err);
751 template<
typename _CharT,
typename _Traits>
752 basic_istream<_CharT, _Traits>&
753 basic_istream<_CharT, _Traits>::
760 this->clear(this->rdstate() & ~ios_base::eofbit);
761 sentry __cerb(*
this,
true);
764 ios_base::iostate __err = ios_base::goodbit;
767 const int_type __eof = traits_type::eof();
768 __streambuf_type* __sb = this->rdbuf();
770 || traits_type::eq_int_type(__sb->sungetc(), __eof))
771 __err |= ios_base::badbit;
775 this->_M_setstate(ios_base::badbit);
776 __throw_exception_again;
779 { this->_M_setstate(ios_base::badbit); }
781 this->setstate(__err);
786 template<
typename _CharT,
typename _Traits>
788 basic_istream<_CharT, _Traits>::
794 sentry __cerb(*
this,
true);
797 ios_base::iostate __err = ios_base::goodbit;
800 __streambuf_type* __sb = this->rdbuf();
803 if (__sb->pubsync() == -1)
804 __err |= ios_base::badbit;
811 this->_M_setstate(ios_base::badbit);
812 __throw_exception_again;
815 { this->_M_setstate(ios_base::badbit); }
817 this->setstate(__err);
822 template<
typename _CharT,
typename _Traits>
823 typename basic_istream<_CharT, _Traits>::pos_type
824 basic_istream<_CharT, _Traits>::
829 pos_type __ret = pos_type(-1);
830 sentry __cerb(*
this,
true);
836 __ret = this->rdbuf()->pubseekoff(0, ios_base::cur,
841 this->_M_setstate(ios_base::badbit);
842 __throw_exception_again;
845 { this->_M_setstate(ios_base::badbit); }
850 template<
typename _CharT,
typename _Traits>
851 basic_istream<_CharT, _Traits>&
852 basic_istream<_CharT, _Traits>::
853 seekg(pos_type __pos)
858 this->clear(this->rdstate() & ~ios_base::eofbit);
859 sentry __cerb(*
this,
true);
862 ios_base::iostate __err = ios_base::goodbit;
868 const pos_type __p = this->rdbuf()->pubseekpos(__pos,
872 if (__p == pos_type(off_type(-1)))
873 __err |= ios_base::failbit;
878 this->_M_setstate(ios_base::badbit);
879 __throw_exception_again;
882 { this->_M_setstate(ios_base::badbit); }
884 this->setstate(__err);
889 template<
typename _CharT,
typename _Traits>
890 basic_istream<_CharT, _Traits>&
891 basic_istream<_CharT, _Traits>::
892 seekg(off_type __off, ios_base::seekdir __dir)
897 this->clear(this->rdstate() & ~ios_base::eofbit);
898 sentry __cerb(*
this,
true);
901 ios_base::iostate __err = ios_base::goodbit;
907 const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir,
911 if (__p == pos_type(off_type(-1)))
912 __err |= ios_base::failbit;
917 this->_M_setstate(ios_base::badbit);
918 __throw_exception_again;
921 { this->_M_setstate(ios_base::badbit); }
923 this->setstate(__err);
929 template<
typename _CharT,
typename _Traits>
930 basic_istream<_CharT, _Traits>&
931 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c)
933 typedef basic_istream<_CharT, _Traits> __istream_type;
934 typedef typename __istream_type::int_type __int_type;
936 typename __istream_type::sentry __cerb(__in,
false);
939 ios_base::iostate __err = ios_base::goodbit;
942 const __int_type __cb = __in.rdbuf()->sbumpc();
943 if (!_Traits::eq_int_type(__cb, _Traits::eof()))
944 __c = _Traits::to_char_type(__cb);
946 __err |= (ios_base::eofbit | ios_base::failbit);
950 __in._M_setstate(ios_base::badbit);
951 __throw_exception_again;
954 { __in._M_setstate(ios_base::badbit); }
956 __in.setstate(__err);
961 template<
typename _CharT,
typename _Traits>
962 basic_istream<_CharT, _Traits>&
963 operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s)
965 typedef basic_istream<_CharT, _Traits> __istream_type;
966 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
967 typedef typename _Traits::int_type int_type;
968 typedef _CharT char_type;
969 typedef ctype<_CharT> __ctype_type;
972 ios_base::iostate __err = ios_base::goodbit;
973 typename __istream_type::sentry __cerb(__in,
false);
981 __num = __gnu_cxx::__numeric_traits<streamsize>::__max;
983 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
985 const int_type __eof = _Traits::eof();
986 __streambuf_type* __sb = __in.rdbuf();
987 int_type __c = __sb->sgetc();
989 while (__extracted < __num - 1
990 && !_Traits::eq_int_type(__c, __eof)
991 && !__ct.is(ctype_base::space,
992 _Traits::to_char_type(__c)))
994 *__s++ = _Traits::to_char_type(__c);
996 __c = __sb->snextc();
998 if (_Traits::eq_int_type(__c, __eof))
999 __err |= ios_base::eofbit;
1008 __in._M_setstate(ios_base::badbit);
1009 __throw_exception_again;
1012 { __in._M_setstate(ios_base::badbit); }
1015 __err |= ios_base::failbit;
1017 __in.setstate(__err);
1022 template<
typename _CharT,
typename _Traits>
1023 basic_istream<_CharT, _Traits>&
1024 ws(basic_istream<_CharT, _Traits>& __in)
1026 typedef basic_istream<_CharT, _Traits> __istream_type;
1027 typedef basic_streambuf<_CharT, _Traits> __streambuf_type;
1028 typedef typename __istream_type::int_type __int_type;
1029 typedef ctype<_CharT> __ctype_type;
1031 const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
1032 const __int_type __eof = _Traits::eof();
1033 __streambuf_type* __sb = __in.rdbuf();
1034 __int_type __c = __sb->sgetc();
1036 while (!_Traits::eq_int_type(__c, __eof)
1037 && __ct.is(ctype_base::space, _Traits::to_char_type(__c)))
1038 __c = __sb->snextc();
1040 if (_Traits::eq_int_type(__c, __eof))
1041 __in.setstate(ios_base::eofbit);
1047 #if _GLIBCXX_EXTERN_TEMPLATE
1048 extern template class basic_istream<char>;
1049 extern template istream& ws(istream&);
1050 extern template istream&
operator>>(istream&,
char&);
1051 extern template istream&
operator>>(istream&,
char*);
1052 extern template istream&
operator>>(istream&,
unsigned char&);
1053 extern template istream&
operator>>(istream&,
signed char&);
1054 extern template istream&
operator>>(istream&,
unsigned char*);
1055 extern template istream&
operator>>(istream&,
signed char*);
1057 extern template istream& istream::_M_extract(
unsigned short&);
1058 extern template istream& istream::_M_extract(
unsigned int&);
1059 extern template istream& istream::_M_extract(
long&);
1060 extern template istream& istream::_M_extract(
unsigned long&);
1061 extern template istream& istream::_M_extract(
bool&);
1062 #ifdef _GLIBCXX_USE_LONG_LONG
1063 extern template istream& istream::_M_extract(
long long&);
1064 extern template istream& istream::_M_extract(
unsigned long long&);
1066 extern template istream& istream::_M_extract(
float&);
1067 extern template istream& istream::_M_extract(
double&);
1068 extern template istream& istream::_M_extract(
long double&);
1069 extern template istream& istream::_M_extract(
void*&);
1071 extern template class basic_iostream<char>;
1073 #ifdef _GLIBCXX_USE_WCHAR_T
1074 extern template class basic_istream<wchar_t>;
1075 extern template wistream& ws(wistream&);
1076 extern template wistream&
operator>>(wistream&,
wchar_t&);
1077 extern template wistream&
operator>>(wistream&,
wchar_t*);
1079 extern template wistream& wistream::_M_extract(
unsigned short&);
1080 extern template wistream& wistream::_M_extract(
unsigned int&);
1081 extern template wistream& wistream::_M_extract(
long&);
1082 extern template wistream& wistream::_M_extract(
unsigned long&);
1083 extern template wistream& wistream::_M_extract(
bool&);
1084 #ifdef _GLIBCXX_USE_LONG_LONG
1085 extern template wistream& wistream::_M_extract(
long long&);
1086 extern template wistream& wistream::_M_extract(
unsigned long long&);
1088 extern template wistream& wistream::_M_extract(
float&);
1089 extern template wistream& wistream::_M_extract(
double&);
1090 extern template wistream& wistream::_M_extract(
long double&);
1091 extern template wistream& wistream::_M_extract(
void*&);
1093 extern template class basic_iostream<wchar_t>;
1097 _GLIBCXX_END_NAMESPACE_VERSION
basic_istream< _CharT, _Traits > & operator>>(basic_istream< _CharT, _Traits > &__is, basic_string< _CharT, _Traits, _Alloc > &__str)
Read stream into a string.
ISO C++ entities toplevel namespace is std.
static const iostate badbit
Indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
static const iostate goodbit
Indicates all is well.
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.
_Ios_Iostate iostate
This is a bitmask type.
static const fmtflags skipws
Skips leading white space before certain input operations.
static const iostate eofbit
Indicates that an input operation reached the end of an input sequence.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...