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.

299 lines
6.8 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. template class _CRTIMP2 basic_ios<char,
  129. char_traits<char> >;
  130. template class _CRTIMP2 basic_ios<wchar_t,
  131. char_traits<wchar_t> >;
  132. #endif // _DLL_CPPLIB
  133. // MANIPULATORS
  134. inline ios_base& __cdecl boolalpha(ios_base& _Iosbase)
  135. { // set boolalpha
  136. _Iosbase.setf(ios_base::boolalpha);
  137. return (_Iosbase);
  138. }
  139. inline ios_base& __cdecl dec(ios_base& _Iosbase)
  140. { // set basefield to dec
  141. _Iosbase.setf(ios_base::dec, ios_base::basefield);
  142. return (_Iosbase);
  143. }
  144. inline ios_base& __cdecl fixed(ios_base& _Iosbase)
  145. { // set floatfield to fixed
  146. _Iosbase.setf(ios_base::fixed, ios_base::floatfield);
  147. return (_Iosbase);
  148. }
  149. inline ios_base& __cdecl hex(ios_base& _Iosbase)
  150. { // set basefield to hex
  151. _Iosbase.setf(ios_base::hex, ios_base::basefield);
  152. return (_Iosbase);
  153. }
  154. inline ios_base& __cdecl internal(ios_base& _Iosbase)
  155. { // set adjustfield to internal
  156. _Iosbase.setf(ios_base::internal, ios_base::adjustfield);
  157. return (_Iosbase);
  158. }
  159. inline ios_base& __cdecl left(ios_base& _Iosbase)
  160. { // set adjustfield to left
  161. _Iosbase.setf(ios_base::left, ios_base::adjustfield);
  162. return (_Iosbase);
  163. }
  164. inline ios_base& __cdecl noboolalpha(ios_base& _Iosbase)
  165. { // clear boolalpha
  166. _Iosbase.unsetf(ios_base::boolalpha);
  167. return (_Iosbase);
  168. }
  169. inline ios_base& __cdecl noshowbase(ios_base& _Iosbase)
  170. { // clear showbase
  171. _Iosbase.unsetf(ios_base::showbase);
  172. return (_Iosbase);
  173. }
  174. inline ios_base& __cdecl noshowpoint(ios_base& _Iosbase)
  175. { // clear showpoint
  176. _Iosbase.unsetf(ios_base::showpoint);
  177. return (_Iosbase);
  178. }
  179. inline ios_base& __cdecl noshowpos(ios_base& _Iosbase)
  180. { // clear showpos
  181. _Iosbase.unsetf(ios_base::showpos);
  182. return (_Iosbase);
  183. }
  184. inline ios_base& __cdecl noskipws(ios_base& _Iosbase)
  185. { // clear skipws
  186. _Iosbase.unsetf(ios_base::skipws);
  187. return (_Iosbase);
  188. }
  189. inline ios_base& __cdecl nounitbuf(ios_base& _Iosbase)
  190. { // clear unitbuf
  191. _Iosbase.unsetf(ios_base::unitbuf);
  192. return (_Iosbase);
  193. }
  194. inline ios_base& __cdecl nouppercase(ios_base& _Iosbase)
  195. { // clear uppercase
  196. _Iosbase.unsetf(ios_base::uppercase);
  197. return (_Iosbase);
  198. }
  199. inline ios_base& __cdecl oct(ios_base& _Iosbase)
  200. { // set oct in basefield
  201. _Iosbase.setf(ios_base::oct, ios_base::basefield);
  202. return (_Iosbase);
  203. }
  204. inline ios_base& __cdecl right(ios_base& _Iosbase)
  205. { // set right in adjustfield
  206. _Iosbase.setf(ios_base::right, ios_base::adjustfield);
  207. return (_Iosbase);
  208. }
  209. inline ios_base& __cdecl scientific(ios_base& _Iosbase)
  210. { // set scientific in floatfield
  211. _Iosbase.setf(ios_base::scientific, ios_base::floatfield);
  212. return (_Iosbase);
  213. }
  214. inline ios_base& __cdecl showbase(ios_base& _Iosbase)
  215. { // set showbase
  216. _Iosbase.setf(ios_base::showbase);
  217. return (_Iosbase);
  218. }
  219. inline ios_base& __cdecl showpoint(ios_base& _Iosbase)
  220. { // set showpoint
  221. _Iosbase.setf(ios_base::showpoint);
  222. return (_Iosbase);
  223. }
  224. inline ios_base& __cdecl showpos(ios_base& _Iosbase)
  225. { // set showpos
  226. _Iosbase.setf(ios_base::showpos);
  227. return (_Iosbase);
  228. }
  229. inline ios_base& __cdecl skipws(ios_base& _Iosbase)
  230. { // set skipws
  231. _Iosbase.setf(ios_base::skipws);
  232. return (_Iosbase);
  233. }
  234. inline ios_base& __cdecl unitbuf(ios_base& _Iosbase)
  235. { // set unitbuf
  236. _Iosbase.setf(ios_base::unitbuf);
  237. return (_Iosbase);
  238. }
  239. inline ios_base& __cdecl uppercase(ios_base& _Iosbase)
  240. { // set uppercase
  241. _Iosbase.setf(ios_base::uppercase);
  242. return (_Iosbase);
  243. }
  244. _STD_END
  245. #pragma warning(pop)
  246. #pragma pack(pop)
  247. #endif /* _IOS_ */
  248. /*
  249. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  250. * Consult your license regarding permissions and restrictions.
  251. V3.10:0009 */