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.

309 lines
8.9 KiB

  1. /***
  2. *ios.h - definitions/declarations for the ios class.
  3. *
  4. * Copyright (c) 1990-2001, Microsoft Corporation. All rights reserved.
  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. * [Public]
  12. *
  13. ****/
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifdef __cplusplus
  18. #ifndef _INC_IOS
  19. #define _INC_IOS
  20. #if !defined(_WIN32)
  21. #error ERROR: Only Win32 target supported!
  22. #endif
  23. #ifdef _MSC_VER
  24. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  25. // alignment.
  26. #pragma pack(push,8)
  27. #include <useoldio.h>
  28. #endif // _MSC_VER
  29. /* Define _CRTIMP */
  30. #ifndef _CRTIMP
  31. #ifdef _DLL
  32. #define _CRTIMP __declspec(dllimport)
  33. #else /* ndef _DLL */
  34. #define _CRTIMP
  35. #endif /* _DLL */
  36. #endif /* _CRTIMP */
  37. #ifdef _MT
  38. typedef struct __CRT_LIST_ENTRY {
  39. struct __CRT_LIST_ENTRY *Flink;
  40. struct __CRT_LIST_ENTRY *Blink;
  41. } _CRT_LIST_ENTRY;
  42. typedef struct _CRT_CRITICAL_SECTION_DEBUG {
  43. unsigned short Type;
  44. unsigned short CreatorBackTraceIndex;
  45. struct _CRT_CRITICAL_SECTION *CriticalSection;
  46. _CRT_LIST_ENTRY ProcessLocksList;
  47. unsigned long EntryCount;
  48. unsigned long ContentionCount;
  49. unsigned long Depth;
  50. void * OwnerBackTrace[ 5 ];
  51. } _CRT_CRITICAL_SECTION_DEBUG, *_PCRT_CRITICAL_SECTION_DEBUG;
  52. typedef struct _CRT_CRITICAL_SECTION {
  53. _PCRT_CRITICAL_SECTION_DEBUG DebugInfo;
  54. //
  55. // The following three fields control entering and exiting the critical
  56. // section for the resource
  57. //
  58. long LockCount;
  59. long RecursionCount;
  60. void * OwningThread; // from the thread's ClientId->UniqueThread
  61. void * LockSemaphore;
  62. unsigned long Reserved;
  63. } _CRT_CRITICAL_SECTION, *_PCRT_CRITICAL_SECTION;
  64. extern "C" {
  65. _CRTIMP void __cdecl _mtlock(_PCRT_CRITICAL_SECTION);
  66. _CRTIMP void __cdecl _mtunlock(_PCRT_CRITICAL_SECTION);
  67. }
  68. #endif /* _MT */
  69. #ifndef NULL
  70. #define NULL 0
  71. #endif
  72. #ifndef EOF
  73. #define EOF (-1)
  74. #endif
  75. #ifdef _MSC_VER
  76. // C4514: "unreferenced inline function has been removed"
  77. #pragma warning(disable:4514) // disable C4514 warning
  78. // #pragma warning(default:4514) // use this to reenable, if desired
  79. #endif // _MSC_VER
  80. class _CRTIMP streambuf;
  81. class _CRTIMP ostream;
  82. class _CRTIMP ios {
  83. public:
  84. enum io_state { goodbit = 0x00,
  85. eofbit = 0x01,
  86. failbit = 0x02,
  87. badbit = 0x04 };
  88. enum open_mode { in = 0x01,
  89. out = 0x02,
  90. ate = 0x04,
  91. app = 0x08,
  92. trunc = 0x10,
  93. nocreate = 0x20,
  94. noreplace = 0x40,
  95. binary = 0x80 };
  96. enum seek_dir { beg=0, cur=1, end=2 };
  97. enum { skipws = 0x0001,
  98. left = 0x0002,
  99. right = 0x0004,
  100. internal = 0x0008,
  101. dec = 0x0010,
  102. oct = 0x0020,
  103. hex = 0x0040,
  104. showbase = 0x0080,
  105. showpoint = 0x0100,
  106. uppercase = 0x0200,
  107. showpos = 0x0400,
  108. scientific = 0x0800,
  109. fixed = 0x1000,
  110. unitbuf = 0x2000,
  111. stdio = 0x4000
  112. };
  113. static const long basefield; // dec | oct | hex
  114. static const long adjustfield; // left | right | internal
  115. static const long floatfield; // scientific | fixed
  116. ios(streambuf*); // differs from ANSI
  117. virtual ~ios();
  118. inline long flags() const;
  119. inline long flags(long _l);
  120. inline long setf(long _f,long _m);
  121. inline long setf(long _l);
  122. inline long unsetf(long _l);
  123. inline int width() const;
  124. inline int width(int _i);
  125. inline ostream* tie(ostream* _os);
  126. inline ostream* tie() const;
  127. inline char fill() const;
  128. inline char fill(char _c);
  129. inline int precision(int _i);
  130. inline int precision() const;
  131. inline int rdstate() const;
  132. inline void clear(int _i = 0);
  133. // inline operator void*() const;
  134. operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  135. inline int operator!() const;
  136. inline int good() const;
  137. inline int eof() const;
  138. inline int fail() const;
  139. inline int bad() const;
  140. inline streambuf* rdbuf() const;
  141. inline long & iword(int) const;
  142. inline void * & pword(int) const;
  143. static long bitalloc();
  144. static int xalloc();
  145. static void sync_with_stdio();
  146. #ifdef _MT
  147. inline void __cdecl setlock();
  148. inline void __cdecl clrlock();
  149. void __cdecl lock() { if (LockFlg<0) _mtlock(lockptr()); };
  150. void __cdecl unlock() { if (LockFlg<0) _mtunlock(lockptr()); }
  151. inline void __cdecl lockbuf();
  152. inline void __cdecl unlockbuf();
  153. #else
  154. void __cdecl lock() { }
  155. void __cdecl unlock() { }
  156. void __cdecl lockbuf() { }
  157. void __cdecl unlockbuf() { }
  158. #endif
  159. protected:
  160. ios();
  161. ios(const ios&); // treat as private
  162. ios& operator=(const ios&);
  163. void init(streambuf*);
  164. enum { skipping, tied };
  165. streambuf* bp;
  166. int state;
  167. int ispecial; // not used
  168. int ospecial; // not used
  169. int isfx_special; // not used
  170. int osfx_special; // not used
  171. int x_delbuf; // if set, rdbuf() deleted by ~ios
  172. ostream* x_tie;
  173. long x_flags;
  174. int x_precision;
  175. char x_fill;
  176. int x_width;
  177. static void (*stdioflush)(); // not used
  178. #ifdef _MT
  179. static void lockc() { _mtlock(& x_lockc); }
  180. static void unlockc() { _mtunlock( & x_lockc); }
  181. _PCRT_CRITICAL_SECTION lockptr() { return & x_lock; }
  182. #else
  183. static void lockc() { }
  184. static void unlockc() { }
  185. #endif
  186. public:
  187. int delbuf() const { return x_delbuf; }
  188. void delbuf(int _i) { x_delbuf = _i; }
  189. private:
  190. static long x_maxbit;
  191. static int x_curindex;
  192. static int sunk_with_stdio; // make sure sync_with done only once
  193. #ifdef _MT
  194. #define MAXINDEX 7
  195. static long x_statebuf[MAXINDEX+1]; // used by xalloc()
  196. static int fLockcInit; // used to see if x_lockc initialized
  197. static _CRT_CRITICAL_SECTION x_lockc; // used to lock static (class) data members
  198. int LockFlg; // enable locking flag
  199. _CRT_CRITICAL_SECTION x_lock; // used for multi-thread lock on object
  200. #else
  201. static long * x_statebuf; // used by xalloc()
  202. #endif
  203. };
  204. #include <streamb.h>
  205. inline _CRTIMP ios& __cdecl dec(ios& _strm) { _strm.setf(ios::dec,ios::basefield); return _strm; }
  206. inline _CRTIMP ios& __cdecl hex(ios& _strm) { _strm.setf(ios::hex,ios::basefield); return _strm; }
  207. inline _CRTIMP ios& __cdecl oct(ios& _strm) { _strm.setf(ios::oct,ios::basefield); return _strm; }
  208. inline long ios::flags() const { return x_flags; }
  209. inline long ios::flags(long _l){ long _lO; _lO = x_flags; x_flags = _l; return _lO; }
  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. inline int ios::width() const { return x_width; }
  214. inline int ios::width(int _i){ int _iO; _iO = (int)x_width; x_width = _i; return _iO; }
  215. inline ostream* ios::tie(ostream* _os){ ostream* _osO; _osO = x_tie; x_tie = _os; return _osO; }
  216. inline ostream* ios::tie() const { return x_tie; }
  217. inline char ios::fill() const { return x_fill; }
  218. inline char ios::fill(char _c){ char _cO; _cO = x_fill; x_fill = _c; return _cO; }
  219. inline int ios::precision(int _i){ int _iO; _iO = (int)x_precision; x_precision = _i; return _iO; }
  220. inline int ios::precision() const { return x_precision; }
  221. inline int ios::rdstate() const { return state; }
  222. // inline ios::operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  223. inline int ios::operator!() const { return state&(badbit|failbit); }
  224. inline int ios::bad() const { return state & badbit; }
  225. inline void ios::clear(int _i){ lock(); state = _i; unlock(); }
  226. inline int ios::eof() const { return state & eofbit; }
  227. inline int ios::fail() const { return state & (badbit | failbit); }
  228. inline int ios::good() const { return state == 0; }
  229. inline streambuf* ios::rdbuf() const { return bp; }
  230. inline long & ios::iword(int _i) const { return x_statebuf[_i] ; }
  231. inline void * & ios::pword(int _i) const { return (void * &)x_statebuf[_i]; }
  232. #ifdef _MT
  233. inline void ios::setlock() { LockFlg--; if (bp) bp->setlock(); }
  234. inline void ios::clrlock() { if (LockFlg <= 0) LockFlg++; if (bp) bp->clrlock(); }
  235. inline void ios::lockbuf() { bp->lock(); }
  236. inline void ios::unlockbuf() { bp->unlock(); }
  237. #endif
  238. #ifdef _MSC_VER
  239. // Restore default packing
  240. #pragma pack(pop)
  241. #endif // _MSC_VER
  242. #endif // _INC_IOS
  243. #endif /* __cplusplus */