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

📄 ostream

📁 realview22.rar
💻
📖 第 1 页 / 共 2 页
字号:
// -*- C++ -*-
/***************************************************************************
 *
 * ostream - Declarations for the Standard Library ostream classes
 *
 * $Id: ostream,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_OSTREAM_INCLUDED
#define _RWSTD_OSTREAM_INCLUDED

#include <ios>
#include <iosfwd>

#ifndef _RWSTD_NO_REDUNDANT_DEFINITIONS
#  include <rw/_ioiter.h>
#  include <streambuf>
#endif   // _RWSTD_NO_REDUNDANT_DEFINITIONS

#include <rw/_numeric.h>
#include <rw/_defs.h>


_RWSTD_NAMESPACE_BEGIN (__rw)

// helper - implements insertion of arithmetic and pointer types
template <class _CharT, class _Traits, class _NativeType>
_STD::basic_ostream<_CharT, _Traits>&
__rw_insert (_STD::basic_ostream<_CharT, _Traits>&, _NativeType);


// helper - implements insertion of character strigs
template<class _CharT, class _Traits, class _StringT>
_STD::basic_ostream<_CharT, _Traits>&
__rw_insert (_STD::basic_ostream<_CharT, _Traits>&, _StringT*,
             _STD::streamsize, _STD::streamsize);

template<class _CharT, class _Traits, class _StringT>
inline _STD::basic_ostream<_CharT, _Traits>&
__rw_insert (_STD::basic_ostream<_CharT, _Traits> &__strm, const _StringT *__s,
             _STD::streamsize __len, _STD::streamsize __width)
{
    return __rw_insert (__strm, _RWSTD_CONST_CAST (_StringT*, __s),
                        __len, __width);
}

_RWSTD_NAMESPACE_END   // __rw


_RWSTD_NAMESPACE_BEGIN (std)


template<class _CharT, class _Traits>
class basic_ostream: 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;
      
    typedef basic_ios<char_type, traits_type>  ios_type;

    // 27.6.2.2, p1
    _EXPLICIT basic_ostream (basic_streambuf<char_type, traits_type> *__sb) {
        this->init (__sb);
    }

    // implements sentry ctor
    basic_ostream& _C_opfx ();

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

    // 27.6.2.3
    class sentry: public _RW::__rw_guard {
        sentry (const sentry&);            //   not defined
        sentry& operator= (const sentry&); //   not defined

    public:

        _EXPLICIT
        sentry (basic_ostream<char_type, traits_type> &__strm)
            : _RW::__rw_guard (__strm.rdbuf () ? __strm._C_bufmutex () : 0),
              _C_strm (__strm) {
                _C_ok = _C_strm._C_opfx ().good ();
            }

        // 27.6.2.3, p4
        ~sentry () {
            if (   (   _C_strm.flags () & ios_base::unitbuf
                    || _C_strm._C_is_sync ()
                    && _C_strm._C_is_std ())   // [w]cout, [w]cerr, [w]clog
                 && !_UNCAUGHT_EXCEPTION ()
                 && -1 == _C_strm.rdbuf ()->pubsync ()) {

                // prevent exceptions from propagating
                _C_strm.setstate (ios_base::badbit, 0);
            }    
        }

        operator bool () const {
            return _C_ok;
        }

    private:

        basic_ostream& _C_strm;   // stream guarded by sentry
        bool           _C_ok;     // is stream okay?
    };

    // 27.6.2.5 - Formatted output functions

    // 27.6.2.5.3, p1
    basic_ostream& operator<< (basic_ostream& (*__pf)(basic_ostream&)) {
        return (*__pf)(*this);
    }

    // 27.6.2.5.3, p2
    basic_ostream& operator<< (ios_base& (*__pf)(ios_base&)) {
        return (*__pf)(*this), *this;
    }

    // 27.6.2.5.3, p4
    basic_ostream& operator<< (ios_type& (*__pf)(ios_type&)) {
        return (*__pf)(*this), *this;
    }

    // 27.6.2.5.2 - Arithmetic inserters

#ifndef _RWSTD_NO_BOOL

    basic_ostream& operator<<(bool __val) {
        return _RW::__rw_insert (*this, __val);
    }

#endif   // _RWSTD_NO_BOOL

    basic_ostream& operator<< (short __val) {
        return _RW::__rw_insert (*this, __val);
    }

    basic_ostream& operator<< (unsigned short __val) {
        return *this << _RWSTD_STATIC_CAST (unsigned long, __val);
    }

    basic_ostream& operator<< (int __val) {
        return _RW::__rw_insert (*this, __val);
    }

    basic_ostream& operator<< (unsigned int __val) {
        return *this << _RWSTD_STATIC_CAST (unsigned long, __val);
    }

    basic_ostream& operator<< (long __val) {
        return _RW::__rw_insert (*this, __val);
    }

    basic_ostream& operator<< (unsigned long __val) {
        return _RW::__rw_insert (*this, __val);
    }

    basic_ostream& operator<< (float __val) {
        return *this << static_cast<double>(__val);
    }

    basic_ostream& operator<< (double __val) {
        return _RW::__rw_insert (*this, __val);
    }

    basic_ostream& operator<< (long double __val) {
        return _RW::__rw_insert (*this, __val);
    }

#ifdef _RWSTD_LONG_LONG

    // extension
    basic_ostream& operator<< (unsigned _RWSTD_LONG_LONG __val) {
        return _RW::__rw_insert (*this, __val);
    }

    // extension
    basic_ostream& operator<< (_RWSTD_LONG_LONG __val) {
        return _RW::__rw_insert (*this, __val);
    }

#endif   // _RWSTD_LONG_LONG

    basic_ostream& operator<< (const void *__val) {
        return _RW::__rw_insert (*this, __val);
    }

    // extension
    basic_ostream& operator<< (basic_streambuf<char_type, traits_type>&);

    // 27.6.2.6.3, p6
    basic_ostream&
    operator<< (basic_streambuf<char_type, traits_type> *__sb) {
        return __sb ? *this << *__sb
                    : (this->setstate (ios_base::badbit), *this);
    }

    // 27.6.2.6 - Unformatted output functions

    // 27.6.2.6, p2
    basic_ostream& put (char_type __c) {
        return _RW::__rw_insert (*this, &__c, 1, 0 /* width */);
    }

    // 27.6.2.6, p5
    basic_ostream& write (const char_type *__s, streamsize __len) {
#if !defined (_MSC_VER) || (_MSC_VER > 1300)
        // working around yet another of the variety of MSVC bugs
        return _RW::__rw_insert (*this, __s, __len, 0 /* width */);
#else
        return _RW::__rw_insert<char_type, traits_type, char_type>
            (*this, __s, __len, 0 /* width */);
#endif   // !defined (_MSC_VER) || (_MSC_VER > 1300)
    }

    // 27.6.2.6, p7
    basic_ostream& flush ();

    // 27.6.2.4 - Seek members

    // 27.6.2.4, p1
    pos_type tellp ();

    // 27.6.2.4, p2
    basic_ostream& seekp (pos_type);

    // 27.6.2.4, p4
    basic_ostream& seekp (off_type, ios_base::seekdir);

    // is `*this' a [w]cout, [w]cerr?
    bool _C_is_cout () const {
        return false;
    }

    bool _C_is_cerr () const {
        return false;
    }

    // is `*this' one of { [w]cout, [w]cerr, [w]clog }?
    bool _C_is_std () const {
        return false;
    }
    
    // pad output with fill chars, return number of chars written
    streamsize _C_pad (streamsize);
};


