Leaked source code of windows server 2003
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.

198 lines
6.0 KiB

  1. /***
  2. *ios.h - definitions/declarations for the ios class.
  3. *
  4. * Copyright (c) 1990-1992, 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. ****/
  12. #ifndef _INC_IOS
  13. #define _INC_IOS
  14. #ifdef M_I86HM
  15. #define _HFAR_ __far
  16. #else
  17. #define _HFAR_
  18. #endif
  19. #ifndef NULL
  20. #define NULL 0
  21. #endif
  22. #ifndef EOF
  23. #define EOF (-1)
  24. #endif
  25. // Force word packing to avoid possible -Zp override
  26. #pragma pack(2)
  27. #pragma warning(disable:4505) // disable unwanted /W4 warning
  28. // #pragma warning(default:4505) // use this to reenable, if necessary
  29. class streambuf;
  30. class ostream;
  31. class ios {
  32. public:
  33. enum io_state { goodbit = 0x00,
  34. eofbit = 0x01,
  35. failbit = 0x02,
  36. badbit = 0x04 };
  37. enum open_mode { in = 0x01,
  38. out = 0x02,
  39. ate = 0x04,
  40. app = 0x08,
  41. trunc = 0x10,
  42. nocreate = 0x20,
  43. noreplace = 0x40,
  44. binary = 0x80 }; // CONSIDER: not in latest spec.
  45. enum seek_dir { beg=0, cur=1, end=2 };
  46. enum { skipws = 0x0001,
  47. left = 0x0002,
  48. right = 0x0004,
  49. internal = 0x0008,
  50. dec = 0x0010,
  51. oct = 0x0020,
  52. hex = 0x0040,
  53. showbase = 0x0080,
  54. showpoint = 0x0100,
  55. uppercase = 0x0200,
  56. showpos = 0x0400,
  57. scientific = 0x0800,
  58. fixed = 0x1000,
  59. unitbuf = 0x2000,
  60. stdio = 0x4000
  61. };
  62. static const long basefield; // dec | oct | hex
  63. static const long adjustfield; // left | right | internal
  64. static const long floatfield; // scientific | fixed
  65. ios(streambuf*); // differs from ANSI
  66. virtual ~ios();
  67. inline long flags() const;
  68. inline long flags(long _l);
  69. inline long setf(long _f,long _m);
  70. inline long setf(long _l);
  71. inline long unsetf(long _l);
  72. inline int width() const;
  73. inline int width(int _i);
  74. inline ostream* tie(ostream* _os);
  75. inline ostream* tie() const;
  76. inline char fill() const;
  77. inline char fill(char _c);
  78. inline int precision(int _i);
  79. inline int precision() const;
  80. inline int rdstate() const;
  81. inline void clear(int _i = 0);
  82. // inline operator void*() const;
  83. operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  84. inline int operator!() const;
  85. inline int good() const;
  86. inline int eof() const;
  87. inline int fail() const;
  88. inline int bad() const;
  89. inline streambuf* rdbuf() const;
  90. inline long _HFAR_ & iword(int) const;
  91. inline void _HFAR_ * _HFAR_ & pword(int) const;
  92. static long bitalloc();
  93. static int xalloc();
  94. static void sync_with_stdio();
  95. protected:
  96. ios();
  97. ios(const ios&); // treat as private
  98. ios& operator=(const ios&);
  99. void init(streambuf*);
  100. enum { skipping, tied };
  101. streambuf* bp;
  102. int state;
  103. int ispecial; // not used
  104. int ospecial; // not used
  105. int isfx_special; // not used
  106. int osfx_special; // not used
  107. int x_delbuf; // if set, rdbuf() deleted by ~ios
  108. ostream* x_tie;
  109. long x_flags;
  110. int x_precision;
  111. int x_width;
  112. char x_fill;
  113. static void (*stdioflush)(); // not used
  114. public:
  115. int delbuf() const { return x_delbuf; }
  116. void delbuf(int _i) { x_delbuf = _i; }
  117. private:
  118. static long x_maxbit;
  119. static long _HFAR_ * x_statebuf; // used by xalloc()
  120. static int x_curindex;
  121. // consider: make interal static to ios::sync_with_stdio()
  122. static int sunk_with_stdio; // make sure sync_with done only once
  123. };
  124. inline ios& dec(ios& _strm) { _strm.setf(ios::dec,ios::basefield); return _strm; }
  125. inline ios& hex(ios& _strm) { _strm.setf(ios::hex,ios::basefield); return _strm; }
  126. inline ios& oct(ios& _strm) { _strm.setf(ios::oct,ios::basefield); return _strm; }
  127. inline long ios::flags() const { return x_flags; }
  128. inline long ios::flags(long _l){ long _lO; _lO = x_flags; x_flags = _l; return _lO; }
  129. inline long ios::setf(long _l,long _m){ long _lO; _lO = x_flags; x_flags = (_l&_m) | (x_flags&(~_m)); return _lO; }
  130. inline long ios::setf(long _l){ long _lO; _lO = x_flags; x_flags |= _l; return _lO; }
  131. inline long ios::unsetf(long _l){ long _lO; _lO = x_flags; x_flags &= (~_l); return _lO; }
  132. inline int ios::width() const { return x_width; }
  133. inline int ios::width(int _i){ int _iO; _iO = (int)x_width; x_width = _i; return _iO; }
  134. inline ostream* ios::tie(ostream* _os){ ostream* _osO; _osO = x_tie; x_tie = _os; return _osO; }
  135. inline ostream* ios::tie() const { return x_tie; }
  136. inline char ios::fill() const { return x_fill; }
  137. inline char ios::fill(char _c){ char _cO; _cO = x_fill; x_fill = _c; return _cO; }
  138. inline int ios::precision(int _i){ int _iO; _iO = (int)x_precision; x_precision = _i; return _iO; }
  139. inline int ios::precision() const { return x_precision; }
  140. inline int ios::rdstate() const { return state; }
  141. // inline ios::operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  142. inline int ios::operator!() const { return state&(badbit|failbit); }
  143. inline int ios::bad() const { return state & badbit; }
  144. inline void ios::clear(int _i){ state = _i; }
  145. inline int ios::eof() const { return state & eofbit; }
  146. inline int ios::fail() const { return state & (badbit | failbit); }
  147. inline int ios::good() const { return state == 0; }
  148. inline streambuf* ios::rdbuf() const { return bp; }
  149. inline long _HFAR_ & ios::iword(int _i) const { return x_statebuf[_i] ; }
  150. inline void _HFAR_ * _HFAR_ & ios::pword(int _i) const { return (void _HFAR_ * _HFAR_ &)x_statebuf[_i]; }
  151. // Restore default packing
  152. #pragma pack()
  153. #endif