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.

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