#if defined (_MSC_VER) && _MSC_VER <= 1300

// explicit instantiation followed by explicit specialization is illegal
// according to 14.6.4.1, p7 but MSVC allows it (linker errors otherwise)

_RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT
                      basic_ostream<char, char_traits<char> >);

#ifndef _RWSTD_NO_WCHAR_T
_RWSTD_INSTANTIATE_2 (class _RWSTD_EXPORT
                      basic_ostream<wchar_t, char_traits<wchar_t> >);
#endif   // _RWSTD_NO_WCHAR_T

#endif   // defined (_MSC_VER) && _MSC_VER <= 1300

template<class _CharT, class _Traits>
inline streamsize
basic_ostream<_CharT, _Traits>::_C_pad (streamsize __len)
{
    // note that __len can be negative
    for (streamsize __i = 0; __i < __len; ++__i) {
        if (traits_type::eq_int_type (this->rdbuf ()->sputc (this->fill ()), 
                                      traits_type::eof ())) {
            return __i;
        }
    }
    return __len;
}


// avoid having to bring standard iostreams into scope
extern _RWSTD_EXPORT const void* __rw_std_streams[];


_RWSTD_SPECIALIZED_FUNCTION
inline bool
basic_ostream<char, char_traits<char> >::_C_is_cout () const
{
    // upcast to a virtual base necessary
    return _RWSTD_STATIC_CAST (const ios_base*, this) == __rw_std_streams [1];
}


_RWSTD_SPECIALIZED_FUNCTION
inline bool
basic_ostream<char, char_traits<char> >::_C_is_cerr () const
{
    // upcast to a virtual base necessary
    return _RWSTD_STATIC_CAST (const ios_base*, this) == __rw_std_streams [2];
}


_RWSTD_SPECIALIZED_FUNCTION
inline bool
basic_ostream<char, char_traits <char> >::_C_is_std () const
{
    // upcast to a virtual base necessary
    return    _C_is_cout () || _C_is_cerr ()
        || _RWSTD_STATIC_CAST (const ios_base*, this) == __rw_std_streams [3];
}


#ifndef _RWSTD_NO_WCHAR_T

_RWSTD_SPECIALIZED_FUNCTION
inline bool
basic_ostream<wchar_t, char_traits <wchar_t> >::_C_is_cout () const
{
    // upcast to a virtual base necessary
    return _RWSTD_STATIC_CAST (const ios_base*, this) == __rw_std_streams [5];
}


_RWSTD_SPECIALIZED_FUNCTION
inline bool
basic_ostream<wchar_t, char_traits <wchar_t> >::_C_is_cerr () const
{
    // upcast to a virtual base necessary
    return _RWSTD_STATIC_CAST (const ios_base*, this) == __rw_std_streams [6];
}


⌨️ 快捷键说明

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