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

📄 istream

📁 realview22.rar
💻
📖 第 1 页 / 共 2 页
字号:
// -*- C++ -*-
/***************************************************************************
 *
 * istream - Declarations for the Standard Library istreams
 *
 * $Id: istream,v 1.1.1.1 2002/01/10 17:38:29 vkorstan Exp $
 *
 ***************************************************************************
 *
 * Copyright (c) 1994-2001 Rogue Wave Software, Inc.  All Rights Reserved.
 *
 * This computer software is owned by Rogue Wave Software, Inc. and is
 * protected by U.S. copyright laws and other laws and by international
 * treaties.  This computer software is furnished by Rogue Wave Software,
 * Inc. pursuant to a written license agreement and may be used, copied,
 * transmitted, and stored only in accordance with the terms of such
 * license and with the inclusion of the above copyright notice.  This
 * computer software or any other copies thereof may not be provided or
 * otherwise made available to any other person.
 *
 * U.S. Government Restricted Rights.  This computer software is provided
 * with Restricted Rights.  Use, duplication, or disclosure by the
 * Government is subject to restrictions as set forth in subparagraph (c)
 * (1) (ii) of The Rights in Technical Data and Computer Software clause
 * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
 * Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19,
 * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
 * Flatiron Parkway, Boulder, Colorado 80301 USA.
 *
 **************************************************************************/

#ifndef _RWSTD_ISTREAM_INCLUDED
#define _RWSTD_ISTREAM_INCLUDED

#include <iosfwd>

#ifndef _RWSTD_NO_REDUNDANT_DEFINITIONS
#  include <ostream>
#endif   // _RWSTD_NO_REDUNDANT_DEFINITIONS

#include <rw/_iosbase.h>
#include <rw/_numeric.h>
#include <rw/_traits.h>

#include <rw/_defs.h>


_RWSTD_NAMESPACE_BEGIN (__rw)

template <class _CharT, class _Traits, class _NativeType>
basic_istream<_CharT, _Traits>&
__rw_extract (_STD::basic_istream<_CharT, _Traits>&, _NativeType&);

_RWSTD_NAMESPACE_END   // __rw


_RWSTD_NAMESPACE_BEGIN (std)

  
template<class _CharT, class _Traits /* = char_traits<char> */>
class basic_istream: virtual public basic_ios<_CharT, _Traits>
{
public:

    typedef _CharT                                    char_type;
    typedef _Traits                                   traits_type;
    typedef _TYPENAME traits_type::int_type           int_type;
    typedef _TYPENAME traits_type::pos_type           pos_type;
    typedef _TYPENAME traits_type::off_type           off_type;
      
    // 27.6.1.1.1, p1
    _EXPLICIT basic_istream (basic_streambuf<char_type, traits_type> *__sb)
        : _C_chcount (0) {
        this->init (__sb);
    }

    // called from sentry's ctor to prepare stream before input
    basic_istream& _C_ipfx (int __flags);

    // allow access to ios_base::_C_bufmutex()
    class sentry;
    friend class sentry;

    // 27.6.1.1.2
    class sentry: public _RW::__rw_guard
    {
        bool _C_ok;

        sentry (const sentry&);            //   not defined
        sentry& operator= (const sentry&); //   not defined

    public:

        // 27.6.1.1.2, p2 - assumes 0 != __strm.rdbuf ()
        _EXPLICIT sentry (basic_istream &__strm, bool __noskipws = false)
            :  _RW::__rw_guard (__strm._C_bufmutex ()) {
            int __flags = (__strm.flags () & ios_base::skipws && !__noskipws ?
                _C_skipws : 0) | _C_faileof;
                _C_ok = __strm._C_ipfx (__flags).good ();
        }

        // 27.6.1.1.2, p8
        operator bool () const {
            return _C_ok;
        }
    };

    // 27.6.1.2.3, p1
    basic_istream& operator>> (basic_istream& (*__pf)(basic_istream&)) {
        return (*__pf)(*this);
    }

    // 27.6.1.2.3, p2
    basic_istream& operator>>(basic_ios<char_type, traits_type>& (*__pf)
                              (basic_ios<char_type, traits_type>&)) {
        return (*__pf)(*this), *this;
    }

