home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / iomanip.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  5KB  |  161 lines

  1. /***
  2. *iomanip.h - definitions/declarations for iostream's parameterized manipulators
  3. *
  4. *       Copyright (c) 1991-1997, 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.  
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif  /* _MSC_VER > 1000 */
  18.  
  19. #ifdef __cplusplus
  20.  
  21. #ifndef _INC_IOMANIP
  22. #define _INC_IOMANIP
  23.  
  24. #if !defined (_WIN32) && !defined (_MAC)
  25. #error ERROR: Only Mac or Win32 targets supported!
  26. #endif  /* !defined (_WIN32) && !defined (_MAC) */
  27.  
  28. #ifndef _CRTBLD
  29. /* This version of the header files is NOT for user programs.
  30.  * It is intended for use when building the C runtimes ONLY.
  31.  * The version intended for public use will not have this message.
  32.  */
  33. #error ERROR: Use of C runtime library internal header file.
  34. #endif  /* _CRTBLD */
  35.  
  36. #ifdef _MSC_VER
  37. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  38. // alignment.
  39. #pragma pack(push,8)
  40.  
  41. #include <useoldio.h>
  42.  
  43. #endif  /* _MSC_VER */
  44.  
  45. #include <iostream.h>
  46.  
  47. #ifdef _MSC_VER
  48. #pragma warning(disable:4514)           // disable unwanted /W4 warning
  49. // #pragma warning(default:4514)        // use this to reenable, if necessary
  50. #endif  /* _MSC_VER */
  51.  
  52. // #define __MKMANIP(X) \#define X##(T) __##X##_ \#\# T
  53. // __MKMANIP(SMANIP);
  54. // __MKMANIP(SAPP);
  55. // __MKMANIP(IMANIP);
  56. // __MKMANIP(IAPP);
  57. // __MKMANIP(OMANIP);
  58. // __MKMANIP(OAPP);
  59. // __MKMANIP(IOMANIP);
  60. // __MKMANIP(IOAPP);
  61.  
  62. #define SMANIP(T) __SMANIP_##T
  63. #define SAPP(T) __SAPP_##T
  64. #define IMANIP(T) __IMANIP_##T
  65. #define IAPP(T) __IAPP_##T
  66. #define OMANIP(T) __OMANIP_##T
  67. #define OAPP(T) __OAPP_##T
  68. #define IOMANIP(T) __IOMANIP_##T
  69. #define IOAPP(T) __IOAPP_##T
  70.  
  71. #define IOMANIPdeclare(T)  \
  72. class SMANIP(T) { \
  73. public: \
  74.         SMANIP(T)(ios& (*f)(ios&,T), T t) : _fp(f), _tp(t) {} \
  75.         friend istream& operator>>(istream& s, const SMANIP(T) & sm) { (*(sm._fp))(s,sm._tp); return s; } \
  76.         friend ostream& operator<<(ostream& s, const SMANIP(T) & sm) { (*(sm._fp))(s,sm._tp); return s; } \
  77. private:        \
  78.         ios& (* _fp)(ios&,T); \
  79.         T _tp; \
  80. };      \
  81. class SAPP(T) { \
  82. public: \
  83.         SAPP(T)( ios& (*f)(ios&,T)) : _fp(f) {} \
  84.         SMANIP(T) operator()(T t) { return SMANIP(T)(_fp,t); }  \
  85. private:        \
  86.         ios& (* _fp)(ios&,T); \
  87. };      \
  88. class IMANIP(T) { \
  89. public: \
  90.         IMANIP(T)(istream& (*f)(istream&,T), T t) : _fp(f), _tp(t) {} \
  91.         friend istream& operator>>(istream& s, IMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  92. private:        \
  93.         istream& (* _fp)(istream&,T); \
  94.         T _tp;  \
  95. };      \
  96. class IAPP(T) { \
  97. public: \
  98.         IAPP(T)( istream& (*f)(istream&,T)) : _fp(f) {} \
  99.         IMANIP(T) operator()(T t) { return IMANIP(T)(_fp,t); }  \
  100. private:        \
  101.         istream& (* _fp)(istream&,T); \
  102. };      \
  103. class OMANIP(T) { \
  104. public: \
  105.         OMANIP(T)(ostream& (*f)(ostream&,T), T t) : _fp(f), _tp(t) {} \
  106.         friend ostream& operator<<(ostream& s, OMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  107. private:        \
  108.         ostream& (* _fp)(ostream&,T); \
  109.         T _tp; \
  110. };      \
  111. class OAPP(T) { \
  112. public: \
  113.         OAPP(T)(ostream& (*f)(ostream&,T)) : _fp(f) {}  \
  114.         OMANIP(T) operator()(T t) { return OMANIP(T)(_fp,t); } \
  115. private:        \
  116.         ostream& (* _fp)(ostream&,T); \
  117. };      \
  118. \
  119. class IOMANIP(T) { \
  120. public: \
  121.         IOMANIP(T)(iostream& (*f)(iostream&,T), T t) : _fp(f), _tp(t) {} \
  122.         friend istream& operator>>(iostream& s, IOMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  123.         friend ostream& operator<<(iostream& s, IOMANIP(T) & sm) { (*sm._fp)(s,sm._tp); return s; } \
  124. private:        \
  125.         iostream& (* _fp)(iostream&,T); \
  126.         T _tp; \
  127. };      \
  128. class IOAPP(T) {        \
  129. public: \
  130.         IOAPP(T)( iostream& (*f)(iostream&,T)) : _fp(f) {}      \
  131.         IOMANIP(T) operator()(T t) { return IOMANIP(T)(_fp,t); }        \
  132. private:        \
  133.         iostream& (* _fp)(iostream&,T); \
  134. }; \
  135.  
  136.  
  137. IOMANIPdeclare(int)
  138.  
  139. IOMANIPdeclare(long)
  140.  
  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.  
  147. inline SMANIP(long)     resetiosflags(long _l) { return SMANIP(long)(__resetiosflags, _l); }
  148. inline SMANIP(int)      setfill(int _m) {return SMANIP(int)(__setfill, _m); }
  149. inline SMANIP(long)     setiosflags(long _l) {return SMANIP(long)(__setiosflags, _l); }
  150. inline SMANIP(int)      setprecision(int _p) {return SMANIP(int)(__setprecision, _p); }
  151. inline SMANIP(int)      setw(int _w) { return SMANIP(int)(__setw, _w); }
  152.  
  153. // Restore previous packing
  154. #ifdef _MSC_VER
  155. #pragma pack(pop)
  156. #endif  /* _MSC_VER */
  157.  
  158. #endif  /* _INC_IOMANIP */
  159.  
  160. #endif  /* __cplusplus */
  161.