home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / modhead1.zip / IOMANIP.H < prev    next >
C/C++ Source or Header  |  1995-09-17  |  4KB  |  179 lines

  1. /*
  2.  *   iomanip.h
  3.  *
  4.  *   C++ IOStreams manipulators.
  5.  *
  6.  *   This file will change drastically once parameterized
  7.  *   types are implemented.
  8.  *
  9.  *           Copyright (c) 1991-1994, MetaWare Incorporated
  10.  */
  11.  
  12. #ifndef __IOMANIP_H
  13. #define __IOMANIP_H
  14. #pragma push_align_members(64);
  15.  
  16. #if _MSDOS && !__EXCEPTIONS__
  17.     #pragma off(exception_aware_class);
  18. #elif _MSDOS || _MSNT || _OS2
  19.     #pragma on(exception_aware_class);
  20. #endif
  21.  
  22. #if _MSNT && _DLL && !_DLLBUILD
  23.     #pragma on(dllimport);
  24. #endif
  25.  
  26. #c_include <generic.h>
  27. #c_include <iostream.h>
  28.  
  29. #define SMANIP(TYPE)    name2(smanip_,TYPE)
  30. #define SAPP(TYPE)    name2(sapply_,TYPE)
  31. #define IMANIP(TYPE)    name2(imanip_,TYPE)
  32. #define OMANIP(TYPE)    name2(omanip_,TYPE)
  33. #define IOMANIP(TYPE)    name2(iomanip_,TYPE)
  34. #define IAPP(TYPE)    name2(iapply_,TYPE)
  35. #define OAPP(TYPE)    name2(oapply_,TYPE)
  36. #define IOAPP(TYPE)    name2(ioapply_,TYPE)
  37.  
  38. #define _CLa(TYPE) \
  39.     class SMANIP(TYPE){ \
  40.         ios&(*fcn)(ios&,TYPE); \
  41.         TYPE arg; \
  42.     public: \
  43.         SMANIP(TYPE)(ios&(*f)(ios&,TYPE),TYPE a) { \
  44.             fcn=f; \
  45.             arg=a; \
  46.             } \
  47.         friend istream&operator>>(istream&i,const SMANIP(TYPE)&m){ \
  48.             ios *s=&i; \
  49.             (*m.fcn)(*s,m.arg); \
  50.             return i; \
  51.             }\
  52.         friend ostream&operator<<(ostream&o,const SMANIP(TYPE)&m){ \
  53.             ios*s=&o; \
  54.             (*m.fcn)(*s,m.arg); \
  55.             return o; \
  56.             } \
  57.     };\
  58.     \
  59.     class SAPP(TYPE){ \
  60.         ios&(*fcn)(ios&,TYPE); \
  61.     public: \
  62.         SAPP(TYPE)(ios&(*f)(ios&,TYPE)) { \
  63.             fcn=f; \
  64.             } \
  65.         SMANIP(TYPE) operator()(TYPE a){ \
  66.             return SMANIP(TYPE)(fcn,a); \
  67.             }\
  68.     };
  69.  
  70.  
  71. #define _CLb(TYPE) \
  72.     class IMANIP(TYPE){ \
  73.         istream&(*fcn)(istream&,TYPE); \
  74.         TYPE arg; \
  75.     public: \
  76.         IMANIP(TYPE)(istream&(*f)(istream&,TYPE),TYPE a){ \
  77.             fcn=f; \
  78.             arg=a; \
  79.             } \
  80.         friend istream& operator>>(istream&s,const IMANIP(TYPE)&m){ \
  81.             return(*m.fcn)(s,m.arg); \
  82.             } \
  83.     };\
  84.     \
  85.     class IAPP(TYPE){ \
  86.         istream&(*fcn)(istream&,TYPE); \
  87.     public: \
  88.         IAPP(TYPE)(istream&(*f)(istream&,TYPE)){ \
  89.             fcn=f; \
  90.             } \
  91.         IMANIP(TYPE) operator()(TYPE a){ \
  92.             return IMANIP(TYPE)(fcn,a); \
  93.             } \
  94.     };
  95.  
  96.  
  97. #define _CLc(TYPE) \
  98.     class OMANIP(TYPE){ \
  99.         ostream&(*fcn)(ostream&,TYPE); \
  100.         TYPE arg; \
  101.     public: \
  102.         OMANIP(TYPE)(ostream&(*f)(ostream&,TYPE),TYPE a){ \
  103.             fcn=f; \
  104.             arg=a; \
  105.             } \
  106.         friend ostream&operator<<(ostream&s,const OMANIP(TYPE)&m){ \
  107.             return(*m.fcn)(s,m.arg); \
  108.             } \
  109.     };\
  110.     \
  111.     class OAPP(TYPE){ \
  112.         ostream&(*fcn)(ostream&,TYPE); \
  113.     public: \
  114.         OAPP(TYPE)(ostream&(*f)(ostream&,TYPE)){ \
  115.             fcn=f; \
  116.             } \
  117.         OMANIP(TYPE) operator()(TYPE a){ \
  118.             return OMANIP(TYPE)(fcn,a); \
  119.             } \
  120.     };
  121.  
  122. #define _CLd(TYPE)\
  123.     class IOMANIP(TYPE){ \
  124.         iostream&(*fcn)(iostream&,TYPE); \
  125.         TYPE arg; \
  126.     public: \
  127.         IOMANIP(TYPE)(iostream&(*f)(iostream&,TYPE),TYPE a){ \
  128.             fcn=f; \
  129.             arg=a; \
  130.             } \
  131.         friend istream&operator>>(iostream&s,const IOMANIP(TYPE)&m){ \
  132.             return(*m.fcn)(s,m.arg); \
  133.             } \
  134.         friend ostream&operator<<(iostream&s,const IOMANIP(TYPE)&m){ \
  135.             return(*m.fcn)(s,m.arg); \
  136.             } \
  137.     };\
  138.     \
  139.     class IOAPP(TYPE){ \
  140.         iostream&(*fcn)(iostream&,TYPE); \
  141.     public: \
  142.         IOAPP(TYPE)(iostream&(*f)(iostream&,TYPE)){ \
  143.             fcn=f; \
  144.             } \
  145.         IOMANIP(TYPE) operator()(TYPE a){ \
  146.             return IOMANIP(TYPE)(fcn,a); \
  147.             } \
  148.     };
  149.  
  150. #define IOMANIPdeclare(TYPE) _CLa(TYPE) _CLb(TYPE) _CLc(TYPE) _CLd(TYPE)
  151.  
  152. #pragma on(nodebug)
  153.  
  154. IOMANIPdeclare(int) ;
  155. IOMANIPdeclare(long) ;
  156.  
  157. SMANIP(int)     setbase(int b) ;    // 0, 8, 10, or 16. (NOT ios::hex, etc.)
  158. SMANIP(long)    resetiosflags(long b) ;
  159. SMANIP(long)    setiosflags(long b) ;
  160. SMANIP(int)    setfill(int f);
  161. SMANIP(int)    setprecision(int p);
  162. SMANIP(int)    setw(int w) ;
  163.  
  164. #pragma pop(nodebug)
  165.  
  166. #if _MSNT && _DLL && !_DLLBUILD
  167.     #pragma pop(dllimport);
  168. #endif
  169.  
  170. #if _MSDOS || _MSNT || _OS2
  171.     #pragma pop(exception_aware_class);
  172. #endif
  173.  
  174. #pragma pop_align_members();
  175. #endif  // __IOMANIP_H
  176.  
  177.  
  178. /**          Copyright (c) 1991-1994, MetaWare Incorporated             **/
  179.