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.

188 lines
6.5 KiB

  1. // xiosbase internal header (from <ios>)
  2. #ifndef _XIOSBASE_
  3. #define _XIOSBASE_
  4. #include <xlocale>
  5. #ifdef _MSC_VER
  6. #pragma pack(push,8)
  7. #if 1200 <= _MSC_VER
  8. #pragma warning(push,3)
  9. #pragma warning(disable:4786)
  10. #endif
  11. #endif /* _MSC_VER */
  12. _STD_BEGIN
  13. // CLASS ios_base
  14. class _CRTIMP2 ios_base {
  15. public:
  16. // CLASS failure
  17. class failure : public runtime_error {
  18. public:
  19. explicit failure(const string &_S)
  20. : runtime_error(_S) {}
  21. virtual ~failure()
  22. {}
  23. protected:
  24. virtual void _Doraise() const
  25. {_RAISE(*this); }
  26. };
  27. enum _Fmtflags {skipws = 0x0001, unitbuf = 0x0002,
  28. uppercase = 0x0004, showbase = 0x0008,
  29. showpoint = 0x0010, showpos = 0x0020,
  30. left = 0x0040, right = 0x0080, internal = 0x0100,
  31. dec = 0x0200, oct = 0x0400, hex = 0x0800,
  32. scientific = 0x1000, fixed = 0x2000, boolalpha = 0x4000,
  33. adjustfield = 0x01c0, basefield = 0x0e00,
  34. floatfield = 0x3000, _Fmtmask = 0x7fff, _Fmtzero = 0};
  35. enum _Iostate {goodbit = 0x0, eofbit = 0x1,
  36. failbit = 0x2, badbit = 0x4, _Statmask = 0x7};
  37. enum _Openmode {in = 0x01, out = 0x02, ate = 0x04,
  38. app = 0x08, trunc = 0x10, binary = 0x20};
  39. enum seekdir {beg = 0, cur = 1, end = 2};
  40. enum event {erase_event, imbue_event, copyfmt_event};
  41. typedef void (__cdecl *event_callback)(event, ios_base&, int);
  42. _BITMASK(_Fmtflags, fmtflags);
  43. _BITMASK(_Iostate, iostate);
  44. _BITMASK(_Openmode, openmode);
  45. typedef short io_state, open_mode, seek_dir;
  46. // CLASS Init
  47. class _CRTIMP2 Init {
  48. public:
  49. Init();
  50. ~Init();
  51. private:
  52. static int _Init_cnt;
  53. };
  54. ios_base& operator=(const ios_base& _R)
  55. {if (this != &_R)
  56. {_State = _R._State;
  57. copyfmt(_R); }
  58. return (*this); }
  59. operator void *() const
  60. {return (fail() ? 0 : (void *)this); }
  61. bool operator!() const
  62. {return (fail()); }
  63. void clear(iostate = goodbit, bool = false);
  64. void clear(io_state _St)
  65. {clear((iostate)_St); }
  66. iostate rdstate() const
  67. {return (_State); }
  68. void setstate(iostate _St, bool _Ex = false)
  69. {if (_St != goodbit)
  70. clear((iostate)((int)rdstate() | (int)_St), _Ex); }
  71. void setstate(io_state _St)
  72. {setstate((iostate)_St); }
  73. bool good() const
  74. {return (rdstate() == goodbit); }
  75. bool eof() const
  76. {return ((int)rdstate() & (int)eofbit); }
  77. bool fail() const
  78. {return (((int)rdstate() & ((int)badbit | (int)failbit)) != 0); }
  79. bool bad() const
  80. {return (((int)rdstate() & (int)badbit) != 0); }
  81. iostate exceptions() const
  82. {return (_Except); }
  83. void exceptions(iostate _Ne)
  84. {_Except = _Ne & _Statmask;
  85. clear(_State); }
  86. void exceptions(io_state _St)
  87. {exceptions((iostate)_St); }
  88. fmtflags flags() const
  89. {return (_Fmtfl); }
  90. fmtflags flags(fmtflags _Nf)
  91. {fmtflags _Of = _Fmtfl;
  92. _Fmtfl = _Nf & _Fmtmask;
  93. return (_Of); }
  94. fmtflags setf(fmtflags _Nf)
  95. {ios_base::fmtflags _Of = _Fmtfl;
  96. _Fmtfl |= _Nf & _Fmtmask;
  97. return (_Of); }
  98. fmtflags setf(fmtflags _Nf, fmtflags _M)
  99. {ios_base::fmtflags _Of = _Fmtfl;
  100. _Fmtfl = (_Fmtfl & ~_M) | (_Nf & _M & _Fmtmask);
  101. return (_Of); }
  102. void unsetf(fmtflags _M)
  103. {_Fmtfl &= ~_M; }
  104. streamsize precision() const
  105. {return (_Prec); }
  106. streamsize precision(int _Np)
  107. {streamsize _Op = _Prec;
  108. _Prec = _Np;
  109. return (_Op); }
  110. streamsize width() const
  111. {return (_Wide); }
  112. streamsize width(streamsize _Nw)
  113. {streamsize _Ow = _Wide;
  114. _Wide = (int)_Nw;
  115. return (_Ow); }
  116. locale getloc() const
  117. {return (_Loc); }
  118. locale imbue(const locale&);
  119. static int __cdecl xalloc()
  120. {_Lockit _Lk;
  121. return (_Index++); }
  122. long& iword(int _Idx)
  123. {return (_Findarr(_Idx)._Lo); }
  124. void *& pword(int _Idx)
  125. {return (_Findarr(_Idx)._Vp); }
  126. void register_callback(event_callback, int);
  127. ios_base& copyfmt(const ios_base&);
  128. virtual ~ios_base();
  129. static bool __cdecl sync_with_stdio(bool _Sfl = true)
  130. {_Lockit _Lk;
  131. const bool _Osfl = _Sync;
  132. _Sync = _Sfl;
  133. return (_Osfl); }
  134. protected:
  135. ios_base()
  136. : _Loc(_Noinit), _Stdstr(0) {}
  137. void _Addstd();
  138. void _Init();
  139. private:
  140. // STRUCT _Iosarray
  141. struct _Iosarray {
  142. public:
  143. _Iosarray(int _Idx, _Iosarray *_Link)
  144. : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0) {}
  145. _Iosarray *_Next;
  146. int _Index;
  147. long _Lo;
  148. void *_Vp;
  149. };
  150. // STRUCT _Fnarray
  151. struct _Fnarray {
  152. _Fnarray(int _Idx, event_callback _P, _Fnarray *_Link)
  153. : _Next(_Link), _Index(_Idx), _Pfn(_P) {}
  154. _Fnarray *_Next;
  155. int _Index;
  156. event_callback _Pfn;
  157. };
  158. void _Callfns(event);
  159. _Iosarray& _Findarr(int);
  160. void _Tidy();
  161. iostate _State, _Except;
  162. fmtflags _Fmtfl;
  163. int _Prec, _Wide;
  164. _Iosarray *_Arr;
  165. _Fnarray *_Calls;
  166. locale _Loc;
  167. size_t _Stdstr;
  168. static int _Index;
  169. static bool _Sync;
  170. };
  171. _BITMASK_OPS(ios_base::_Fmtflags)
  172. _BITMASK_OPS(ios_base::_Iostate)
  173. _BITMASK_OPS(ios_base::_Openmode)
  174. _STD_END
  175. #ifdef _MSC_VER
  176. #if 1200 <= _MSC_VER
  177. #pragma warning(pop)
  178. #endif
  179. #pragma pack(pop)
  180. #endif /* _MSC_VER */
  181. #endif /* _XIOSBASE_ */
  182. /*
  183. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  184. * Consult your license regarding permissions and restrictions.
  185. */