Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

445 lines
12 KiB

  1. // xiosbase internal header (from <ios>)
  2. #pragma once
  3. #ifndef _XIOSBASE_
  4. #define _XIOSBASE_
  5. #include <xlocale>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. _STD_BEGIN
  9. // TEMPLATE CLASS _Iosb
  10. template<class _Dummy>
  11. class _Iosb
  12. { // define templatized bitmask/enumerated types, instantiate on demand
  13. public:
  14. enum _Dummy_enum {_Dummy_enum_val = 1}; // don't ask
  15. enum _Fmtflags
  16. { // constants for formatting options
  17. _Fmtmask = 0x7fff, _Fmtzero = 0};
  18. _BITMASK(_Fmtflags, fmtflags);
  19. static const _Fmtflags skipws = (_Fmtflags)0x0001;
  20. static const _Fmtflags unitbuf = (_Fmtflags)0x0002;
  21. static const _Fmtflags uppercase = (_Fmtflags)0x0004;
  22. static const _Fmtflags showbase = (_Fmtflags)0x0008;
  23. static const _Fmtflags showpoint = (_Fmtflags)0x0010;
  24. static const _Fmtflags showpos = (_Fmtflags)0x0020;
  25. static const _Fmtflags left = (_Fmtflags)0x0040;
  26. static const _Fmtflags right = (_Fmtflags)0x0080;
  27. static const _Fmtflags internal = (_Fmtflags)0x0100;
  28. static const _Fmtflags dec = (_Fmtflags)0x0200;
  29. static const _Fmtflags oct = (_Fmtflags)0x0400;
  30. static const _Fmtflags hex = (_Fmtflags)0x0800;
  31. static const _Fmtflags scientific = (_Fmtflags)0x1000;
  32. static const _Fmtflags fixed = (_Fmtflags)0x2000;
  33. static const _Fmtflags boolalpha = (_Fmtflags)0x4000;
  34. static const _Fmtflags adjustfield = (_Fmtflags)0x01c0;
  35. static const _Fmtflags basefield = (_Fmtflags)0x0e00;
  36. static const _Fmtflags floatfield = (_Fmtflags)0x3000;
  37. enum _Iostate
  38. { // constants for stream states
  39. _Statmask = 0x7};
  40. _BITMASK(_Iostate, iostate);
  41. static const _Iostate goodbit = (_Iostate)0x0;
  42. static const _Iostate eofbit = (_Iostate)0x1;
  43. static const _Iostate failbit = (_Iostate)0x2;
  44. static const _Iostate badbit = (_Iostate)0x4;
  45. enum _Openmode
  46. { // constants for file opening options
  47. _Openmask = 0x3f};
  48. _BITMASK(_Openmode, openmode);
  49. static const _Openmode in = (_Openmode)0x01;
  50. static const _Openmode out = (_Openmode)0x02;
  51. static const _Openmode ate = (_Openmode)0x04;
  52. static const _Openmode app = (_Openmode)0x08;
  53. static const _Openmode trunc = (_Openmode)0x10;
  54. static const _Openmode binary = (_Openmode)0x20;
  55. enum _Seekdir
  56. { // constants for file positioning options
  57. _Seekmask = 0x3};
  58. _BITMASK(_Seekdir, seekdir);
  59. static const _Seekdir beg = (_Seekdir)0;
  60. static const _Seekdir cur = (_Seekdir)1;
  61. static const _Seekdir end = (_Seekdir)2;
  62. };
  63. template<class _Dummy>
  64. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::skipws;
  65. template<class _Dummy>
  66. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::unitbuf;
  67. template<class _Dummy>
  68. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::uppercase;
  69. template<class _Dummy>
  70. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showbase;
  71. template<class _Dummy>
  72. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showpoint;
  73. template<class _Dummy>
  74. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::showpos;
  75. template<class _Dummy>
  76. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::left;
  77. template<class _Dummy>
  78. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::right;
  79. template<class _Dummy>
  80. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::internal;
  81. template<class _Dummy>
  82. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::dec;
  83. template<class _Dummy>
  84. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::oct;
  85. template<class _Dummy>
  86. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::hex;
  87. template<class _Dummy>
  88. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::scientific;
  89. template<class _Dummy>
  90. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::fixed;
  91. template<class _Dummy>
  92. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::boolalpha;
  93. template<class _Dummy>
  94. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::adjustfield;
  95. template<class _Dummy>
  96. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::basefield;
  97. template<class _Dummy>
  98. const typename _Iosb<_Dummy>::_Fmtflags _Iosb<_Dummy>::floatfield;
  99. template<class _Dummy>
  100. const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::goodbit;
  101. template<class _Dummy>
  102. const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::eofbit;
  103. template<class _Dummy>
  104. const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::failbit;
  105. template<class _Dummy>
  106. const typename _Iosb<_Dummy>::_Iostate _Iosb<_Dummy>::badbit;
  107. template<class _Dummy>
  108. const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::in;
  109. template<class _Dummy>
  110. const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::out;
  111. template<class _Dummy>
  112. const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::ate;
  113. template<class _Dummy>
  114. const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::app;
  115. template<class _Dummy>
  116. const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::trunc;
  117. template<class _Dummy>
  118. const typename _Iosb<_Dummy>::_Openmode _Iosb<_Dummy>::binary;
  119. template<class _Dummy>
  120. const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::beg;
  121. template<class _Dummy>
  122. const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::cur;
  123. template<class _Dummy>
  124. const typename _Iosb<_Dummy>::_Seekdir _Iosb<_Dummy>::end;
  125. // CLASS ios_base
  126. class _CRTIMP2 ios_base
  127. : public _Iosb<int>
  128. { // base class for ios
  129. public:
  130. typedef std::streamoff streamoff;
  131. typedef std::streampos streampos;
  132. enum event
  133. { // constants for ios events
  134. erase_event, imbue_event, copyfmt_event};
  135. typedef void (__cdecl *event_callback)(event, ios_base&, int);
  136. typedef unsigned int io_state, open_mode, seek_dir;
  137. // CLASS failure
  138. class failure
  139. : public runtime_error
  140. { // base of all iostreams exceptions
  141. public:
  142. explicit failure(const string &_Message)
  143. : runtime_error(_Message)
  144. { // construct with message
  145. }
  146. virtual ~failure()
  147. { // destroy the object
  148. }
  149. protected:
  150. virtual void _Doraise() const
  151. { // report the exception
  152. _RAISE(*this);
  153. }
  154. };
  155. // CLASS Init
  156. class _CRTIMP2 Init
  157. { // controller for standard-stream initialization
  158. public:
  159. Init(); // initialize standard streams on first construction
  160. ~Init(); // flush standard streams on last destruction
  161. private:
  162. static int _Init_cnt; // net constructions - destructions
  163. };
  164. ios_base& operator=(const ios_base& _Right)
  165. { // assign state and format stuff from _Right
  166. if (this != &_Right)
  167. { // worth doing
  168. _Mystate = _Right._Mystate;
  169. copyfmt(_Right);
  170. }
  171. return (*this);
  172. }
  173. operator void *() const
  174. { // test if any stream operation has failed
  175. return (fail() ? 0 : (void *)this);
  176. }
  177. bool operator!() const
  178. { // test if no stream operation has failed
  179. return (fail());
  180. }
  181. void clear(iostate, bool); // set state, possibly reraise exception
  182. void clear(iostate _State = goodbit)
  183. { // set state to argument
  184. clear(_State, false);
  185. }
  186. void clear(io_state _State)
  187. { // set state to argument, old-style
  188. clear((iostate)_State);
  189. }
  190. iostate rdstate() const
  191. { // return stream state
  192. return (_Mystate);
  193. }
  194. void setstate(iostate _State, bool _Exreraise)
  195. { // merge in state argument, possibly reraise exception
  196. if (_State != goodbit)
  197. clear((iostate)((int)rdstate() | (int)_State), _Exreraise);
  198. }
  199. void setstate(iostate _State)
  200. { // merge in state argument
  201. if (_State != goodbit)
  202. clear((iostate)((int)rdstate() | (int)_State), false);
  203. }
  204. void setstate(io_state _State)
  205. { // merge in state argument, old style
  206. setstate((iostate)_State);
  207. }
  208. bool good() const
  209. { // test if no state bits are set
  210. return (rdstate() == goodbit);
  211. }
  212. bool eof() const
  213. { // test if eofbit is set in stream state
  214. return ((int)rdstate() & (int)eofbit);
  215. }
  216. bool fail() const
  217. { // test if badbit or failbit is set in stream state
  218. return (((int)rdstate()
  219. & ((int)badbit | (int)failbit)) != 0);
  220. }
  221. bool bad() const
  222. { // test if badbit is set in stream state
  223. return (((int)rdstate() & (int)badbit) != 0);
  224. }
  225. iostate exceptions() const
  226. { // return exception mask
  227. return (_Except);
  228. }
  229. void exceptions(iostate _Newexcept)
  230. { // set exception mask to argument
  231. _Except = (iostate)((int)_Newexcept & (int)_Statmask);
  232. clear(_Mystate);
  233. }
  234. void exceptions(io_state _State)
  235. { // set exception mask to argument, old style
  236. exceptions((iostate)_State);
  237. }
  238. fmtflags flags() const
  239. { // return format flags
  240. return (_Fmtfl);
  241. }
  242. fmtflags flags(fmtflags _Newfmtflags)
  243. { // set format flags to argument
  244. fmtflags _Oldfmtflags = _Fmtfl;
  245. _Fmtfl = (fmtflags)((int)_Newfmtflags & (int)_Fmtmask);
  246. return (_Oldfmtflags);
  247. }
  248. fmtflags setf(fmtflags _Newfmtflags)
  249. { // merge in format flags argument
  250. ios_base::fmtflags _Oldfmtflags = _Fmtfl;
  251. _Fmtfl = (fmtflags)((int)_Fmtfl
  252. | (int)_Newfmtflags & (int)_Fmtmask);
  253. return (_Oldfmtflags);
  254. }
  255. fmtflags setf(fmtflags _Newfmtflags, fmtflags _Mask)
  256. { // merge in format flags argument under mask argument
  257. ios_base::fmtflags _Oldfmtflags = _Fmtfl;
  258. _Fmtfl = (fmtflags)(((int)_Fmtfl & (int)~_Mask)
  259. | ((int)_Newfmtflags & (int)_Mask & (int)_Fmtmask));
  260. return (_Oldfmtflags);
  261. }
  262. void unsetf(fmtflags _Mask)
  263. { // clear format flags under mask argument
  264. _Fmtfl = (fmtflags)((int)_Fmtfl & (int)~_Mask);
  265. }
  266. streamsize precision() const
  267. { // return precision
  268. return (_Prec);
  269. }
  270. streamsize precision(streamsize _Newprecision)
  271. { // set precision to argument
  272. streamsize _Oldprecision = _Prec;
  273. _Prec = _Newprecision;
  274. return (_Oldprecision);
  275. }
  276. streamsize width() const
  277. { // return width
  278. return (_Wide);
  279. }
  280. streamsize width(streamsize _Newwidth)
  281. { // set width to argument
  282. streamsize _Oldwidth = _Wide;
  283. _Wide = _Newwidth;
  284. return (_Oldwidth);
  285. }
  286. locale getloc() const
  287. { // get locale
  288. return (*_Ploc);
  289. }
  290. locale imbue(const locale&); // set locale to argument
  291. static int __cdecl xalloc()
  292. { // allocate new iword/pword index
  293. _Lockit _Lock(_LOCK_STREAM); // lock thread to ensure atomicity
  294. return (_Index++);
  295. }
  296. long& iword(int _Idx)
  297. { // return reference to long element
  298. return (_Findarr(_Idx)._Lo);
  299. }
  300. void *& pword(int _Idx)
  301. { // return reference to pointer element
  302. return (_Findarr(_Idx)._Vp);
  303. }
  304. void register_callback(event_callback, int); // register event handler
  305. ios_base& copyfmt(const ios_base&); // copy format stuff
  306. virtual ~ios_base(); // destroy the object
  307. static bool __cdecl sync_with_stdio(bool _Newsync = true)
  308. { // set C/C++ synchronization flag from argument
  309. _Lockit _Lock(_LOCK_STREAM); // lock thread to ensure atomicity
  310. const bool _Oldsync = _Sync;
  311. _Sync = _Newsync;
  312. return (_Oldsync);
  313. }
  314. void _Addstd(); // add this to list of standard streams
  315. protected:
  316. ios_base()
  317. : _Stdstr(0)
  318. { // default constructor
  319. }
  320. void _Init(); // initialize to standard values
  321. private:
  322. // STRUCT _Iosarray
  323. struct _Iosarray
  324. { // list element for open-ended sparse array of longs/pointers
  325. public:
  326. _Iosarray(int _Idx, _Iosarray *_Link)
  327. : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0)
  328. { // construct node for index _Idx and link it in
  329. }
  330. _Iosarray *_Next; // pointer to next node
  331. int _Index; // index of this node
  332. long _Lo; // stored long value
  333. void *_Vp; // stored pointer value
  334. };
  335. // STRUCT _Fnarray
  336. struct _Fnarray
  337. { // list element for open-ended sparse array of event handlers
  338. _Fnarray(int _Idx, event_callback _Pnew, _Fnarray *_Link)
  339. : _Next(_Link), _Index(_Idx), _Pfn(_Pnew)
  340. { // construct node for index _Idx and link it in
  341. }
  342. _Fnarray *_Next; // pointer to next node
  343. int _Index; // index of this node
  344. event_callback _Pfn; // pointer to event handler
  345. };
  346. void _Callfns(event); // call all event handlers, reporting event
  347. _Iosarray& _Findarr(int); // find an array element
  348. void _Tidy(); // free allocated storage
  349. iostate _Mystate; // stream state
  350. iostate _Except; // exception mask
  351. fmtflags _Fmtfl; // format flags
  352. streamsize _Prec; // field precision
  353. streamsize _Wide; // field width
  354. _Iosarray *_Arr; // pointer to first node of long/pointer array
  355. _Fnarray *_Calls; // pointer to first node of call list
  356. locale *_Ploc; // pointer to locale
  357. size_t _Stdstr; // if > 0 index of standard stream to suppress destruction
  358. static int _Index; // source of unique indexes for long/pointer array
  359. static bool _Sync; // C/C++ synchronization flag (ignored)
  360. };
  361. _BITMASK_OPS(ios_base::_Fmtflags)
  362. _BITMASK_OPS(ios_base::_Iostate)
  363. _BITMASK_OPS(ios_base::_Openmode)
  364. _BITMASK_OPS(ios_base::_Seekdir)
  365. _STD_END
  366. #pragma warning(pop)
  367. #pragma pack(pop)
  368. #endif /* _XIOSBASE_ */
  369. /*
  370. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  371. * Consult your license regarding permissions and restrictions.
  372. V3.10:0009 */