📄 istream.cc
字号:
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
use_facet<num_get<charT,istreambuf_iterator<charT,traits> > >(this->getloc())
#else
use_facet(this->getloc(),(num_get<charT,istreambuf_iterator<charT,traits> >*)0)
#endif
.get(istreambuf_iterator<charT,traits>(*this),istreambuf_iterator<charT,traits>(),*this,err,p);
}
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::badbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif
if ( err ) this->setstate(err);
return *this;
}
/*
* istream_type& operator>>(basic_streambuf&)
* reads characters from the stream and inserts them into 'sb'
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::operator>>(streambuf_type& sb)
{
ios_base::iostate err = 0;
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
if(ipfx)
{
int_type c;
if ( traits::eq_int_type(this->rdbuf()->sgetc(),traits::eof()) )
err = ios_base::failbit;
while( !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) ) {
if( traits::eq_int_type(sb.sputc(c),traits::eof()) ) {
err = ios_base::failbit;
break;
}
this->rdbuf()->sbumpc();
}
if( traits::eq_int_type(c,traits::eof()) )
err |= ios_base::eofbit;
}
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::failbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif
if ( err ) this->setstate(err);
return *this;
}
/*
* istream_type& operator>>(basic_streambuf *)
* reads characters from the stream and inserts them into 'sb'
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::operator>>(streambuf_type *sb)
{
ios_base::iostate err = 0;
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
if ( sb!=0 )
{
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this);
if(ipfx)
{
int_type c;
if ( traits::eq_int_type(this->rdbuf()->sgetc(),traits::eof()) )
err = ios_base::failbit;
while( !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) )
{
if( traits::eq_int_type(sb->sputc(c),traits::eof()) )
{
err = ios_base::failbit;
break;
}
this->rdbuf()->sbumpc();
}
if( traits::eq_int_type(c,traits::eof()) )
err |= ios_base::eofbit;
}
}
else
err = ios_base::failbit;
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::failbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif
if ( err ) this->setstate(err);
return *this;
}
/*
* istream_type& get(char_type *, streamsize, char_type)
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::
get(char_type *s, streamsize n, char_type delim)
{
ios_base::iostate err = 0;
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
__chcount = 0;
if (s!=0)
{
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
if(ipfx)
{
char_type *op = s;
int_type c = 0;
while(--n > 0 && (c = this->rdbuf()->sgetc()) != delim &&
( !traits::eq_int_type(c,traits::eof()) ))
{
*s++ = _RWSTD_STATIC_CAST(char_type, c);
++__chcount;
this->rdbuf()->snextc();
}
if( traits::eq_int_type(c,traits::eof()) )
err = ((s == op) ? (ios_base::eofbit | ios_base::failbit) :
ios_base::eofbit);
}
*s = 0; //terminate with null
}
else
err = ios_base::badbit;
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::badbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif
if ( err ) this->setstate(err);
return *this;
}
/*
* istream_type& get(char_type&)
* gets a single character, first skipping white space.
* see also: int_type get();
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::get(char_type& s)
{
ios_base::iostate err = 0;
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
__chcount = 0;
if(ipfx)
{
int_type tmp = this->rdbuf()->sbumpc();
if ( traits::eq_int_type(tmp,traits::eof()) )
{
err = ios_base::failbit | ios_base::eofbit;
}
else
{
s = traits::to_char_type(tmp);
__chcount = 1;
}
}
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::badbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif
if ( err ) this->setstate(err);
return *this;
}
/*
* istream_type& get(basic_streambuf&, char_type)
* insert characters into sb upto delim
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::
get(streambuf_type& sb, char_type delim)
{
ios_base::iostate err = 0;
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
__chcount = 0;
if(ipfx)
{
int_type c;
while(((c = this->rdbuf()->sgetc()) != delim) &&
( !traits::eq_int_type(c,traits::eof()) ))
{
if( traits::eq_int_type(sb.sputc(c),traits::eof()) ) {
err = ios_base::failbit;
break;
}
++__chcount;
this->rdbuf()->sbumpc();
}
if(c == traits::eof())
err |= ios_base::eofbit;
}
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::badbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif
if ( err ) this->setstate(err);
return *this;
}
/*
* istream_type& getline(char_type *, streamsize, char_type)
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::
getline(char_type *s, streamsize n, char_type delim)
{
ios_base::iostate err = 0;
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
__chcount = 0;
if (s!=0)
{
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
if(ipfx) {
char_type *op = s;
int_type c = 0;
while( --n > 0 && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) )
{
++__chcount;
this->rdbuf()->sbumpc();
if(c == delim)
break;
*s++ = _RWSTD_STATIC_CAST(char_type, c);
}
*s = 0;
if( traits::eq_int_type(c,traits::eof()) ) {
err = (s == op) ? (ios_base::eofbit | ios_base::failbit)
: ios_base::eofbit;
}
else if ( this->rdbuf()->sgetc() == delim )
this->rdbuf()->sbumpc(); // eat the delimiter
else if ( n == 0 )
err |= ios_base::failbit; // too much data
}
*s = 0; //terminate with null
}
else
err = ios_base::badbit;
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::badbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif // _RWSTD_NO_EXCEPTIONS
if ( err ) this->setstate(err);
return *this;
}
/*
* istream_type& ignore(streamsize, int_type)
* this ignores n characters or until delim
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::ignore(streamsize n, int_type delim)
{
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
__chcount = 0;
if(ipfx)
{
int_type c = 0;
while(--n >= 0 && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()) )
{
++__chcount;
this->rdbuf()->sbumpc();
if(c == delim)
break;
}
if( traits::eq_int_type(c,traits::eof()) )
this->setstate(ios_base::eofbit);
}
return *this;
}
/*
* istream_type& read(char_type *, streamsize)
*/
template<class charT, class traits>
basic_istream<charT, traits>&
basic_istream<charT, traits>::read(char_type *s, streamsize n)
{
ios_base::iostate err = 0;
#ifndef _RWSTD_NO_EXCEPTIONS
try {
#endif
__chcount = 0;
if (s!=0)
{
_TYPENAME basic_istream<charT, traits>::sentry ipfx(*this,1);
if(ipfx)
{
int_type c = 0;
while((--n >= 0) && !traits::eq_int_type( (c = this->rdbuf()->sgetc()),traits::eof()))
{
*s++ = c;
++__chcount;
this->rdbuf()->sbumpc();
}
if( traits::eq_int_type(c,traits::eof()) )
err = (n >= 0) ? (ios_base::eofbit | ios_base::failbit) : ios_base::eofbit;
}
}
else
err = ios_base::badbit;
#ifndef _RWSTD_NO_EXCEPTIONS
} // end of try block
#endif
#ifndef _RWSTD_NO_EXCEPTIONS
catch(...)
{
bool flag = false;
try {
this->setstate(ios_base::badbit);
}
catch( ios_base::failure ) { flag= true; }
if ( flag ) throw;
}
#endif // _RWSTD_NO_EXCEPTIONS
if ( err ) this->setstate(err);
return *this;
}
/*
* streamsize readsome(char_type *, streamsize)
*/
template<class charT, class traits>
streamsize
basic_istream<charT, traits>::readsome(char_type *s, streamsize n)
{
int navail = this->rdbuf()->in_avail();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -