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.

307 lines
8.5 KiB

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