    // 27.6.1.2.3, p4
    basic_istream& operator>> (ios_base& (*__pf)(ios_base&)) {
        return (*__pf)(*this), *this;
    }


    // 27.6.1.2.2 - Arithmetic Extractors

#ifndef _RWSTD_NO_BOOL

    basic_istream& operator>> (bool &__val) {
        return _RW::__rw_extract (*this, __val);
    }

#endif   // _RWSTD_NO_BOOL

    basic_istream& operator>>(short &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(unsigned short &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(int &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(unsigned int &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(long &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(unsigned long &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(float &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(double &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(long double &__val) {
        return _RW::__rw_extract (*this, __val);
    }

#ifdef _RWSTD_LONG_LONG

    basic_istream& operator>>(_RWSTD_LONG_LONG &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    basic_istream& operator>>(unsigned _RWSTD_LONG_LONG &__val) {
        return _RW::__rw_extract (*this, __val);
    }

#endif   // _RWSTD_LONG_LONG

    basic_istream& operator>>(void* &__val) {
        return _RW::__rw_extract (*this, __val);
    }

    // extension
    basic_istream& operator>> (basic_streambuf<char_type, traits_type> &__sb) {
        // call extension
        return get (__sb, traits_type::eof ());
    }

    // 27.6.1.2.3, p13
    basic_istream& operator>>(basic_streambuf<char_type, traits_type> *__sb) {
        return  __sb ? *this >> *__sb
                     : (this->setstate (ios_base::failbit), *this);
    }

    // 27.6.1.3 - Unformatted input functions

    // 27.6.1.3, p3
    int_type get () {
        return sentry (*this, true) ?
              _C_unsafe_get (&_C_chcount, traits_type::eof (),
                             _C_faileof | _C_eatnull)
            : traits_type::eof ();
    }

    // 27.6.1.3, p5
    basic_istream& get (char_type& __ch) {
        return read (&__ch, 1, traits_type::eof (), _C_failnoi | _C_eatnull);
    }

    // 27.6.1.3, p7: extract at most n - 1 chars, delim not extracted
    //               always null-terminate, fail if no char extracted
    basic_istream& get (char_type *__s, streamsize __n, char_type __delim) {
        return read (__s, __n, traits_type::to_int_type (__delim),
                     _C_nullterm | _C_failnoi | _C_eatnull);
    }

    // 27.6.1.3, p9: extract at most n - 1 chars
    //               always null-terminate, fail if no char extracted
    basic_istream& get (char_type *__s, streamsize __n) {
        return get (__s, __n, this->widen ('\n'));
    }

    // extension - first arg is a pointer to disambiguate the overloads
    //             in case both int_type and char_type are the same type
    basic_istream& get (basic_streambuf<char_type, traits_type>*, int_type);

    // 27.6.1.3, p12: extract up to but not including delim or eof
    basic_istream& get (basic_streambuf<char_type, traits_type>& __sb,
                        char_type                                __delim) {
        // using extension
        return get (&__sb, traits_type::to_int_type (__delim));
    }

    // 27.6.1.3, p15
    basic_istream& get (basic_streambuf<char_type, traits_type>& __sb) {
        return get (__sb, this->widen ('\n'));
    }

    // 27.6.1.3, p16: extract at most n - 1, delim extracted but not stored
    //                fail if either 0 or n - 1 are extracted
    basic_istream& getline (char_type *__s, streamsize __n, char_type __delim) {
        // using extension
        return read (__s, __n, traits_type::to_int_type (__delim),
                       _C_nullterm | _C_eatdelim | _C_eatnull
                     | _C_failend | _C_failnoi);
    }

    // 27.6.1.3, p23
    basic_istream& getline (char_type *__s, streamsize __n) {
        return getline (__s, __n, this->widen ('\n'));
    }

    // 27.6.1.3, p24: extract at most n including delim
    basic_istream& ignore (streamsize __n = 1,
                           int_type __delim = traits_type::eof ()) {
        // using extension - passing null pointer to ignore input
        return read (0, __n, __delim, _C_eatdelim | _C_eatnull);
    }

    // extension

⌨️ 快捷键说明

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