Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C++ Class Library Definition - /* iostream.h -- basic stream i/o declarations http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
/* iostream.h -- basic stream I/O declarations

    Copyright (c) 1990 by Borland International
    All rights reserved.

    There are some inline functions here which generate a LOT of code
    (as much as 300 bytes), but are available inline because AT&T did
    it that way.  We have also made them true functions in the library
    and conditionally deleted the inline code from this header.

    If you really want these big functions to be inline, #define the
    macro name _BIG_INLINE_ before including this header.

    Programs will compile and link correctly even if some modules are
    compiled with _BIG_INLINE_ and some are not.
*/

#ifndef __IOSTREAM_H
#define __IOSTREAM_H

#include <mem.h>    // to get memcpy and NULL

#if __STDC__
#define _Cdecl
#else
#define _Cdecl  cdecl
#endif

// Definition of EOF must match the one in <stdio.h>
#define EOF (-1)

// extract a char from int i, ensuring that zapeof(EOF) != EOF
#define zapeof(i) ((unsigned char)(i))

typedef long streampos;
typedef long streamoff;

class streambuf;
class ostream;


class ios {
public:
        // stream status bits
    enum io_state   {
                goodbit  = 0x00,    // no bit set: all is ok
                eofbit   = 0x01,    // at end of file
                failbit  = 0x02,    // last I/O operation failed
                badbit   = 0x04,    // invalid operation attempted
                hardfail = 0x80     // unrecoverable error
        };

        // stream operation mode
    enum open_mode  {
                in   = 0x01,        // open for reading
                out  = 0x02,        // open for writing
                ate  = 0x04,        // seek to eof upon original open
                app  = 0x08,        // append mode: all additions at eof
                trunc    = 0x10,    // truncate file if already exists
                nocreate = 0x20,    // open fails if file doesn't exist
                noreplace= 0x40,    // open fails if file already exists
                binary   = 0x80     // binary (not text) file
        };



        // stream seek direction
    enum seek_dir { beg=0, cur=1, end=2 };

        // formatting flags
    enum    {
                skipws    = 0x0001, // skip whitespace on input
                left      = 0x0002, // left-adjust output
                right     = 0x0004, // right-adjust output
                internal  = 0x0008, // padding after sign or base indicator
                dec   = 0x0010,     // decimal conversion
                oct   = 0x0020,     // octal conversion
                hex   = 0x0040,     // hexidecimal conversion
                showbase  = 0x0080, // use base indicator on output
                showpoint = 0x0100, // force decimal point (floating output)
                uppercase = 0x0200, // upper-case hex output
                showpos   = 0x0400, // add '+' to positive integers
                scientific= 0x0800, // use 1.2345E2 floating notation
                fixed     = 0x1000, // use 123.45 floating notation
                unitbuf   = 0x2000, // flush all streams after insertion
                stdio     = 0x4000  // flush stdout, stderr after insertion
        };

        // constants for second parameter of seft()
static  const long basefield;       // dec | oct | hex
static  const long adjustfield;     // left | right | internal
static  const long floatfield;      // scientific | fixed

        // constructor, destructor
        _Cdecl ios(streambuf*);
virtual _Cdecl ~ios();

        // for reading/setting/clearing format flags
    long    _Cdecl flags();
    long    _Cdecl flags(long);
    long    _Cdecl setf(long _setbits, long _field);
    long    _Cdecl setf(long);
    long    _Cdecl unsetf(long);

        // reading/setting field width
    int     _Cdecl width();
    int     _Cdecl width(int);

        // reading/setting padding character
    char    _Cdecl fill();
    char    _Cdecl fill(char);

        // reading/setting digits of floating precision
    int     _Cdecl precision(int);
    int     _Cdecl precision();

        // reading/setting ostream tied to this stream
    ostream* _Cdecl tie(ostream*);
    ostream* _Cdecl tie();

        // find out about current stream state
        int     _Cdecl rdstate();       // return the stream state
        int     _Cdecl eof();           // non-zero on end of file
        int     _Cdecl fail();          // non-zero if an operation failed
        int     _Cdecl bad();           // non-zero if error occurred
        int     _Cdecl good();          // non-zero if no state bits set
        void    _Cdecl clear(int = 0);  // set the stream state
                        _Cdecl operator void* ();   // zero if state failed
        int     _Cdecl operator! ();    // non-zero if state failed



        streambuf* _Cdecl rdbuf();      // get the assigned streambuf

        // for declaring additional flag bits and user words
static long _Cdecl bitalloc();  // acquire a new flag bit, value returned
static int  _Cdecl xalloc();    // acquire a new user word, index returned
        long  & _Cdecl iword(int);  // return the nth user word as an int
        void* & _Cdecl pword(int);  // return the nth user word as a pointer

static void _Cdecl sync_with_stdio();

        // obsolete, for streams 1.2 compatibility
    int     _Cdecl skip(int);

protected:
        // additional state flags for ispecial and ospecial
    enum { skipping = 0x100, tied = 0x200 };

        streambuf* bp;          // the associated streambuf
        ostream* x_tie;         // the tied ostream, if any
        int     state;          // status bits
        int     ispecial;       // istream status bits  ***
        int     ospecial;       // ostream status bits  ***
        long    x_flags;        // formatting flag bits
        int     x_precision;    // floating-point precision on output
        int     x_width;        // field width on output
        int     x_fill;         // padding character on output
        int     isfx_special;   // unused       ***
        int     osfx_special;   // unused       ***
        int     delbuf;         // unused       ***
        int     assign_private; // unused       ***
/*
 * The data members marked with *** above are not documented in the AT&T
 * release of streams, so we cannot guarantee compatibility with any
 * other streams release in the use or values of these data members.
 * If you can document any expected behavior of these data members, we
 * will try to adjust our implementation accordingly.
 */

                        _Cdecl ios();       // null constructor, does not initialize

        void    _Cdecl init(streambuf*);    // the actual initialization

        void    _Cdecl setstate(int);       // set all status bits

static  void _Cdecl (*stdioflush)();

private:
        // for extra flag bits and user words
static  long    nextbit;
static  int usercount;
    union ios_user_union *userwords;
    int     nwords;
    void    _Cdecl usersize(int);

        // these declarations prevent automatic copying of an ios
                        _Cdecl ios(ios&);           // declared but not defined
        void    _Cdecl operator= (ios&);    // declared but not defined

};
inline streambuf* _Cdecl ios::rdbuf() { return bp; }
inline ostream* _Cdecl ios::tie() { return x_tie; }
inline char     _Cdecl ios::fill() { return x_fill; }
inline int      _Cdecl ios::precision() { return x_precision; }
inline int      _Cdecl ios::rdstate() { return state; }


inline int      _Cdecl ios::eof() { return state & eofbit; }
inline int      _Cdecl ios::fail() {return state&(failbit|badbit|hardfail);}
inline int      _Cdecl ios::bad() { return state & (badbit | hardfail); }
inline int      _Cdecl ios::good() { return state == 0; }
inline long     _Cdecl ios::flags() { return x_flags; }
inline int      _Cdecl ios::width() { return x_width; }
inline int      _Cdecl ios::width(int _w) { int _i = x_width; x_width = _w;
                                                                return _i; }
inline char     _Cdecl ios::fill(char _c) { char _x = x_fill; x_fill = _c;
                                                                return _x; }
inline int      _Cdecl ios::precision(int _p) {
                        int _x = x_precision; x_precision = _p; return _x;
                        }
inline          _Cdecl ios::operator void* () { return fail() ? 0 : this; }
inline int      _Cdecl ios::operator! () { return fail(); }

See Also: iostream.h (2)

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson