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.

128 lines
4.1 KiB

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