
------------- Listing 1: The header <ios> ---------------------

// ios standard header
#ifndef _IOS_
#define _IOS_
#include <exception>
class ostream;
class streambuf;
        // class ios
class ios {
public:
            // class failure
    class failure : public xmsg {
    public:
        failure(const char *_X = 0, const char *_Y = 0,
            const char *_Z = 0);
            : xmsg(_X, _Y, _Z) {};
        virtual ~failure();
    };
    enum _Fmtflags {skipws = 0x0001, unitbuf = 0x0002,
        uppercase = 0x0004, showbase = 0x0008,
        showpoint = 0x0010, showpos = 0x0020,
        left = 0x0040, right = 0x0080, internal = 0x0100,
        dec = 0x0200, oct = 0x0400, hex = 0x0800,
        scientific = 0x1000, fixed = 0x2000,
        adjustfield = 0x01c0, basefield = 0x0e00,
        floatfield = 0x3000, _Fmtmask = 0x3fff, _Fmtzero = 0};
    enum _Iostate {goodbit = 0x0, eofbit = 0x1,
        failbit = 0x2, badbit = 0x4, _Statmask = 0x7};
    enum _Openmode {in = 0x01, out = 0x02, ate = 0x04,
        app = 0x08, trunc = 0x10, binary = 0x20};
    enum seekdir {beg = 0, cur = 1, end = 2};
    _BITMASK(_Fmtflags, fmtflags);
    _BITMASK(_Iostate, iostate);
    _BITMASK(_Openmode, openmode);
    typedef int io_state, open_mode, seek_dir;
            // class Init
    class Init {
    public:
        Init();
        ~Init();
    private:
        static int _Init_cnt;
        };
            // class _Iosarray
    class _Iosarray {
    public:
        _Iosarray(int _Idx, _Iosarray *_Link = 0)
            : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0) {}
        _Iosarray *_Next;
        int _Index;
        long _Lo;
        void *_Vp;
        };
    ios(streambuf *_S)
        {init(_S); }
    virtual ~ios();
    operator void *() const
        {return (void *)(!*this ? 0 : this); }
    _Bool operator!() const
        {return ((_State & (failbit|badbit)) != 0); }
    ios& copyfmt(const ios&);
    ostream *tie() const
        {return (_Tiestr); }
    ostream *tie(ostream *);
    streambuf *rdbuf() const
        {return (_Sb); }
    streambuf *rdbuf(streambuf *);
    iostate rdstate() const
        {return (_State); }
    void clear(iostate = goodbit);
    void setstate(iostate _St)
        {clear(_State | _St); }
    _Bool good() const
        {return (_State == goodbit); }
    _Bool eof() const
        {return (_State & eofbit); }
    _Bool fail() const
        {return (_State & (badbit | failbit)); }
    _Bool bad() const
        {return (_State & badbit); }
    iostate exceptions() const
        {return (_Except); }
    void exceptions(iostate);
    fmtflags flags() const
        {return (_Fmtfl); }
    fmtflags flags(fmtflags);
    fmtflags setf(fmtflags);
    fmtflags setf(fmtflags, fmtflags);
    void unsetf(fmtflags);
    int fill() const
        {return (_Fillch); }
    int fill(int);
    int precision() const
        {return (_Prec); }
    int precision(int);
    int width() const
        {return (_Wide); }
    int width(int);
    static int xalloc()
        {return (_Index++); }
    long& iword(int _Idx)
        {return (_Findarr(_Idx)._Lo); }
    void *& pword(int _Idx)
        {return (_Findarr(_Idx)._Vp); }
#if _HAS_ENUM_OVERLOADING
    void clear(io_state _St = 0)
        {clear((iostate)_St); }
    void setstate(io_state _St)
        {setstate((iostate)_St); }
    void exceptions(io_state _St)
        {exceptions(iostate)_St); }
#endif
protected:
    ios()
        {init(0); }
    ios(_Uninitialized)
        {}
    ios(const ios&);
    ios& operator=(const ios&);
    void init(streambuf *);
private:
    streambuf *_Sb;
    ostream *_Tiestr;
    iostate _State, _Except;
    fmtflags _Fmtfl;
    int _Prec, _Wide;
    char _Fillch;
    static int _Index;
    _Iosarray *_Arr;
    _Iosarray& _Findarr(int);
    void _Tidy();
    };
        // manipulators
ios& dec(ios&);
ios& fixed(ios&);
ios& hex(ios&);
ios& internal(ios&);
ios& left(ios&);
ios& noshowbase(ios&);
ios& noshowpoint(ios&);
ios& noshowpos(ios&);
ios& noskipws(ios&);
ios& nouppercase(ios&);
ios& oct(ios&);
ios& right(ios&);
ios& scientific(ios&);
ios& showbase(ios&);
ios& showpoint(ios&);
ios& showpos(ios&);
ios& skipws(ios&);
ios& uppercase(ios&);
#endif


