Annotation of mstools/h/ios.h, revision 1.1

1.1     ! root        1: /***
        !             2: *ios.h - definitions/declarations for the ios class.
        !             3: *
        !             4: *      Copyright (c) 1990-1992, Microsoft Corporation.  All rights reserved.
        !             5: *
        !             6: *Purpose:
        !             7: *      This file defines the classes, values, macros, and functions
        !             8: *      used by the ios class.
        !             9: *      [AT&T C++]
        !            10: *
        !            11: ****/
        !            12: 
        !            13: #ifndef _INC_IOS
        !            14: #define _INC_IOS
        !            15: 
        !            16: 
        !            17: #ifdef _MT
        !            18: #include <oscalls.h>   // critical section declarations
        !            19: void _mtlockinit(PRTL_CRITICAL_SECTION);
        !            20: void _mtlock(PRTL_CRITICAL_SECTION);
        !            21: void _mtunlock(PRTL_CRITICAL_SECTION);
        !            22: #endif
        !            23: 
        !            24: #ifndef NULL
        !            25: #define NULL   0
        !            26: #endif
        !            27: 
        !            28: #ifndef EOF
        !            29: #define EOF    (-1)
        !            30: #endif
        !            31: 
        !            32: // Force word packing to avoid possible -Zp override
        !            33: #pragma pack(4)
        !            34: 
        !            35: #pragma warning(disable:4505)          // disable unwanted /W4 warning
        !            36: // #pragma warning(default:4505)       // use this to reenable, if necessary
        !            37: 
        !            38: class streambuf;
        !            39: class ostream;
        !            40: 
        !            41: class ios {
        !            42: 
        !            43: public:
        !            44:     enum io_state {  goodbit = 0x00,
        !            45:                     eofbit  = 0x01,
        !            46:                     failbit = 0x02,
        !            47:                     badbit  = 0x04 };
        !            48: 
        !            49:     enum open_mode { in        = 0x01,
        !            50:                     out       = 0x02,
        !            51:                     ate       = 0x04,
        !            52:                     app       = 0x08,
        !            53:                     trunc     = 0x10,
        !            54:                     nocreate  = 0x20,
        !            55:                     noreplace = 0x40,
        !            56:                     binary    = 0x80 };        // CONSIDER: not in latest spec.
        !            57: 
        !            58:     enum seek_dir { beg=0, cur=1, end=2 };
        !            59: 
        !            60:     enum {  skipws     = 0x0001,
        !            61:            left       = 0x0002,
        !            62:            right      = 0x0004,
        !            63:            internal   = 0x0008,
        !            64:            dec        = 0x0010,
        !            65:            oct        = 0x0020,
        !            66:            hex        = 0x0040,
        !            67:            showbase   = 0x0080,
        !            68:            showpoint  = 0x0100,
        !            69:            uppercase  = 0x0200,
        !            70:            showpos    = 0x0400,
        !            71:            scientific = 0x0800,
        !            72:            fixed      = 0x1000,
        !            73:            unitbuf    = 0x2000,
        !            74:            stdio      = 0x4000
        !            75:                                 };
        !            76: 
        !            77:     static const long basefield;       // dec | oct | hex
        !            78:     static const long adjustfield;     // left | right | internal
        !            79:     static const long floatfield;      // scientific | fixed
        !            80: 
        !            81:     ios(streambuf*);                   // differs from ANSI
        !            82:     virtual ~ios();
        !            83: 
        !            84:     inline long flags() const;
        !            85:     inline long flags(long _l);
        !            86: 
        !            87:     inline long setf(long _f,long _m);
        !            88:     inline long setf(long _l);
        !            89:     inline long unsetf(long _l);
        !            90: 
        !            91:     inline int width() const;
        !            92:     inline int width(int _i);
        !            93: 
        !            94:     inline ostream* tie(ostream* _os);
        !            95:     inline ostream* tie() const;
        !            96: 
        !            97:     inline char fill() const;
        !            98:     inline char fill(char _c);
        !            99: 
        !           100:     inline int precision(int _i);
        !           101:     inline int precision() const;
        !           102: 
        !           103:     inline int rdstate() const;
        !           104:     inline void clear(int _i = 0);
        !           105: 
        !           106: //  inline operator void*() const;
        !           107:     operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
        !           108:     inline int operator!() const;
        !           109: 
        !           110:     inline int  good() const;
        !           111:     inline int  eof() const;
        !           112:     inline int  fail() const;
        !           113:     inline int  bad() const;
        !           114: 
        !           115:     inline streambuf* rdbuf() const;
        !           116: 
        !           117:     inline long & iword(int) const;
        !           118:     inline void * & pword(int) const;
        !           119: 
        !           120:     static long bitalloc();
        !           121:     static int xalloc();
        !           122:     static void sync_with_stdio();
        !           123: 
        !           124: #ifdef _MT
        !           125:     inline void setlock();
        !           126:     inline void clrlock();
        !           127:     void lock() { if (LockFlg<0) _mtlock(lockptr()); };
        !           128:     void unlock() { if (LockFlg<0) _mtunlock(lockptr()); }
        !           129:     inline void lockbuf();
        !           130:     inline void unlockbuf();
        !           131: #else
        !           132:     void lock() { }
        !           133:     void unlock() { }
        !           134:     void lockbuf() { }
        !           135:     void unlockbuf() { }
        !           136: #endif
        !           137: 
        !           138: protected:
        !           139:     ios();
        !           140:     ios(const ios&);                   // treat as private
        !           141:     ios& operator=(const ios&);
        !           142:     void init(streambuf*);
        !           143: 
        !           144:     enum { skipping, tied };
        !           145:     streambuf* bp;
        !           146: 
        !           147:     int     state;
        !           148:     int     ispecial;                  // not used
        !           149:     int     ospecial;                  // not used
        !           150:     int     isfx_special;              // not used
        !           151:     int     osfx_special;              // not used
        !           152:     int     x_delbuf;                  // if set, rdbuf() deleted by ~ios
        !           153: 
        !           154:     ostream* x_tie;
        !           155:     long    x_flags;
        !           156:     int     x_precision;
        !           157:     char    x_fill;
        !           158:     int     x_width;
        !           159: 
        !           160:     static void (*stdioflush)();       // not used
        !           161: 
        !           162: #ifdef _MT
        !           163:     static void lockc() { _mtlock(& x_lockc); }
        !           164:     static void unlockc() { _mtunlock( & x_lockc); }
        !           165:     PRTL_CRITICAL_SECTION lockptr() { return & x_lock; }
        !           166: #else
        !           167:     static void lockc() { }
        !           168:     static void unlockc() { }
        !           169: #endif
        !           170: 
        !           171: public:
        !           172:     int        delbuf() const { return x_delbuf; }
        !           173:     void    delbuf(int _i) { x_delbuf = _i; }
        !           174: 
        !           175: private:
        !           176:     static long x_maxbit;
        !           177:     static int x_curindex;
        !           178: // consider: make interal static to ios::sync_with_stdio()
        !           179:     static int sunk_with_stdio;                // make sure sync_with done only once
        !           180: #ifdef _MT
        !           181: #define MAXINDEX 7
        !           182:     static long x_statebuf[MAXINDEX+1];  // used by xalloc()
        !           183:     static int fLockcInit;             // used to see if x_lockc initialized
        !           184:     static RTL_CRITICAL_SECTION x_lockc; // used to lock static (class) data members
        !           185: // consider: make pointer and allocate elsewhere
        !           186:     int LockFlg;                       // enable locking flag
        !           187:     RTL_CRITICAL_SECTION x_lock;       // used for multi-thread lock on object
        !           188: #else
        !           189:     static long * x_statebuf;  // used by xalloc()
        !           190: #endif
        !           191: };
        !           192: 
        !           193: #include <streamb.h>
        !           194: 
        !           195: inline ios& dec(ios& _strm) { _strm.setf(ios::dec,ios::basefield); return _strm; }
        !           196: inline ios& hex(ios& _strm) { _strm.setf(ios::hex,ios::basefield); return _strm; }
        !           197: inline ios& oct(ios& _strm) { _strm.setf(ios::oct,ios::basefield); return _strm; }
        !           198: 
        !           199: inline long ios::flags() const { return x_flags; }
        !           200: inline long ios::flags(long _l){ long _lO; _lO = x_flags; x_flags = _l; return _lO; }
        !           201: 
        !           202: inline long ios::setf(long _l,long _m){ long _lO; lock(); _lO = x_flags; x_flags = (_l&_m) | (x_flags&(~_m)); unlock(); return _lO; }
        !           203: inline long ios::setf(long _l){ long _lO; lock(); _lO = x_flags; x_flags |= _l; unlock(); return _lO; }
        !           204: inline long ios::unsetf(long _l){ long _lO; lock(); _lO = x_flags; x_flags &= (~_l); unlock(); return _lO; }
        !           205: 
        !           206: inline int ios::width() const { return x_width; }
        !           207: inline int ios::width(int _i){ int _iO; _iO = (int)x_width; x_width = _i; return _iO; }
        !           208: 
        !           209: inline ostream* ios::tie(ostream* _os){ ostream* _osO; _osO = x_tie; x_tie = _os; return _osO; }
        !           210: inline ostream* ios::tie() const { return x_tie; }
        !           211: inline char ios::fill() const { return x_fill; }
        !           212: inline char ios::fill(char _c){ char _cO; _cO = x_fill; x_fill = _c; return _cO; }
        !           213: inline int ios::precision(int _i){ int _iO; _iO = (int)x_precision; x_precision = _i; return _iO; }
        !           214: inline int ios::precision() const { return x_precision; }
        !           215: 
        !           216: inline int ios::rdstate() const { return state; }
        !           217: 
        !           218: // inline ios::operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
        !           219: inline int ios::operator!() const { return state&(badbit|failbit); }
        !           220: 
        !           221: inline int  ios::bad() const { return state & badbit; }
        !           222: // consider: are locks needed on clear() ?
        !           223: inline void ios::clear(int _i){ lock(); state = _i; unlock(); }
        !           224: inline int  ios::eof() const { return state & eofbit; }
        !           225: inline int  ios::fail() const { return state & (badbit | failbit); }
        !           226: inline int  ios::good() const { return state == 0; }
        !           227: 
        !           228: inline streambuf* ios::rdbuf() const { return bp; }
        !           229: 
        !           230: inline long & ios::iword(int _i) const { return x_statebuf[_i] ; }
        !           231: inline void * & ios::pword(int _i) const { return (void * &)x_statebuf[_i]; }
        !           232: 
        !           233: #ifdef _MT
        !           234:     inline void ios::setlock() { LockFlg--; if (bp) bp->setlock(); }
        !           235:     inline void ios::clrlock() { if (LockFlg <= 0) LockFlg++; if (bp) bp->clrlock(); }
        !           236:     inline void ios::lockbuf() { bp->lock(); }
        !           237:     inline void ios::unlockbuf() { bp->unlock(); }
        !           238: #endif
        !           239: 
        !           240: // Restore default packing
        !           241: #pragma pack()
        !           242: 
        !           243: #endif         // !_INC_IOS

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.