📄 istream.tcc
字号:
{ sentry __cerb(*this, false); if (__cerb) { try { iostate __err = iostate(0); _M_fnumget->get(*this, 0, *this, __err, __n); this->setstate(__err); } catch(exception& __fail){ // 27.6.1.2.1 Common requirements. // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(void*& __n) { sentry __cerb(*this, false); if (__cerb) { try { iostate __err = iostate(0); _M_fnumget->get(*this, 0, *this, __err, __n); this->setstate(__err); } catch(exception& __fail){ // 27.6.1.2.1 Common requirements. // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(__streambuf_type* __sbout) { streamsize __xtrct = 0; __streambuf_type* __sbin = this->rdbuf(); sentry __cerb(*this, false); if (__sbout && __cerb) __xtrct = _S_copy_streambufs(*this, __sbin, __sbout); if (!__sbout || !__xtrct) this->setstate(ios_base::failbit); return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::get(void) { const int_type __eof = traits_type::eof(); int_type __retval = __eof; _M_gcount = 0; sentry __cerb(*this, true); if (__cerb) { try { __retval = this->rdbuf()->sbumpc(); // 27.6.1.1 paragraph 3 if (__retval != __eof) _M_gcount = 1; else this->setstate(ios_base::eofbit | ios_base::failbit); } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } return __retval; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type& __c) { const int_type __eof = traits_type::eof(); int_type __bufval; _M_gcount = 0; sentry __cerb(*this, true); if (__cerb) { try { __bufval = this->rdbuf()->sbumpc(); // 27.6.1.1 paragraph 3 if (__bufval != __eof) { _M_gcount = 1; __c = traits_type::to_char_type(__bufval); } else this->setstate(ios_base::eofbit | ios_base::failbit); } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: get(char_type* __s, streamsize __n, char_type __delim) { const int_type __eof = traits_type::eof(); int_type __idelim = traits_type::to_int_type(__delim); _M_gcount = 0; sentry __cerb(*this, true); if (__cerb) { try { __streambuf_type* __sb = this->rdbuf(); for (; _M_gcount < __n; ++_M_gcount) { int_type __bufval = __sb->sbumpc(); if (__bufval == __eof) { this->setstate(ios_base::eofbit | ios_base::failbit); break; } if (__idelim == __bufval) { __sb->sputbackc(__bufval); break; } *__s = traits_type::to_char_type(__bufval); ++__s; } if (!_M_gcount) this->setstate(ios_base::failbit); *__s = char_type(NULL); } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: get(__streambuf_type& __sb, char_type __delim) { _M_gcount = 0; sentry __cerb(*this, true); if (__cerb) { try { const int_type __eof = traits_type::eof(); __streambuf_type* __this_sb = this->rdbuf(); const __ctype_type* __ctype = this->_M_get_fctype_ios(); streamsize __n = __this_sb->in_avail(); for (; _M_gcount < __n; ++_M_gcount) { int_type __bufval = __this_sb->sbumpc(); if (__bufval == __eof) { this->setstate(ios_base::eofbit); break; } __bufval = traits_type::to_char_type(__bufval); if (__ctype->is(__delim, __bufval)) { __this_sb->sputbackc(__bufval); break; } int_type __g = __sb.sputc(__bufval); if (__g == __eof) { __this_sb->sputbackc(__bufval); break; } } } catch(exception& __fail){ // "...the exception is caught but not rethrown." } if (!_M_gcount) this->setstate(ios_base::failbit); } return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: getline(char_type* __s, streamsize __n, char_type __delim) { _M_gcount = 0; bool __testdelim = false; sentry __cerb(*this, true); if (__cerb) { try { int_type __idelim = traits_type::to_int_type(__delim); __streambuf_type* __sb = this->rdbuf(); int_type __c = __sb->sbumpc(); ++_M_gcount; const int_type __eof = traits_type::eof(); __testdelim = __idelim == __c; bool __testeof = __c == __eof; while (_M_gcount < __n - 1 && !__testeof && !__testdelim) { *__s = traits_type::to_char_type(__c); ++__s; __c = __sb->sbumpc(); ++_M_gcount; __testeof = __c == __eof; __testdelim = __c == __idelim; } if (__testeof) this->setstate(ios_base::eofbit); if (_M_gcount == __n - 1) { *__s = traits_type::to_char_type(__c); ++__s; } *__s = char_type(NULL); } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } if (!_M_gcount || _M_gcount == __n - 1) this->setstate(ios_base::failbit); return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: ignore(streamsize __n, int_type __delim) { const int_type __eof = traits_type::eof(); _M_gcount = 0; sentry __cerb(*this, true); if (__cerb && __n != numeric_limits<int>::max()) { try { __streambuf_type* __sb = this->rdbuf(); const __ctype_type* __ctype = this->_M_get_fctype_ios(); for (; _M_gcount < __n; ++_M_gcount) { int_type __bufval = __sb->sbumpc(); if (__bufval == __eof) { this->setstate(ios_base::eofbit); break; } if (__ctype->is(__delim, __bufval)) break; } } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } return *this; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::peek(void) { int_type __retval = traits_type::eof(); _M_gcount = 0; sentry __cerb(*this, true); if (__cerb && this->good()) { try { __retval = this->rdbuf()->sgetc(); _M_gcount = 1; } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } return __retval; } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: read(char_type* __s, streamsize __n) { const int_type __eof = traits_type::eof(); _M_gcount = 0; sentry __cerb(*this, true); if (__cerb) { try { __streambuf_type* __sb = this->rdbuf(); for (; _M_gcount < __n; ++_M_gcount) { int_type __bufval = __sb->sbumpc(); if (__bufval == __eof) { this->setstate(ios_base::eofbit | ios_base::failbit); break; } *__s = traits_type::to_char_type(__bufval); ++__s; } } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } else this->setstate(ios_base::failbit); return *this; } template<typename _CharT, typename _Traits> streamsize basic_istream<_CharT, _Traits>:: readsome(char_type* __s, streamsize __n) { const int_type __eof = traits_type::eof(); _M_gcount = 0; sentry __cerb(*this, true); if (__cerb) { try { streamsize __num = this->rdbuf()->in_avail(); if (__num != static_cast<streamsize>(__eof)) { __num = min(__num, __n); _M_gcount = this->rdbuf()->sgetn(__s, __num); } else this->setstate(ios_base::eofbit); } catch(exception& __fail){ // 27.6.1.3 paragraph 1 // Turn this on without causing an ios::failure to be thrown. this->setstate(ios_base::badbit); if ((this->exceptions() & ios_base::badbit) != 0) throw; } } else this->setstate(ios_base::failbit); return _M_gcount; } template<typename _CharT, typename _Traits>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -