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

1.1     ! root        1: /***
        !             2: *streamb.h - definitions/declarations for the streambuf 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 streambuf class.
        !             9: *      [AT&T C++]
        !            10: *
        !            11: ****/
        !            12: 
        !            13: #ifndef _INC_STREAMB
        !            14: #define _INC_STREAMB
        !            15: 
        !            16: 
        !            17: #include <ios.h>               // need ios::seek_dir definition
        !            18: #ifdef _MT
        !            19: #include <oscalls.h>   // required for Multi-thread declarations
        !            20: void _mtlockinit(PRTL_CRITICAL_SECTION);
        !            21: void _mtlock(PRTL_CRITICAL_SECTION);
        !            22: void _mtunlock(PRTL_CRITICAL_SECTION);
        !            23: #endif
        !            24: 
        !            25: #ifndef NULL
        !            26: #define NULL   0
        !            27: #endif
        !            28: 
        !            29: #ifndef EOF
        !            30: #define EOF    (-1)
        !            31: #endif
        !            32: 
        !            33: // Force word packing to avoid possible -Zp override
        !            34: #pragma pack(4)
        !            35: 
        !            36: #pragma warning(disable:4505)          // disable unwanted /W4 warning
        !            37: // #pragma warning(default:4505)       // use this to reenable, if necessary
        !            38: 
        !            39: typedef long streampos, streamoff;
        !            40: 
        !            41: class ios;
        !            42: 
        !            43: class streambuf {
        !            44: public:
        !            45: 
        !            46:     virtual ~streambuf();
        !            47: 
        !            48:     inline int in_avail() const;
        !            49:     inline int out_waiting() const;
        !            50:     int sgetc();
        !            51:     int snextc();
        !            52:     int sbumpc();
        !            53:     void stossc();
        !            54: 
        !            55:     inline int sputbackc(char);
        !            56: 
        !            57:     inline int sputc(int);
        !            58:     inline int sputn(const char *,int);
        !            59:     inline int sgetn(char *,int);
        !            60: 
        !            61:     virtual int sync();
        !            62: 
        !            63: //  enum seek_dir { beg=0, cur=1, end=2 };  // CONSIDER: needed ???
        !            64: 
        !            65:     virtual streambuf* setbuf(char *, int);
        !            66:     virtual streampos seekoff(streamoff,ios::seek_dir,int =ios::in|ios::out);
        !            67:     virtual streampos seekpos(streampos,int =ios::in|ios::out);
        !            68: 
        !            69:     virtual int xsputn(const char *,int);
        !            70:     virtual int xsgetn(char *,int);
        !            71: 
        !            72:     virtual int overflow(int =EOF) = 0;        // pure virtual function
        !            73:     virtual int underflow() = 0;       // pure virtual function
        !            74: 
        !            75:     virtual int pbackfail(int);
        !            76: 
        !            77:     void dbp();
        !            78: 
        !            79: #ifdef _MT
        !            80:     void setlock() { LockFlg--; }      // <0 indicates lock required;
        !            81:     void clrlock() { if (LockFlg <= 0) LockFlg++; }
        !            82:     void lock() { if (LockFlg<0) _mtlock(lockptr()); };
        !            83:     void unlock() { if (LockFlg<0) _mtunlock(lockptr()); }
        !            84: #else
        !            85:     void lock() { }
        !            86:     void unlock() { }
        !            87: #endif
        !            88: 
        !            89: protected:
        !            90:     streambuf();
        !            91:     streambuf(char *,int);
        !            92: 
        !            93:     inline char * base() const;
        !            94:     inline char * ebuf() const;
        !            95:     inline char * pbase() const;
        !            96:     inline char * pptr() const;
        !            97:     inline char * epptr() const;
        !            98:     inline char * eback() const;
        !            99:     inline char * gptr() const;
        !           100:     inline char * egptr() const;
        !           101:     inline int blen() const;
        !           102:     inline void setp(char *,char *);
        !           103:     inline void setg(char *,char *,char *);
        !           104:     inline void pbump(int);
        !           105:     inline void gbump(int);
        !           106: 
        !           107:     void setb(char *,char *,int =0);
        !           108:     inline int unbuffered() const;
        !           109:     inline void unbuffered(int);
        !           110:     int allocate();
        !           111:     virtual int doallocate();
        !           112: #ifdef _MT
        !           113:     PRTL_CRITICAL_SECTION lockptr() { return & x_lock; }
        !           114: #endif
        !           115: 
        !           116: private:
        !           117:     int _fAlloc;
        !           118:     int _fUnbuf;
        !           119:     int x_lastc;
        !           120:     char * _base;
        !           121:     char * _ebuf;
        !           122:     char * _pbase;
        !           123:     char * _pptr;
        !           124:     char * _epptr;
        !           125:     char * _eback;
        !           126:     char * _gptr;
        !           127:     char * _egptr;
        !           128: #ifdef _MT
        !           129:     int LockFlg;               // <0 indicates locking required
        !           130:    RTL_CRITICAL_SECTION x_lock;        // lock needed only for multi-thread operation
        !           131: #endif
        !           132: };
        !           133: 
        !           134: inline int streambuf::in_avail() const { return (gptr()<_egptr) ? (_egptr-gptr()) : 0; }
        !           135: inline int streambuf::out_waiting() const { return (_pptr>=_pbase) ? (_pptr-_pbase) : 0; }
        !           136: 
        !           137: inline int streambuf::sputbackc(char _c){ return (_eback<gptr()) ? *(--_gptr)=_c : pbackfail(_c); }
        !           138: 
        !           139: inline int streambuf::sputc(int _i){ return (_pptr<_epptr) ? (unsigned char)(*(_pptr++)=(char)_i) : overflow(_i); }
        !           140: 
        !           141: inline int streambuf::sputn(const char * _str,int _n) { return xsputn(_str, _n); }
        !           142: inline int streambuf::sgetn(char * _str,int _n) { return xsgetn(_str, _n); }
        !           143: 
        !           144: inline char * streambuf::base() const { return _base; }
        !           145: inline char * streambuf::ebuf() const { return _ebuf; }
        !           146: inline int streambuf::blen() const  {return ((_ebuf > _base) ? (_ebuf-_base) : 0); }
        !           147: inline char * streambuf::pbase() const { return _pbase; }
        !           148: inline char * streambuf::pptr() const { return _pptr; }
        !           149: inline char * streambuf::epptr() const { return _epptr; }
        !           150: inline char * streambuf::eback() const { return _eback; }
        !           151: inline char * streambuf::gptr() const { return _gptr; }
        !           152: inline char * streambuf::egptr() const { return _egptr; }
        !           153: inline void streambuf::gbump(int n) { if (_egptr) _gptr += n; }
        !           154: inline void streambuf::pbump(int n) { if (_epptr) _pptr += n; }
        !           155: inline void streambuf::setg(char * eb, char * g, char * eg) {_eback=eb; _gptr=g; _egptr=eg; x_lastc=EOF; }
        !           156: inline void streambuf::setp(char * p, char * ep) {_pptr=_pbase=p; _epptr=ep; }
        !           157: inline int streambuf::unbuffered() const { return _fUnbuf; }
        !           158: inline void streambuf::unbuffered(int fUnbuf) { _fUnbuf = fUnbuf; }
        !           159: 
        !           160: // Restore default packing
        !           161: #pragma pack()
        !           162: 
        !           163: #endif /* !_INC_STREAMB */

unix.superglobalmegacorp.com

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