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.

177 lines
5.7 KiB

  1. /***
  2. *iomanip.h - definitions/declarations for iostream's parameterized manipulators
  3. *
  4. * Copyright (c) 1991-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines the classes, values, macros, and functions
  8. * used by the iostream classes' paramterized manipulators.
  9. * [AT&T C++]
  10. *
  11. * [Public]
  12. *
  13. *Revision History:
  14. * 01-23-92 KRS Ported from 16-bit version.
  15. * 02-23-93 SKS Update copyright to 1993
  16. * 06-08-93 SKS Add "const" keyword in declaration operator >> & <<
  17. * 10-13-93 GJF Enclose #pragma-s in #ifdef _MSC_VER
  18. * 08-12-94 GJF Disable warning 4514 instead of 4505.
  19. * 11-03-94 GJF Changed pack pragma to 8 byte alignment.
  20. * 02-11-95 CFW Add _CRTBLD to avoid users getting wrong headers.
  21. * 02-14-95 CFW Clean up Mac merge.
  22. * 05-11-95 CFW Only for use by C++ programs.
  23. * 12-14-95 JWM Add "#pragma once".
  24. * 04-15-96 JWM Remove _OLD_IOSTREAMS, add '#pragma comment(lib,"cirt")'.
  25. * 04-16-96 JWM '#include useoldio.h' replaces '#pragma comment(...)'.
  26. * 09-05-96 RDK Change class initialization to handle reference definition.
  27. * 02-24-97 GJF Detab-ed.
  28. * 05-17-99 PML Remove all Macintosh support.
  29. *
  30. ****/
  31. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  32. #pragma once
  33. #endif
  34. #ifdef __cplusplus
  35. #ifndef _INC_IOMANIP
  36. #define _INC_IOMANIP
  37. #if !defined(_WIN32)
  38. #error ERROR: Only Win32 target supported!
  39. #endif
  40. #ifndef _CRTBLD
  41. /* This version of the header files is NOT for user programs.
  42. * It is intended for use when building the C runtimes ONLY.
  43. * The version intended for public use will not have this message.
  44. */
  45. #error ERROR: Use of C runtime library internal header file.
  46. #endif /* _CRTBLD */
  47. #ifdef _MSC_VER
  48. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  49. // alignment.
  50. #pragma pack(push,8)
  51. #include <useoldio.h>
  52. #endif // _MSC_VER
  53. #include <iostream.h>
  54. #ifdef _MSC_VER
  55. #pragma warning(disable:4514) // disable unwanted /W4 warning
  56. // #pragma warning(default:4514) // use this to reenable, if necessary
  57. #endif // _MSC_VER
  58. // #define __MKMANIP(X) \#define X##(T) __##X##_ \#\# T
  59. // __MKMANIP(SMANIP);
  60. // __MKMANIP(SAPP);
  61. // __MKMANIP(IMANIP);
  62. // __MKMANIP(IAPP);
  63. // __MKMANIP(OMANIP);
  64. // __MKMANIP(OAPP);
  65. // __MKMANIP(IOMANIP);
  66. // __MKMANIP(IOAPP);
  67. #define SMANIP(T) __SMANIP_##T
  68. #define SAPP(T) __SAPP_##T
  69. #define IMANIP(T) __IMANIP_##T
  70. #define IAPP(T) __IAPP_##T
  71. #define OMANIP(T) __OMANIP_##T
  72. #define OAPP(T) __OAPP_##T
  73. #define IOMANIP(T) __IOMANIP_##T
  74. #define IOAPP(T) __IOAPP_##T
  75. #define IOMANIPdeclare(T) \
  76. class SMANIP(T) { \
  77. public: \
  78. SMANIP(T)(ios& (*f)(ios&,T), T t) : _fp(f), _tp(t) {} \
  79. friend istream& operator>>(istream& s, const SMANIP(T) & sm) { (*(sm._fp))(s,sm._tp); return s; } \
  80. friend ostream& operator<<(ostream& s, const SMANIP(T) & sm) { (*(sm._fp))(s,sm._tp); return s; } \
  81. private: \
  82. ios& (* _fp)(ios&,T); \
  83. T _tp; \
  84. }; \
  85. class SAPP(T) { \
  86. public: \
  87. SAPP(T)( ios& (*f)(ios&,T)) : _fp(f) {} \
  88. SMANIP(T) operator()(T t) { return SMANIP(T)(_fp,t); } \
  89. private: \
  90. ios& (* _fp)(ios&,T); \
  91. }; \
  92. class IMANIP(T) { \
  93. public: \
  94. IMANIP(T)(istream& (*f)(istream&,T), T t) : _fp(f), _tp(t) {} \
  95. friend istream& operator>>(istream& s, IMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  96. private: \
  97. istream& (* _fp)(istream&,T); \
  98. T _tp; \
  99. }; \
  100. class IAPP(T) { \
  101. public: \
  102. IAPP(T)( istream& (*f)(istream&,T)) : _fp(f) {} \
  103. IMANIP(T) operator()(T t) { return IMANIP(T)(_fp,t); } \
  104. private: \
  105. istream& (* _fp)(istream&,T); \
  106. }; \
  107. class OMANIP(T) { \
  108. public: \
  109. OMANIP(T)(ostream& (*f)(ostream&,T), T t) : _fp(f), _tp(t) {} \
  110. friend ostream& operator<<(ostream& s, OMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  111. private: \
  112. ostream& (* _fp)(ostream&,T); \
  113. T _tp; \
  114. }; \
  115. class OAPP(T) { \
  116. public: \
  117. OAPP(T)(ostream& (*f)(ostream&,T)) : _fp(f) {} \
  118. OMANIP(T) operator()(T t) { return OMANIP(T)(_fp,t); } \
  119. private: \
  120. ostream& (* _fp)(ostream&,T); \
  121. }; \
  122. \
  123. class IOMANIP(T) { \
  124. public: \
  125. IOMANIP(T)(iostream& (*f)(iostream&,T), T t) : _fp(f), _tp(t) {} \
  126. friend istream& operator>>(iostream& s, IOMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  127. friend ostream& operator<<(iostream& s, IOMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  128. private: \
  129. iostream& (* _fp)(iostream&,T); \
  130. T _tp; \
  131. }; \
  132. class IOAPP(T) { \
  133. public: \
  134. IOAPP(T)( iostream& (*f)(iostream&,T)) : _fp(f) {} \
  135. IOMANIP(T) operator()(T t) { return IOMANIP(T)(_fp,t); } \
  136. private: \
  137. iostream& (* _fp)(iostream&,T); \
  138. }; \
  139. IOMANIPdeclare(int)
  140. IOMANIPdeclare(long)
  141. inline ios& __resetiosflags(ios& s, long _flg) { s.setf(0,_flg); return s; }
  142. inline ios& __setfill(ios& s, int _fc) { s.fill((char)_fc); return s; }
  143. inline ios& __setiosflags(ios& s, long _flg) { s.setf(_flg); return s; }
  144. inline ios& __setprecision(ios& s, int _pre) { s.precision(_pre); return s; }
  145. inline ios& __setw(ios& s, int _wid) { s.width(_wid); return s; }
  146. inline SMANIP(long) resetiosflags(long _l) { return SMANIP(long)(__resetiosflags, _l); }
  147. inline SMANIP(int) setfill(int _m) {return SMANIP(int)(__setfill, _m); }
  148. inline SMANIP(long) setiosflags(long _l) {return SMANIP(long)(__setiosflags, _l); }
  149. inline SMANIP(int) setprecision(int _p) {return SMANIP(int)(__setprecision, _p); }
  150. inline SMANIP(int) setw(int _w) { return SMANIP(int)(__setw, _w); }
  151. // Restore previous packing
  152. #ifdef _MSC_VER
  153. #pragma pack(pop)
  154. #endif // _MSC_VER
  155. #endif // _INC_IOMANIP
  156. #endif /* __cplusplus */