|
|
|
1 |
|
// xiosbase internal header (from <ios>) |
2 |
|
#pragma once |
3 |
|
#ifndef _XIOSBASE_ |
4 |
|
#define _XIOSBASE_ |
5 |
|
#ifndef RC_INVOKED |
6 |
|
#include <xlocale> |
7 |
|
#include <share.h> |
8 |
|
|
9 |
|
#ifdef _MSC_VER |
10 |
|
#pragma pack(push,_CRT_PACKING) |
11 |
|
#pragma warning(push,3) |
12 |
|
#pragma warning(disable:4412) |
13 |
|
#endif /* _MSC_VER */ |
14 |
|
|
15 |
|
_STD_BEGIN |
16 |
|
|
17 |
|
#define _IOSskipws 0x0001 |
18 |
|
#define _IOSunitbuf 0x0002 |
19 |
|
#define _IOSuppercase 0x0004 |
20 |
|
#define _IOSshowbase 0x0008 |
21 |
|
#define _IOSshowpoint 0x0010 |
22 |
|
#define _IOSshowpos 0x0020 |
23 |
|
#define _IOSleft 0x0040 |
24 |
|
#define _IOSright 0x0080 |
25 |
|
#define _IOSinternal 0x0100 |
26 |
|
#define _IOSdec 0x0200 |
27 |
|
#define _IOSoct 0x0400 |
28 |
|
#define _IOShex 0x0800 |
29 |
|
#define _IOSscientific 0x1000 |
30 |
|
#define _IOSfixed 0x2000 |
31 |
|
|
32 |
|
#define _IOShexfloat 0x3000 // added with TR1/ |
33 |
|
|
34 |
|
#define _IOSboolalpha 0x4000 |
35 |
|
#define _IOS_Stdio 0x8000 |
36 |
|
|
37 |
|
#define _IOS_Nocreate 0x40 |
38 |
|
#define _IOS_Noreplace 0x80 |
39 |
|
#define _IOSbinary 0x20 |
40 |
|
|
41 |
|
// TEMPLATE CLASS _Iosb |
42 |
|
template<class _Dummy> |
43 |
|
class _Iosb |
44 |
|
{ // define templatized bitmask/enumerated types, instantiate on demand |
45 |
|
public: |
46 |
|
enum _Dummy_enum {_Dummy_enum_val = 1}; // don't ask |
47 |
|
|
48 |
|
enum _Fmtflags |
49 |
|
{ // constants for formatting options |
50 |
|
_Fmtmask = 0xffff, _Fmtzero = 0}; |
51 |
|
|
52 |
|
static const _Fmtflags skipws = (_Fmtflags)_IOSskipws; |
53 |
|
static const _Fmtflags unitbuf = (_Fmtflags)_IOSunitbuf; |
54 |
|
static const _Fmtflags uppercase = (_Fmtflags)_IOSuppercase; |
55 |
|
static const _Fmtflags showbase = (_Fmtflags)_IOSshowbase; |
56 |
|
static const _Fmtflags showpoint = (_Fmtflags)_IOSshowpoint; |
57 |
|
static const _Fmtflags showpos = (_Fmtflags)_IOSshowpos; |
58 |
|
static const _Fmtflags left = (_Fmtflags)_IOSleft; |
59 |
|
static const _Fmtflags right = (_Fmtflags)_IOSright; |
60 |
|
static const _Fmtflags internal = (_Fmtflags)_IOSinternal; |
61 |
|
static const _Fmtflags dec = (_Fmtflags)_IOSdec; |
62 |
|
static const _Fmtflags oct = (_Fmtflags)_IOSoct; |
63 |
|
static const _Fmtflags hex = (_Fmtflags)_IOShex; |
64 |
|
static const _Fmtflags scientific = (_Fmtflags)_IOSscientific; |
65 |
|
static const _Fmtflags fixed = (_Fmtflags)_IOSfixed; |
66 |
|
|
67 |
|
static const _Fmtflags hexfloat = |
68 |
|
(_Fmtflags)_IOShexfloat; // added with TR1/ |
69 |
|
|
70 |
|
static const _Fmtflags boolalpha = (_Fmtflags)_IOSboolalpha; |
71 |
|
static const _Fmtflags _Stdio = (_Fmtflags)_IOS_Stdio; |
72 |
|
static const _Fmtflags adjustfield = (_Fmtflags)(_IOSleft |
73 |
|
| _IOSright | _IOSinternal); |
74 |
|
static const _Fmtflags basefield = (_Fmtflags)(_IOSdec |
75 |
|
| _IOSoct | _IOShex); |
76 |
|
static const _Fmtflags floatfield = (_Fmtflags)(_IOSscientific |
77 |
|
| _IOSfixed); |
78 |
|
|
79 |
|
enum _Iostate |
80 |
|
{ // constants for stream states |
81 |
|
_Statmask = 0x17}; |
82 |
|
|
83 |
|
static const _Iostate goodbit = (_Iostate)0x0; |
84 |
|
static const _Iostate eofbit = (_Iostate)0x1; |
85 |
|
static const _Iostate failbit = (_Iostate)0x2; |
86 |
|
static const _Iostate badbit = (_Iostate)0x4; |
87 |
|
static const _Iostate _Hardfail = (_Iostate)0x10; |
88 |
|
|
89 |
|
enum _Openmode |
90 |
|
{ // constants for file opening options |
91 |
|
_Openmask = 0xff}; |
92 |
|
|
93 |
|
static const _Openmode in = (_Openmode)0x01; |
94 |
|
static const _Openmode out = (_Openmode)0x02; |
95 |
|
static const _Openmode ate = (_Openmode)0x04; |
96 |
|
static const _Openmode app = (_Openmode)0x08; |
97 |
|
static const _Openmode trunc = (_Openmode)0x10; |
98 |
|
static const _Openmode _Nocreate = (_Openmode)_IOS_Nocreate; |
99 |
|
static const _Openmode _Noreplace = (_Openmode)_IOS_Noreplace; |
100 |
|
static const _Openmode binary = (_Openmode)_IOSbinary; |
101 |
|
|
102 |
|
enum _Seekdir |
103 |
|
{ // constants for file positioning options |
104 |
|
_Seekmask = 0x3}; |
105 |
|
static const _Seekdir beg = (_Seekdir)0; |
106 |
|
static const _Seekdir cur = (_Seekdir)1; |
107 |
|
static const _Seekdir end = (_Seekdir)2; |
108 |
|
|
109 |
|
enum |
110 |
|
{ // constant for default file opening protection |
111 |
|
_Openprot = _SH_DENYNO}; |
112 |
|
}; |
113 |
|
|
114 |
|
template<class _Dummy> |
115 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::skipws; |
116 |
|
template<class _Dummy> |
117 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::unitbuf; |
118 |
|
template<class _Dummy> |
119 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::uppercase; |
120 |
|
template<class _Dummy> |
121 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showbase; |
122 |
|
template<class _Dummy> |
123 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showpoint; |
124 |
|
template<class _Dummy> |
125 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showpos; |
126 |
|
template<class _Dummy> |
127 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::left; |
128 |
|
template<class _Dummy> |
129 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::right; |
130 |
|
template<class _Dummy> |
131 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::internal; |
132 |
|
template<class _Dummy> |
133 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::dec; |
134 |
|
template<class _Dummy> |
135 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::oct; |
136 |
|
template<class _Dummy> |
137 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::hex; |
138 |
|
template<class _Dummy> |
139 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::scientific; |
140 |
|
template<class _Dummy> |
141 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::fixed; |
142 |
|
|
143 |
|
template<class _Dummy> |
144 |
|
const typename _Iosb<_Dummy>::_Fmtflags |
145 |
|
_Iosb<_Dummy>::hexfloat; // added with TR1 |
146 |
|
|
147 |
|
template<class _Dummy> |
148 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::boolalpha; |
149 |
|
template<class _Dummy> |
150 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::_Stdio; |
151 |
|
template<class _Dummy> |
152 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::adjustfield; |
153 |
|
template<class _Dummy> |
154 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::basefield; |
155 |
|
template<class _Dummy> |
156 |
|
const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::floatfield; |
157 |
|
|
158 |
|
template<class _Dummy> |
159 |
|
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::goodbit; |
160 |
|
template<class _Dummy> |
161 |
|
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::eofbit; |
162 |
|
template<class _Dummy> |
163 |
|
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::failbit; |
164 |
|
template<class _Dummy> |
165 |
|
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::badbit; |
166 |
|
template<class _Dummy> |
167 |
|
const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::_Hardfail; |
168 |
|
|
169 |
|
template<class _Dummy> |
170 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::in; |
171 |
|
template<class _Dummy> |
172 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::out; |
173 |
|
template<class _Dummy> |
174 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::ate; |
175 |
|
template<class _Dummy> |
176 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::app; |
177 |
|
template<class _Dummy> |
178 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::trunc; |
179 |
|
template<class _Dummy> |
180 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::_Nocreate; |
181 |
|
template<class _Dummy> |
182 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::_Noreplace; |
183 |
|
template<class _Dummy> |
184 |
|
const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::binary; |
185 |
|
|
186 |
|
template<class _Dummy> |
187 |
|
const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::beg; |
188 |
|
template<class _Dummy> |
189 |
|
const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::cur; |
190 |
|
template<class _Dummy> |
191 |
|
const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::end; |
192 |
|
|
193 |
|
// CLASS ios_base |
194 |
|
class _CRTIMP2_PURE ios_base |
195 |
|
: public _Iosb<int> |
196 |
|
{ // base class for ios |
197 |
|
public: |
198 |
|
_BITMASK(_Fmtflags, fmtflags); |
199 |
|
_BITMASK(_Iostate, iostate); |
200 |
|
_BITMASK(_Openmode, openmode); |
201 |
|
_BITMASK(_Seekdir, seekdir); |
202 |
|
|
203 |
|
typedef std::streamoff streamoff; |
204 |
|
typedef std::streampos streampos; |
205 |
|
|
206 |
|
enum event |
207 |
|
{ // constants for ios events |
208 |
|
erase_event, imbue_event, copyfmt_event}; |
209 |
|
|
210 |
|
typedef void (__CLRCALL_OR_CDECL *event_callback)(event, ios_base&, int); |
211 |
|
typedef unsigned int io_state, open_mode, seek_dir; |
212 |
|
|
213 |
|
// CLASS failure |
214 |
|
class failure |
215 |
|
: public runtime_error |
216 |
|
{ // base of all iostreams exceptions |
217 |
|
public: |
218 |
|
explicit __CLR_OR_THIS_CALL failure(const string &_Message) |
219 |
|
: runtime_error(_Message) |
220 |
|
{ // construct with message |
221 |
|
} |
222 |
|
|
223 |
|
virtual __CLR_OR_THIS_CALL ~failure() _THROW0() |
224 |
|
{ // destroy the object |
225 |
|
} |
226 |
|
|
227 |
|
#if !_HAS_EXCEPTIONS |
228 |
|
|
229 |
|
protected: |
230 |
|
virtual void __CLR_OR_THIS_CALL _Doraise() const |
231 |
|
{ // report the exception |
232 |
|
_RAISE(*this); |
233 |
|
} |
234 |
|
#endif /* _HAS_EXCEPTIONS */ |
235 |
|
|
236 |
|
}; |
237 |
|
|
238 |
|
// CLASS Init |
239 |
|
class _CRTIMP2_PURE Init |
240 |
|
{ // controller for standard-stream initialization |
241 |
|
public: |
242 |
|
__CLR_OR_THIS_CALL Init() |
243 |
|
{ |
244 |
|
_Init_ctor(this); |
245 |
|
} |
246 |
|
|
247 |
|
__CLR_OR_THIS_CALL ~Init() |
248 |
|
{ |
249 |
|
_Init_dtor(this); |
250 |
|
} |
251 |
|
|
252 |
|
private: |
253 |
|
static _MRTIMP2_NPURE void __cdecl _Init_ctor(Init *); |
254 |
|
static _MRTIMP2_NPURE void __cdecl _Init_dtor(Init *); |
255 |
|
|
256 |
|
_MRTIMP2_NPURE static int& __cdecl _Init_cnt_func(); // net constructions - destructions |
257 |
|
#ifdef _M_CEE_PURE |
258 |
|
static int& _Init_cnt; // net constructions - destructions |
259 |
|
#else |
260 |
|
__PURE_APPDOMAIN_GLOBAL static int _Init_cnt; // net constructions - destructions |
261 |
|
#endif |
262 |
|
}; |
263 |
|
|
264 |
|
ios_base& __CLR_OR_THIS_CALL operator=(const ios_base& _Right) |
265 |
|
{ // assign state and format stuff from _Right |
266 |
|
if (this != &_Right) |
267 |
|
{ // worth doing |
268 |
|
_Mystate = _Right._Mystate; |
269 |
|
copyfmt(_Right); |
270 |
|
} |
271 |
|
return (*this); |
272 |
|
} |
273 |
|
|
274 |
|
__CLR_OR_THIS_CALL operator void *() const |
275 |
|
{ // test if any stream operation has failed |
276 |
|
return (fail() ? 0 : (void *)this); |
277 |
|
} |
278 |
|
|
279 |
|
bool __CLR_OR_THIS_CALL operator!() const |
280 |
|
{ // test if no stream operation has failed |
281 |
|
return (fail()); |
282 |
|
} |
283 |
|
|
284 |
|
void __CLR_OR_THIS_CALL clear(iostate _State, bool _Reraise) |
285 |
|
{ // set state, possibly reraise exception |
286 |
|
_Mystate = (iostate)(_State & _Statmask); |
287 |
|
if ((_Mystate & _Except) == 0) |
288 |
|
; |
289 |
|
else if (_Reraise) |
290 |
|
_RERAISE; |
291 |
|
else if (_Mystate & _Except & badbit) |
292 |
|
_THROW_NCEE(failure, "ios_base::badbit set"); |
293 |
|
else if (_Mystate & _Except & failbit) |
294 |
|
_THROW_NCEE(failure, "ios_base::failbit set"); |
295 |
|
else |
296 |
|
_THROW_NCEE(failure, "ios_base::eofbit set"); |
297 |
|
} |
298 |
|
|
299 |
|
void __CLR_OR_THIS_CALL clear(iostate _State = goodbit) |
300 |
|
{ // set state to argument |
301 |
|
clear(_State, false); |
302 |
|
} |
303 |
|
|
304 |
|
void __CLR_OR_THIS_CALL clear(io_state _State) |
305 |
|
{ // set state to argument, old-style |
306 |
|
clear((iostate)_State); |
307 |
|
} |
560 |
|
(*_Ptr->_Pfn)(_Ev, *this, _Ptr->_Index); |
561 |
|
} |
562 |
|
|
563 |
|
_Iosarray& __CLR_OR_THIS_CALL _Findarr(int _Idx) |
564 |
|
{ // locate or make a variable array element |
565 |
|
_Iosarray *_Ptr, *_Q; |
566 |
|
|
567 |
|
for (_Ptr = _Arr, _Q = 0; _Ptr != 0; _Ptr = _Ptr->_Next) |
568 |
|
if (_Ptr->_Index == _Idx) |
569 |
|
return (*_Ptr); // found element, return it |
570 |
|
else if (_Q == 0 && _Ptr->_Lo == 0 && _Ptr->_Vp == 0) |
571 |
|
_Q = _Ptr; // found recycling candidate |
572 |
|
|
573 |
|
if (_Q != 0) |
574 |
|
{ // recycle existing element |
575 |
|
_Q->_Index = _Idx; |
576 |
|
return (*_Q); |
577 |
|
} |
578 |
|
|
579 |
|
_Arr = _NEW_CRT _Iosarray(_Idx, _Arr); // make a new element |
580 |
|
return (*_Arr); |
581 |
|
} |
582 |
|
|
583 |
|
void __CLRCALL_OR_CDECL _Tidy() |
584 |
|
{ // discard storage for an ios_base |
585 |
|
_Callfns(erase_event); |
586 |
|
_Iosarray *_Q1, *_Q2; |
587 |
|
|
588 |
|
for (_Q1 = _Arr; _Q1 != 0; _Q1 = _Q2) |
589 |
|
_Q2 = _Q1->_Next, _DELETE_CRT(_Q1); // delete array elements |
590 |
|
_Arr = 0; |
591 |
|
|
592 |
|
_Fnarray *_Q3, *_Q4; |
593 |
|
for (_Q3 = _Calls; _Q3 != 0; _Q3 = _Q4) |
594 |
|
_Q4 = _Q3->_Next, _DELETE_CRT(_Q3); // delete callback elements |
595 |
|
_Calls = 0; |
596 |
|
} |
597 |
|
|
598 |
|
static _MRTIMP2_NPURE void __cdecl _Ios_base_dtor(ios_base *); |
599 |
|
|
600 |
|
iostate _Mystate; // stream state |
601 |
|
iostate _Except; // exception mask |
602 |
|
fmtflags _Fmtfl; // format flags |
603 |
|
streamsize _Prec; // field precision |
604 |
|
streamsize _Wide; // field width |
605 |
|
_Iosarray *_Arr; // pointer to first node of long/pointer array |
606 |
|
_Fnarray *_Calls; // pointer to first node of call list |
607 |
|
locale *_Ploc; // pointer to locale |
608 |
|
|
609 |
|
#if defined(_M_CEE_PURE) |
610 |
|
static int& _Index; // source of unique indexes for long/pointer array |
611 |
|
static bool& _Sync; // C/C++ synchronization flag (ignored) |
612 |
|
#else |
613 |
|
__PURE_APPDOMAIN_GLOBAL static int _Index; // source of unique indexes for long/pointer array |
614 |
|
__PURE_APPDOMAIN_GLOBAL static bool _Sync; // C/C++ synchronization flag (ignored) |
615 |
|
#endif |
616 |
|
static _MRTIMP2_NPURE int& __cdecl _Index_func(); |
617 |
|
static _MRTIMP2_NPURE bool& __cdecl _Sync_func(); |
618 |
|
}; |
619 |
|
|
620 |
|
_BITMASK_OPS(ios_base::_Fmtflags) |
621 |
|
_BITMASK_OPS(ios_base::_Iostate) |
622 |
|
_BITMASK_OPS(ios_base::_Openmode) |
623 |
|
_BITMASK_OPS(ios_base::_Seekdir) |
624 |
|
_STD_END |
625 |
|
#ifdef _MSC_VER |
626 |
|
#pragma warning(pop) |
627 |
|
#pragma pack(pop) |
628 |
|
#endif /* _MSC_VER */ |
629 |
|
|
630 |
|
#endif /* RC_INVOKED */ |
631 |
|
#endif /* _XIOSBASE_ */ |
632 |
|
|
633 |
|
/* |
634 |
|
* Copyright (c) 1992-2006 by P.J. Plauger. ALL RIGHTS RESERVED. |
635 |
|
* Consult your license regarding permissions and restrictions. |
636 |
|
V5.02:0009 */ |
637 |
|
|
|
|
|