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.

146 lines
4.1 KiB

  1. /***
  2. *iomanip.h - definitions/declarations for iostream's parameterized manipulators
  3. *
  4. * Copyright (c) 1991-1995, 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. ****/
  14. #ifdef __cplusplus
  15. #ifndef _INC_IOMANIP
  16. #define _INC_IOMANIP
  17. #if !defined(_WIN32) && !defined(_MAC)
  18. #error ERROR: Only Mac or Win32 targets supported!
  19. #endif
  20. #ifdef _MSC_VER
  21. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  22. // alignment.
  23. #pragma pack(push,8)
  24. #endif // _MSC_VER
  25. #include <iostream.h>
  26. #ifdef _MSC_VER
  27. #pragma warning(disable:4514) // disable unwanted /W4 warning
  28. // #pragma warning(default:4514) // use this to reenable, if necessary
  29. #endif // _MSC_VER
  30. // #define __MKMANIP(X) \#define X##(T) __##X##_ \#\# T
  31. // __MKMANIP(SMANIP);
  32. // __MKMANIP(SAPP);
  33. // __MKMANIP(IMANIP);
  34. // __MKMANIP(IAPP);
  35. // __MKMANIP(OMANIP);
  36. // __MKMANIP(OAPP);
  37. // __MKMANIP(IOMANIP);
  38. // __MKMANIP(IOAPP);
  39. #define SMANIP(T) __SMANIP_##T
  40. #define SAPP(T) __SAPP_##T
  41. #define IMANIP(T) __IMANIP_##T
  42. #define IAPP(T) __IAPP_##T
  43. #define OMANIP(T) __OMANIP_##T
  44. #define OAPP(T) __OAPP_##T
  45. #define IOMANIP(T) __IOMANIP_##T
  46. #define IOAPP(T) __IOAPP_##T
  47. #define IOMANIPdeclare(T) \
  48. class SMANIP(T) { \
  49. public: \
  50. SMANIP(T)(ios& (*f)(ios&,T), T t) { _fp = f; _tp = t; } \
  51. friend istream& operator>>(istream& s, const SMANIP(T) & sm) { (*(sm._fp))(s,sm._tp); return s; } \
  52. friend ostream& operator<<(ostream& s, const SMANIP(T) & sm) { (*(sm._fp))(s,sm._tp); return s; } \
  53. private: \
  54. ios& (* _fp)(ios&,T); \
  55. T _tp; \
  56. }; \
  57. class SAPP(T) { \
  58. public: \
  59. SAPP(T)( ios& (*f)(ios&,T)) { _fp = f; } \
  60. SMANIP(T) operator()(T t) { return SMANIP(T)(_fp,t); } \
  61. private: \
  62. ios& (* _fp)(ios&,T); \
  63. }; \
  64. class IMANIP(T) { \
  65. public: \
  66. IMANIP(T)(istream& (*f)(istream&,T), T t) { _fp = f; _tp = t; } \
  67. friend istream& operator>>(istream& s, IMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  68. private: \
  69. istream& (* _fp)(istream&,T); \
  70. T _tp; \
  71. }; \
  72. class IAPP(T) { \
  73. public: \
  74. IAPP(T)( istream& (*f)(istream&,T)) { _fp = f; } \
  75. IMANIP(T) operator()(T t) { return IMANIP(T)(_fp,t); } \
  76. private: \
  77. istream& (* _fp)(istream&,T); \
  78. }; \
  79. class OMANIP(T) { \
  80. public: \
  81. OMANIP(T)(ostream& (*f)(ostream&,T), T t) { _fp = f; _tp = t; } \
  82. friend ostream& operator<<(ostream& s, OMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  83. private: \
  84. ostream& (* _fp)(ostream&,T); \
  85. T _tp; \
  86. }; \
  87. class OAPP(T) { \
  88. public: \
  89. OAPP(T)(ostream& (*f)(ostream&,T)) { _fp = f; } \
  90. OMANIP(T) operator()(T t) { return OMANIP(T)(_fp,t); } \
  91. private: \
  92. ostream& (* _fp)(ostream&,T); \
  93. }; \
  94. \
  95. class IOMANIP(T) { \
  96. public: \
  97. IOMANIP(T)(iostream& (*f)(iostream&,T), T t) { _fp = f; _tp = t; } \
  98. friend istream& operator>>(iostream& s, IOMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  99. friend ostream& operator<<(iostream& s, IOMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  100. private: \
  101. iostream& (* _fp)(iostream&,T); \
  102. T _tp; \
  103. }; \
  104. class IOAPP(T) { \
  105. public: \
  106. IOAPP(T)( iostream& (*f)(iostream&,T)) { _fp = f; } \
  107. IOMANIP(T) operator()(T t) { return IOMANIP(T)(_fp,t); } \
  108. private: \
  109. iostream& (* _fp)(iostream&,T); \
  110. }; \
  111. IOMANIPdeclare(int)
  112. IOMANIPdeclare(long)
  113. inline ios& __resetiosflags(ios& s, long _flg) { s.setf(0,_flg); return s; }
  114. inline ios& __setfill(ios& s, int _fc) { s.fill((char)_fc); return s; }
  115. inline ios& __setiosflags(ios& s, long _flg) { s.setf(_flg); return s; }
  116. inline ios& __setprecision(ios& s, int _pre) { s.precision(_pre); return s; }
  117. inline ios& __setw(ios& s, int _wid) { s.width(_wid); return s; }
  118. inline SMANIP(long) resetiosflags(long _l) { return SMANIP(long)(__resetiosflags, _l); }
  119. inline SMANIP(int) setfill(int _m) {return SMANIP(int)(__setfill, _m); }
  120. inline SMANIP(long) setiosflags(long _l) {return SMANIP(long)(__setiosflags, _l); }
  121. inline SMANIP(int) setprecision(int _p) {return SMANIP(int)(__setprecision, _p); }
  122. inline SMANIP(int) setw(int _w) { return SMANIP(int)(__setw, _w); }
  123. // Restore previous packing
  124. #ifdef _MSC_VER
  125. #pragma pack(pop)
  126. #endif // _MSC_VER
  127. #endif // _INC_IOMANIP
  128. #endif /* __cplusplus */