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

📄 ios.mh

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 MH
字号:
///////////////////////////////////////////////////////////////////////////
// FILE: ios/ios.h (iostreams base class)
//
:keep CPP_HDR
:include crwat.sp
//
// Description: This header is part of the C++ standard library. It
//              defines the common base class used by the iostreams classes.
///////////////////////////////////////////////////////////////////////////
:segment !CNAME
#ifndef _IOS_H_INCLUDED
#define _IOS_H_INCLUDED

:include readonly.sp

#ifndef _IOS_INCLUDED
  #include <ios>
#endif
using std::streampos;
using std::streamoff;
using std::ios;
using std::dec;
using std::hex;
using std::oct;

#endif
:elsesegment
#ifndef _IOS_INCLUDED
#define _IOS_INCLUDED

:include readonly.sp

#ifndef __cplusplus
#error The header ios requires C++
#endif

#ifndef _COMDEF_H_INCLUDED
 #include <_comdef.h>
#endif

// Define EOF to be the same as that used with C.
#if !defined( EOF )
    #define EOF (-1)
#endif

// __NOT_EOF is useful for those functions that return "something other
// than EOF" to indicate that everything is OK.
#define __NOT_EOF 0

:include watexc.sp

:include cpplock.sp

// This is referred to in class ios, but is defined later, or elsewhere:
class _WPRTLINK __WATCOM_ios;

namespace std {

  // Position in the stream (absolute value, 0 is first byte):
  typedef long streampos;

  // Offset from current position in the stream:
  typedef long streamoff;

  // These are referred to in class ios, but are defined later, or elsewhere:
  class _WPRTLINK istream;
  class _WPRTLINK ostream;
  class _WPRTLINK streambuf;

  // **************************** IOS ****************************************
:include pshpackl.sp
  class _WPRTLINK ios {
  public:
    enum io_state {                   // Error state
        goodbit = 0x00,               // - no errors
        badbit  = 0x01,               // - operation failed, may not proceed
        failbit = 0x02,               // - operation failed, may proceed
        eofbit  = 0x04                // - end of file
    };
    typedef int iostate;
    enum open_mode {                  // How to open a stream
        in        = 0x0001,           // - open for input
        out       = 0x0002,           // - open for output
        atend     = 0x0004,           // - seek to end after opening
        append    = 0x0008,           // - open for output, append to the end
        truncate  = 0x0010,           // - discard contents after opening
        nocreate  = 0x0020,           // - open only an existing file
        noreplace = 0x0040,           // - open only a new file
        text      = 0x0080,           // - open as text file
        binary    = 0x0100,           // - open as binary file

        app       = append,           // Historical purposes
        ate       = atend,
        trunc     = truncate
    };
    typedef int openmode;
    enum seek_dir {                   // Seek direction
        beg       = 0x00,             // - seek from beginning
        cur       = 0x01,             // - seek from current position
        end       = 0x02              // - seek from end
    };
    typedef int seekdir;
    enum fmt_flags {                  // Format flags
        skipws     = 0x0001,          // - skip whitespace
        left       = 0x0002,          // - align field to left edge
        right      = 0x0004,          // - align field to right edge
        internal   = 0x0008,          // - sign at left, value at right
        dec        = 0x0010,          // - decimal conversion for integers
        oct        = 0x0020,          // - octal conversion for integers
        hex        = 0x0040,          // - hexadecimal conversion for integers
        showbase   = 0x0080,          // - show dec/octal/hex base on output
        showpoint  = 0x0100,          // - show decimal and digits on output
        uppercase  = 0x0200,          // - use E,X (not e,x) on output numbers
        showpos    = 0x0400,          // - use + for output positive numbers
        scientific = 0x0800,          // - use scientific notation for output
        fixed      = 0x1000,          // - use floating notation for output
        unitbuf    = 0x2000,          // - flush stream after output
        stdio      = 0x4000,          // - flush stdout/stderr after output

        #define _LAST_FORMAT_FLAG 0x00004000
        #define _LAST_FLAG_BIT    0x80000000

        basefield  = dec | oct | hex,
        adjustfield= left | right | internal,
        floatfield = scientific | fixed,
    };
    typedef long fmtflags;
:segment STRICT_ANSI_C_PLUS_PLUS
    class Init {
    public:
        Init() {};                    // - not required by WATCOM
    };
:endsegment

    class failure : public __WATCOM_exception {
        iostate __cause;
    public:
        failure( iostate );           // - set the cause of failure
        iostate cause() const;        // - query the cause of failure
    };

    ios( streambuf *__sb );
    ios( ios const & );
    virtual ~ios();

    ios &operator = ( ios const & );
        operator void * () const;
    int operator !      () const;

