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