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