⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 istream.cc

📁 Keil for ARM.rar
💻 CC
📖 第 1 页 / 共 4 页
字号:
    if(navail == -1)
    {   
      this->setstate(ios_base::eofbit);
      return 0;
    }
    if(navail == 0 ) return 0;

    if ( this->good() )
    {
      if(n < navail) 
      { 
        read(s, n);
        return (n);
      }

      read(s, navail);
      return (streamsize)(navail);
    }
    else
    { 
      if ( !(this->rdstate() & ios_base::failbit) )
        this->setstate(ios_base::failbit);
    }
  
    return 0;
  }

  /*
   * int_type peek()
   */

  template<class charT, class traits>
  _TYPENAME basic_istream<charT, traits>::int_type
  basic_istream<charT, traits>::peek()
  {
    __chcount = 0;

    if(this->good())
    {
#ifdef _RWSTD_MULTI_THREAD
      if ( this->rdbuf() )
        _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
#endif
      _TYPENAME traits::int_type tmp = this->rdbuf()->sgetc();
      if ( !traits::eq_int_type( tmp,traits::eof() ) )
        __chcount = 1;
      return tmp;
    }

    return traits::eof();
  }

  /*
   * pos_type tellg()
   */

  template<class charT, class traits>
  _TYPENAME basic_istream<charT, traits>::pos_type
  basic_istream<charT, traits>::tellg()
  {
    pos_type         p;

#ifndef _RWSTD_NO_EXCEPTIONS
    try {
#endif 

#ifdef _RWSTD_MULTI_THREAD
      if ( this->rdbuf() ) {
        _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
#endif //  _RWSTD_MULTI_THREAD
      if ( this->fail() ) return pos_type(off_type(-1));   

      p = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);

#ifdef _RWSTD_MULTI_THREAD
      }
#endif //  _RWSTD_MULTI_THREAD

#ifndef _RWSTD_NO_EXCEPTIONS
    }
