home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / IOMANIP.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  5KB  |  172 lines

  1. //
  2. //  iomanip.h    I/O streams manipulators
  3. //
  4. //  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  5. //
  6. #ifndef _IOMANIP_H_INCLUDED
  7. #define _IOMANIP_H_INCLUDED
  8.  
  9. #ifndef __cplusplus
  10. #error iomanip.h is for use with C++
  11. #endif
  12.  
  13. #ifndef _COMDEF_H_INCLUDED
  14.  #include <_comdef.h>
  15. #endif
  16. #ifndef _IOSTREAM_H_INCLUDED
  17.  #include <iostream.h>
  18. #endif
  19.  
  20. #if defined(_M_IX86)
  21.   #pragma pack(__push,1);
  22. #else
  23.   #pragma pack(__push,8);
  24. #endif
  25. template<class T>
  26.     class _WPRTLINK smanip;
  27. template<class T>
  28.     class _WPRTLINK sapp {
  29.     public:
  30.     sapp( ios &(*__f)( ios &, T ) ) : 
  31.         __fn( __f ) {};
  32.     smanip<T> operator()( T __p ) { return smanip<T>( __fn, __p ); };
  33.     private:
  34.     ios &(*__fn)( ios &, T );
  35.     };
  36. template<class T>
  37.     class _WPRTLINK smanip {
  38.     public:
  39.     smanip( ios &(*__f)( ios &, T ), T __p ) : 
  40.         __fn( __f ), __parm( __p ) {};
  41.     friend _WPRTLINK istream &operator>>( istream &, const smanip<T> & );
  42.     friend _WPRTLINK ostream &operator<<( ostream &, const smanip<T> & );
  43.     private:
  44.     ios &(*__fn)( ios &, T );
  45.     T __parm;
  46.     };
  47. template<class T>
  48.     _WPRTLINK istream &operator>>( istream &__is, const smanip<T> &__sm ) {
  49.     __sm.__fn( __is, __sm.__parm );
  50.     return( __is );
  51.     }
  52. template<class T>
  53.     _WPRTLINK ostream &operator<<( ostream &__os, const smanip<T> &__sm ) {
  54.     __sm.__fn( __os, __sm.__parm );
  55.     return( __os );
  56.     }
  57.  
  58. template<class T>
  59.     class _WPRTLINK imanip;
  60. template<class T>
  61.     class _WPRTLINK iapp {
  62.     public:
  63.     iapp( istream &(*__f)( istream &, T ) ) : 
  64.         __fn( __f ) {};
  65.     imanip<T> operator()( T __p ) { return imanip<T>( __fn, __p ) };
  66.     private:
  67.     istream &(*__fn)( istream &, T );
  68.     };
  69. template<class T>
  70.     class _WPRTLINK imanip {
  71.     public:
  72.     imanip( istream &(*__f)( istream &, T ), T __p ) : 
  73.         __fn( __f ), __parm( __p ) {};
  74.     friend _WPRTLINK istream &operator>>( istream &, const imanip<T> & );
  75.     private:
  76.     istream &(*__fn)( istream &, T );
  77.     T __parm;
  78.     };
  79. template<class T>
  80.     _WPRTLINK istream &operator>>( istream &__is, const imanip<T> &__im ) {
  81.     __im.__fn( __is, __im.__parm );
  82.     return( __is );
  83.     }
  84.  
  85. template<class T>
  86.     class _WPRTLINK omanip;
  87. template<class T>
  88.     class _WPRTLINK oapp {
  89.     public:
  90.     oapp( ostream &(*__f)( ostream &, T ) ) : 
  91.         __fn( __f ) {} ;
  92.     omanip<T> operator()( T __p ) { return omanip<T>( __fn, __p ); };
  93.     private:
  94.     ostream &(*__fn)( ostream &, T );
  95.     };
  96. template<class T>
  97.     class _WPRTLINK omanip {
  98.     public:
  99.     omanip( ostream &(*__f)( ostream &, T ), T __p ) : 
  100.         __fn( __f ), __parm( __p ) {};
  101.     friend _WPRTLINK ostream &operator<<( ostream &, const omanip<T> & );
  102.     private:
  103.     ostream &(*__fn)( ostream &, T );
  104.     T __parm;
  105.     };
  106. template<class T>
  107.     _WPRTLINK ostream &operator<<( ostream &__os, const omanip<T> &__om ) {
  108.     __om.__fn( __os, __om.__parm );
  109.     return( __os );
  110.     }
  111.  
  112. template<class T>
  113.     class _WPRTLINK iomanip;
  114. template<class T>
  115.     class _WPRTLINK ioapp {
  116.     public:
  117.     ioapp( iostream &(*__f)( iostream &, T ) ) : 
  118.         __fn( __f ) {};
  119.     iomanip<T> operator()( T __p ) { return iomanip<T>( __fn, __p ) };
  120.     private:
  121.     iostream &(*__fn)( iostream &, T );
  122.     };
  123. template<class T>
  124.     class _WPRTLINK iomanip {
  125.     public:
  126.     iomanip( iostream &(*__f)( iostream &, T ), T __p ) :
  127.         __fn( __f ), __parm( __p ) {};
  128.     friend _WPRTLINK iostream &operator>>( iostream &, const iomanip<T> & );
  129.     private:
  130.     iostream &(*__fn)( iostream &, T );
  131.     T __parm;
  132.     };
  133. template<class T>
  134.     _WPRTLINK iostream &operator>>( iostream &__is, const iomanip<T> &__im ) {
  135.     __im.__fn( __is, __im.__parm );
  136.     return( __is );
  137.     }
  138.     
  139. #pragma pack(__pop);
  140.  
  141. // applicator objects
  142. #ifdef M_I86HM
  143. _WPRTLINK extern sapp<long> _WCFAR resetiosflags;
  144. _WPRTLINK extern sapp<int>  _WCFAR setbase;
  145. _WPRTLINK extern sapp<int>  _WCFAR setfill;
  146. _WPRTLINK extern sapp<long> _WCFAR setiosflags;
  147. _WPRTLINK extern sapp<int>  _WCFAR setprecision;
  148. _WPRTLINK extern sapp<int>  _WCFAR setw;
  149. #else
  150. _WPRTLINK extern sapp<long> _WCNEAR resetiosflags;
  151. _WPRTLINK extern sapp<int>  _WCNEAR setbase;
  152. _WPRTLINK extern sapp<int>  _WCNEAR setfill;
  153. _WPRTLINK extern sapp<long> _WCNEAR setiosflags;
  154. _WPRTLINK extern sapp<int>  _WCNEAR setprecision;
  155. _WPRTLINK extern sapp<int>  _WCNEAR setw;
  156. #endif
  157.  
  158. // define some compatibility macros for legacy code
  159. #define SMANIP(__Typ)    smanip<__Typ>
  160. #define SAPP(__Typ)    sapp<__Typ>
  161. #define IMANIP(__Typ)    imanip<__Typ>
  162. #define IAPP(__Typ)    iapp<__Typ>
  163. #define OMANIP(__Typ)    omanip<__Typ>
  164. #define OAPP(__Typ)    oapp<__Typ>
  165. #define IOMANIP(__Typ)    iomanip<__Typ>
  166. #define IOAPP(__Typ)    ioapp<__Typ>
  167.  
  168. #define SMANIP_define(__Typ)
  169. #define IOMANIPdeclare(__Typ)
  170.  
  171. #endif
  172.