    ostream   *tie( ostream *__ostrm );
    ostream   *tie() const;
    streambuf *rdbuf() const;
    iostate    rdstate() const;
    iostate    clear( iostate __state = 0 );
    int        good() const;
    int        bad()  const;
    int        fail() const;
    int        eof()  const;
    iostate    exceptions( iostate __enable );
    iostate    exceptions() const;
    fmtflags   setf( fmtflags __onbits, fmtflags __mask );
    fmtflags   setf( fmtflags __onbits );
    fmtflags   unsetf( fmtflags __offbits );
    fmtflags   flags( fmtflags __bits );
    fmtflags   flags() const;
    char       fill( char __fillchar );
    char       fill() const;
    int        precision( int __precision );
    int        precision() const;
    int        width( int __width );
    int        width() const;
    long      &iword( int __index );
    void     *&pword( int __index );

    static void sync_with_stdio( void ) {};     // obsolete function

    static fmtflags bitalloc();
    static int      xalloc();

    __lock *__i_lock;        // ios data member operations
    static __lock *__x_lock; // xalloc/bitalloc operations

  protected:
    ios();

    void init( streambuf *__sb );
    void setstate( ios::iostate __orbits );

  private:
    streambuf *__strmbuf;
    ostream   *__tied_stream;
    long       __format_flags;
    int        __error_state;
    int        __enabled_exceptions;
    int        __float_precision;
    int        __field_width;
    void      *__xalloc_list;
    char       __fill_character;

    static int       __xalloc_index;
    static fmtflags  __last_format_flag;

    friend class __WATCOM_ios;
    int : 0;
  };
:include poppack.sp

  inline streambuf *ios::rdbuf() const {
    return( __strmbuf );
  }

  inline ios::iostate ios::rdstate() const {
    return( __error_state );
  }

  inline int ios::good() const {
    return( __error_state == 0 );
  }

  inline int ios::bad() const {
    return( __error_state & ios::badbit );
  }

  inline int ios::fail() const {
    return( __error_state & (ios::failbit|ios::badbit) );
  }

  inline int ios::eof() const {
    return( __error_state & ios::eofbit );
  }

  inline ios::iostate ios::exceptions() const {
    return( __enabled_exceptions );
  }

  inline ios::operator void * () const {
    return( (void *) (fail()==0) );
  }

  inline int ios::operator ! () const {
    return( fail() );
  }

  inline ios::fmtflags ios::setf( ios::fmtflags __onbits ) {
    __lock_it( __i_lock );
    ios::fmtflags __old_flags = __format_flags;
    __format_flags           |= __onbits;
    return( __old_flags );
  }

  inline ios::fmtflags ios::setf( ios::fmtflags __onbits, ios::fmtflags __mask ) {
    __lock_it( __i_lock );
    ios::fmtflags __old_flags = __format_flags;
    __format_flags           &= ~__mask;
    __format_flags           |= __onbits & __mask;
    return( __old_flags );
  }

  inline ios::fmtflags ios::unsetf( ios::fmtflags __offbits ) {
    __lock_it( __i_lock );
    ios::fmtflags __old_flags = __format_flags;
    __format_flags           &= ~__offbits;
    return( __old_flags );
  }

  inline ios::fmtflags ios::flags( ios::fmtflags __flags ) {
    __lock_it( __i_lock );
    ios::fmtflags __old_flags = __format_flags;
    __format_flags            = __flags;
    return( __old_flags );
  }

  inline ios::fmtflags ios::flags() const {
    return( __format_flags );
  }

  inline char ios::fill( char __fillchar ) {
    __lock_it( __i_lock );
    char __old_fill  = __fill_character;
    __fill_character = __fillchar;
    return( __old_fill );
  }

  inline char ios::fill() const {
    return( __fill_character );
  }

  inline int ios::precision( int __precision ) {
    __lock_it( __i_lock );
    int __old_precision = __float_precision;
    __float_precision   = __precision;
    return( __old_precision );
  }

  inline int ios::precision() const {
    return( __float_precision );
  }

  inline int ios::width( int __width ) {
    __lock_it( __i_lock );
    int __old_width = __field_width;
    __field_width   = __width;
    return( __old_width );
  }

  inline int ios::width() const {
    return( __field_width );
  }

  inline ostream *ios::tie( ostream *__ostrm ) {
    __lock_it( __i_lock );
    ostream *__old_tie = __tied_stream;
    __tied_stream      = __ostrm;
    return( __old_tie );
  }

  inline ostream *ios::tie() const {
    return( __tied_stream );
  }

  // **************************** MANIPULATORS *******************************
  _WPRTLINK extern ios &dec( ios & );
  _WPRTLINK extern ios &hex( ios & );
  _WPRTLINK extern ios &oct( ios & );

} // namespace std

#endif
:endsegment

⌨️ 快捷键说明

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