#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

    return p;
  }


  /*
   * istream_type& putback(char_type)
   */

  template<class charT, class traits>
  basic_istream<charT, traits>&
  basic_istream<charT, traits>::putback(char_type c)
  {
    ios_base::iostate err = 0;

#ifndef _RWSTD_NO_EXCEPTIONS
    try {
#endif 
  
#ifdef _RWSTD_MULTI_THREAD
      if ( this->rdbuf() )
        _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
#endif 
      if (this->good())
      {
        if( traits::eq_int_type(this->rdbuf()->sputbackc(c),traits::eof()) ) 
          err = ios_base::badbit;      
      }
      else
      { 
        if ( !(this->rdstate() & ios_base::failbit) )
          this->setstate(ios_base::failbit);
      }

#ifndef _RWSTD_NO_EXCEPTIONS
    }
#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& unget()
   */

  template<class charT, class traits>
  basic_istream<charT, traits>&
  basic_istream<charT, traits>::unget()
  {
    ios_base::iostate err = 0;

#ifndef _RWSTD_NO_EXCEPTIONS
    try {
#endif 

#ifdef _RWSTD_MULTI_THREAD
      if ( this->rdbuf() )
        _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
#endif
      if (this->good())
      {
        if( traits::eq_int_type(this->rdbuf()->sungetc(),traits::eof()) )
          err = ios_base::badbit;  
      }
      else
      { 
        if ( !(this->rdstate() & ios_base::failbit) )
          this->setstate(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::badbit);
      }
      catch( ios_base::failure ) { flag= true; }
      if ( flag ) throw;
    }
#endif //  _RWSTD_NO_EXCEPTIONS
    if ( err ) this->setstate(err);
    return *this;
  }

  /*
   * streamsize gcount() const
   */

  template<class charT, class traits>
  streamsize basic_istream<charT, traits>::gcount() const
  {
    return __chcount;
  }

  /*
   * int sync()
   */

  template<class charT, class traits>
  int basic_istream<charT, traits>::sync()
  {
    ios_base::iostate err = 0;

#ifndef _RWSTD_NO_EXCEPTIONS
    try {
#endif 
  
#ifdef _RWSTD_MULTI_THREAD
      if ( this->rdbuf() )
        _RWSTDGuard guard(this->rdbuf()->buffer_mutex_);
#endif
      if(this->rdbuf()) 
      {  
        if(this->rdbuf()->pubsync() == -1)
          err = ios_base::badbit;  
        else
        {
          if ( this->rdstate() & ios_base::eofbit )
            clear( this->rdstate() & ~(ios_base::eofbit | ios_base::failbit));
          return 0;
        } 
      }

#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 -1;
  }

  // string extractor and getline

#ifndef _RWSTD_NO_NAMESPACE
}
namespace __rwstd {
#endif

  template <class streamT, class stringT, class traits>
  streamT& _RWSTDExportTemplate rw_extract_string(streamT& is, stringT& s, traits)
  {
    _TYPENAME streamT::int_type c;
    _RW_STD::ios_base::iostate err = 0;

#ifndef _RWSTD_NO_EXCEPTIONS
    try {
#endif  
      _TYPENAME streamT::sentry ipfx(is);

      if(ipfx)
      { 
        s.erase();
        c = is.rdbuf()->sbumpc();

        const _RW_STD::ctype<_TYPENAME streamT::char_type>& ctype_facet =
#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
        _RW_STD::use_facet<_RW_STD::ctype<_TYPENAME streamT::char_type> >(is.getloc());
#else
        _RW_STD::use_facet(is.getloc(),(_RW_STD::ctype<_TYPENAME streamT::char_type>*)0);
#endif //  _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE

        _TYPENAME stringT::size_type i = 0, len = 32;
        _TYPENAME stringT::value_type* buff = new _TYPENAME stringT::value_type[len+1];
        _TYPENAME stringT::value_type* ptr = buff;

        _TYPENAME stringT::size_type end = s.max_size();
        if (is.width())
          end = (end >  (_TYPENAME stringT::size_type)is.width()) ? is.width() : end;

        while ( !traits::eq_int_type(c,traits::eof()) &&  !ctype_facet.is(ctype_facet.space,c) )
        {
          if (i == len)
          {
            _TYPENAME stringT::size_type oldlen = len;             
            len *= 2;
            _TYPENAME stringT::value_type* tmp = new _TYPENAME stringT::value_type[len+1];
            traits::move(tmp,buff,oldlen);
            delete [] buff;
            buff = tmp;
            ptr = buff + i;
          }

          *ptr++ = traits::to_char_type(c);            
          i++;
          if ( i == end ) break;
          c = is.rdbuf()->sbumpc();
        }
        *ptr = traits::to_char_type(0);
        s.assign(buff,i);
        delete [] buff;

        if ( i == 0 ) err |= _RW_STD::ios_base::failbit;
        if ( traits::eq_int_type(c,traits::eof()) ) 
          err |= _RW_STD::ios_base::eofbit;

      }

      is.width(0);
#ifndef _RWSTD_NO_EXCEPTIONS
    } // end of try block
#endif

#ifndef _RWSTD_NO_EXCEPTIONS
    catch(...)
    {
      bool flag = false;
      try {
        is.setstate(_RW_STD::ios_base::badbit);
      }
      catch( _RW_STD::ios_base::failure ) { flag= true; }
      if ( flag ) throw;
    }
#endif

    if ( err ) is.setstate(err);
    return is;
  }


#ifndef _RWSTD_NO_NAMESPACE
}
namespace std {
#endif

  template<class charT, class traits, class Allocator>
  basic_istream<charT,traits>&
  _RWSTDExportTemplate getline (basic_istream<charT,traits>& is,
                        basic_string<charT,traits,Allocator>& str,
                        charT delim )
  {
    _TYPENAME traits::int_type c;
    ios_base::iostate err = 0;

#ifndef _RWSTD_NO_EXCEPTIONS
    try {
#endif  
      _TYPENAME basic_istream<charT,traits>::sentry ipfx(is,1);

      if(ipfx)
      { 
        c = is.rdbuf()->sbumpc();
        _TYPENAME Allocator::size_type i = 0, len = 32;

        charT* buff = new charT[len+1];
        charT* ptr =  buff;

        while ( !traits::eq_int_type(c,traits::eof()) )
        {
          if (i == len)
          {
            _TYPENAME Allocator::size_type oldlen = len;             
            len *= 2;
            charT* tmp = new charT[len+1];
            traits::move(tmp,buff,oldlen);
            delete [] buff;
            buff = tmp;
            ptr = buff + i;
          }
          if ( traits::eq(traits::to_char_type(c),delim) )
            break;
          i++;
          if (i == str.max_size())
          {
            err |= ios_base::failbit;
            break;
          }
          *ptr++ = traits::to_char_type(c);
          c = is.rdbuf()->sbumpc();
        }
        *ptr = traits::to_char_type(0);
        str.assign(buff,i);
        delete [] buff;

        if ( traits::eq_int_type(c,traits::eof()) )
          err |= ios_base::eofbit;

        if ( i==0 )
          err |= ios_base::failbit;

      }
#ifndef _RWSTD_NO_EXCEPTIONS
    } // end of try block
#endif

#ifndef _RWSTD_NO_EXCEPTIONS
    catch(...)
    {
      bool flag = false;
      try {
        is.setstate(ios_base::badbit);
      }
      catch( ios_base::failure ) { flag= true; }
      if ( flag ) throw;
    }
#endif
    if ( err ) is.setstate(err);
    return is;
  }  


  /*
   * class basic_iostream
   */

  /*
   * basic_iostream(basic_streambuf *)
   */

  template<class charT, class traits>
  basic_iostream<charT, traits>::
  basic_iostream(basic_streambuf<charT, traits> *sb)
  :basic_istream<charT, traits>(sb)
  ,basic_ostream<charT, traits>(sb)
  {
  }

  /*
   * basic_iostream( )
   */

  template<class charT, class traits>
  basic_iostream<charT, traits>::
  basic_iostream( )
  :basic_istream<charT, traits>()
  ,basic_ostream<charT, traits>()
  {
  }


  /*
   * ~basic_iostream()
   */

  template<class charT, class traits>
  basic_iostream<charT, traits>::
  ~basic_iostream()
  {
  }

#ifndef _RWSTD_NO_NAMESPACE
}
#endif

#endif // __STD_RW_ISTREAM_CC__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -