///////////////////////////////////////////////////////////////////////////
// FILE: ios/ios.h (iostreams base class)
//
// =========================================================================
//
//                          Open Watcom Project
//
//    Copyright (c) 2002-2010 Open Watcom Contributors. All Rights Reserved.
//    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
//
//    This file is automatically generated. Do not edit directly.
//
// =========================================================================
//
// Description: This header is part of the C++ standard library. It
//              defines the common base class used by the iostreams classes.
///////////////////////////////////////////////////////////////////////////
#ifndef _IOS_INCLUDED
#define _IOS_INCLUDED

#ifndef _ENABLE_AUTODEPEND
 #pragma read_only_file;
#endif

#ifndef __cplusplus
 #error This header file 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

#ifndef _WATCOM_EXCEPTION_DEFINED
#define _WATCOM_EXCEPTION_DEFINED
 #define _WATCOM_EXCEPTION_DEFINED_
 struct __WATCOM_exception {
  #if defined(__AXP__) || defined(__PPC__)
     void *__filler;
  #endif
 };
#endif

// For multi-thread support.
#ifndef __lock_it

 class __lock;

 #ifdef __SW_BM
  class _WPRTLINK __get_lock {
  public:
      __get_lock( __lock * );
      ~__get_lock();
  private:
      __lock *__lk;
  };
  #define __lock_it( __l ) __get_lock __lock_name( __LINE__ )( __l )
  #define __lock_name( __ln ) __lock_glue( __lock__, __ln )
  #define __lock_glue( __pre, __lin ) __pre ## __lin
 #else
  #define __lock_it( __l )
 #endif
#endif

// 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 ****************************************
#ifdef _M_IX86
 #pragma pack( __push, 1 )
#else
 #pragma pack( __push, 8 )
#endif
  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;

    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;
  };
#pragma pack( __pop )

  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
