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.

305 lines
7.3 KiB

  1. // ios standard header
  2. #pragma once
  3. #ifndef _IOS_
  4. #define _IOS_
  5. #include <xlocnum>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. _STD_BEGIN
  9. // TEMPLATE CLASS basic_ios
  10. template<class _Elem,
  11. class _Traits>
  12. class basic_ios
  13. : public ios_base
  14. { // base class for basic_istream/basic_ostream
  15. public:
  16. typedef basic_ios<_Elem, _Traits> _Myt;
  17. typedef basic_ostream<_Elem, _Traits> _Myos;
  18. typedef basic_streambuf<_Elem, _Traits> _Mysb;
  19. typedef ctype<_Elem> _Ctype;
  20. typedef _Elem char_type;
  21. typedef _Traits traits_type;
  22. typedef typename _Traits::int_type int_type;
  23. typedef typename _Traits::pos_type pos_type;
  24. typedef typename _Traits::off_type off_type;
  25. explicit basic_ios(_Mysb *_Strbuf)
  26. { // construct from stream buffer pointer
  27. init(_Strbuf);
  28. }
  29. virtual ~basic_ios()
  30. { // destroy the object
  31. }
  32. void clear(iostate _State = goodbit, bool _Except = false)
  33. { // set state, possibly reraise exception
  34. ios_base::clear((iostate)(_Mystrbuf == 0
  35. ? (int)_State | (int)badbit : (int)_State), _Except);
  36. }
  37. void clear(io_state _State)
  38. { // set state to _State
  39. clear((iostate)_State);
  40. }
  41. void setstate(iostate _State, bool _Except = false)
  42. { // merge _State into state, possible reraise exception
  43. if (_State != goodbit)
  44. clear((iostate)((int)rdstate() | (int)_State), _Except);
  45. }
  46. void setstate(io_state _State)
  47. { // merge _State into state
  48. setstate((iostate)_State);
  49. }
  50. _Myt& copyfmt(const _Myt& _Right)
  51. { // copy format parameters
  52. _Tiestr = _Right.tie();
  53. _Fillch = _Right.fill();
  54. ios_base::copyfmt(_Right);
  55. return (*this);
  56. }
  57. _Myos *tie() const
  58. { // return tie pointer
  59. return (_Tiestr);
  60. }
  61. _Myos *tie(_Myos *_Newtie)
  62. { // set tie pointer
  63. _Myos *_Oldtie = _Tiestr;
  64. _Tiestr = _Newtie;
  65. return (_Oldtie);
  66. }
  67. _Mysb *rdbuf() const
  68. { // return stream buffer pointer
  69. return (_Mystrbuf);
  70. }
  71. _Mysb *rdbuf(_Mysb *_Strbuf)
  72. { // set stream buffer pointer
  73. _Mysb *_Oldstrbuf = _Mystrbuf;
  74. _Mystrbuf = _Strbuf;
  75. clear();
  76. return (_Oldstrbuf);
  77. }
  78. locale imbue(const locale& _Loc)
  79. { // set locale to argument
  80. locale _Oldlocale = ios_base::imbue(_Loc);
  81. if (rdbuf() != 0)
  82. rdbuf()->pubimbue(_Loc);
  83. return (_Oldlocale);
  84. }
  85. _Elem fill() const
  86. { // return fill character
  87. return (_Fillch);
  88. }
  89. _Elem fill(_Elem _Newfill)
  90. { // set fill character
  91. _Elem _Oldfill = _Fillch;
  92. _Fillch = _Newfill;
  93. return (_Oldfill);
  94. }
  95. char narrow(_Elem _Ch, char _Dflt = '\0') const
  96. { // convert _Ch to byte using imbued locale
  97. const _Ctype& _Facet = _USE(getloc(), _Ctype);
  98. return (_Facet.narrow(_Ch, _Dflt));
  99. }
  100. _Elem widen(char _Byte) const
  101. { // convert _Byte to character using imbued locale
  102. const _Ctype& _Facet = _USE(getloc(), _Ctype);
  103. return (_Facet.widen(_Byte));
  104. }
  105. protected:
  106. void init(_Mysb *_Strbuf = 0, bool _Isstd = false)
  107. { // initialize with stream buffer pointer
  108. _Mystrbuf = _Strbuf;
  109. _Tiestr = 0;
  110. _Fillch = _WIDEN(_Elem, ' ');
  111. _Init(); // initialize ios_base
  112. if (_Mystrbuf == 0)
  113. setstate(badbit);
  114. if (_Isstd)
  115. _Addstd(); // special handling for standard streams
  116. }
  117. basic_ios()
  118. { // default constructor, do nothing
  119. }
  120. private:
  121. basic_ios(const _Myt&); // not defined
  122. _Myt& operator=(const _Myt&); // not defined
  123. _Mysb *_Mystrbuf; // pointer to stream buffer
  124. _Myos *_Tiestr; // pointer to tied output stream
  125. _Elem _Fillch; // the fill character
  126. };
  127. #ifdef _DLL_CPPLIB
  128. #ifdef __FORCE_INSTANCE
  129. template class _CRTIMP2 basic_ios<char,
  130. char_traits<char> >;
  131. template class _CRTIMP2 basic_ios<wchar_t,
  132. char_traits<wchar_t> >;
  133. #ifdef _CRTBLD_NATIVE_WCHAR_T
  134. template class _CRTIMP2 basic_ios<unsigned short,
  135. char_traits<unsigned short> >;
  136. #endif
  137. #endif // __FORCE_INSTANCE
  138. #endif // _DLL_CPPLIB
  139. // MANIPULATORS
  140. inline ios_base& __cdecl boolalpha(ios_base& _Iosbase)
  141. { // set boolalpha
  142. _Iosbase.setf(ios_base::boolalpha);
  143. return (_Iosbase);
  144. }
  145. inline ios_base& __cdecl dec(ios_base& _Iosbase)
  146. { // set basefield to dec
  147. _Iosbase.setf(ios_base::dec, ios_base::basefield);
  148. return (_Iosbase);
  149. }
  150. inline ios_base& __cdecl fixed(ios_base& _Iosbase)
  151. { // set floatfield to fixed
  152. _Iosbase.setf(ios_base::fixed, ios_base::floatfield);
  153. return (_Iosbase);
  154. }
  155. inline ios_base& __cdecl hex(ios_base& _Iosbase)
  156. { // set basefield to hex
  157. _Iosbase.setf(ios_base::hex, ios_base::basefield);
  158. return (_Iosbase);
  159. }
  160. inline ios_base& __cdecl internal(ios_base& _Iosbase)
  161. { // set adjustfield to internal
  162. _Iosbase.setf(ios_base::internal, ios_base::adjustfield);
  163. return (_Iosbase);
  164. }
  165. inline ios_base& __cdecl left(ios_base& _Iosbase)
  166. { // set adjustfield to left
  167. _Iosbase.setf(ios_base::left, ios_base::adjustfield);
  168. return (_Iosbase);
  169. }
  170. inline ios_base& __cdecl noboolalpha(ios_base& _Iosbase)
  171. { // clear boolalpha
  172. _Iosbase.unsetf(ios_base::boolalpha);
  173. return (_Iosbase);
  174. }
  175. inline ios_base& __cdecl noshowbase(ios_base& _Iosbase)
  176. { // clear showbase
  177. _Iosbase.unsetf(ios_base::showbase);
  178. return (_Iosbase);
  179. }
  180. inline ios_base& __cdecl noshowpoint(ios_base& _Iosbase)
  181. { // clear showpoint
  182. _Iosbase.unsetf(ios_base::showpoint);
  183. return (_Iosbase);
  184. }
  185. inline ios_base& __cdecl noshowpos(ios_base& _Iosbase)
  186. { // clear showpos
  187. _Iosbase.unsetf(ios_base::showpos);
  188. return (_Iosbase);
  189. }
  190. inline ios_base& __cdecl noskipws(ios_base& _Iosbase)
  191. { // clear skipws
  192. _Iosbase.unsetf(ios_base::skipws);
  193. return (_Iosbase);
  194. }
  195. inline ios_base& __cdecl nounitbuf(ios_base& _Iosbase)
  196. { // clear unitbuf
  197. _Iosbase.unsetf(ios_base::unitbuf);
  198. return (_Iosbase);
  199. }
  200. inline ios_base& __cdecl nouppercase(ios_base& _Iosbase)
  201. { // clear uppercase
  202. _Iosbase.unsetf(ios_base::uppercase);
  203. return (_Iosbase);
  204. }
  205. inline ios_base& __cdecl oct(ios_base& _Iosbase)
  206. { // set oct in basefield
  207. _Iosbase.setf(ios_base::oct, ios_base::basefield);
  208. return (_Iosbase);
  209. }
  210. inline ios_base& __cdecl right(ios_base& _Iosbase)
  211. { // set right in adjustfield
  212. _Iosbase.setf(ios_base::right, ios_base::adjustfield);
  213. return (_Iosbase);
  214. }
  215. inline ios_base& __cdecl scientific(ios_base& _Iosbase)
  216. { // set scientific in floatfield
  217. _Iosbase.setf(ios_base::scientific, ios_base::floatfield);
  218. return (_Iosbase);
  219. }
  220. inline ios_base& __cdecl showbase(ios_base& _Iosbase)
  221. { // set showbase
  222. _Iosbase.setf(ios_base::showbase);
  223. return (_Iosbase);
  224. }
  225. inline ios_base& __cdecl showpoint(ios_base& _Iosbase)
  226. { // set showpoint
  227. _Iosbase.setf(ios_base::showpoint);
  228. return (_Iosbase);
  229. }
  230. inline ios_base& __cdecl showpos(ios_base& _Iosbase)
  231. { // set showpos
  232. _Iosbase.setf(ios_base::showpos);
  233. return (_Iosbase);
  234. }
  235. inline ios_base& __cdecl skipws(ios_base& _Iosbase)
  236. { // set skipws
  237. _Iosbase.setf(ios_base::skipws);
  238. return (_Iosbase);
  239. }
  240. inline ios_base& __cdecl unitbuf(ios_base& _Iosbase)
  241. { // set unitbuf
  242. _Iosbase.setf(ios_base::unitbuf);
  243. return (_Iosbase);
  244. }
  245. inline ios_base& __cdecl uppercase(ios_base& _Iosbase)
  246. { // set uppercase
  247. _Iosbase.setf(ios_base::uppercase);
  248. return (_Iosbase);
  249. }
  250. _STD_END
  251. #pragma warning(pop)
  252. #pragma pack(pop)
  253. #endif /* _IOS_ */
  254. /*
  255. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  256. * Consult your license regarding permissions and restrictions.
  257. V3.10:0009 */