home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / iomanip < prev    next >
Text File  |  2001-05-15  |  5KB  |  191 lines

  1. /*
  2.  * Copyright (c) 1999
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Copyright (c) 1999 
  6.  * Boris Fomitchev
  7.  *
  8.  * This material is provided "as is", with absolutely no warranty expressed
  9.  * or implied. Any use is at your own risk.
  10.  *
  11.  * Permission to use or copy this software for any purpose is hereby granted 
  12.  * without fee, provided the above notices are retained on all copies.
  13.  * Permission to modify the code and to distribute modified code is granted,
  14.  * provided the above notices are retained, and a notice that the code was
  15.  * modified is included with the above copyright notice.
  16.  *
  17.  */ 
  18.  
  19. #ifndef _STLP_IOMANIP
  20. #define _STLP_IOMANIP
  21.  
  22. # ifndef _STLP_OUTERMOST_HEADER_ID
  23. #  define _STLP_OUTERMOST_HEADER_ID 0x1030
  24. #  include <stl/_prolog.h>
  25. # endif
  26.  
  27. # if defined ( _STLP_OWN_IOSTREAMS )
  28.  
  29. #  include <stl/_istream.h>              // Includes <ostream> and <ios>
  30.  
  31. _STLP_BEGIN_NAMESPACE
  32.  
  33. //----------------------------------------------------------------------
  34. // Machinery for defining manipulators.
  35.  
  36. // Class that calls one of ios_base's single-argument member functions.
  37. template <class _Arg>
  38. struct _Ios_Manip_1 {
  39.    typedef _Arg (ios_base::*__f_ptr_type)(_Arg);
  40.  
  41.   _Ios_Manip_1(__f_ptr_type __f, const _Arg& __arg)  
  42.     : _M_f(__f), _M_arg(__arg)
  43.     {}
  44.   
  45.   void operator()(ios_base& __ios) const {
  46.     (__ios.*_M_f)(_M_arg);
  47.   }
  48.  
  49.   __f_ptr_type _M_f;
  50.   _Arg _M_arg;
  51. };
  52.  
  53. // Class that calls one of ios_base's two-argument member functions.
  54. struct _Ios_Setf_Manip {
  55.   ios_base::fmtflags _M_flag;
  56.   ios_base::fmtflags _M_mask;
  57.   bool _M_two_args;
  58.  
  59.   _Ios_Setf_Manip(ios_base::fmtflags __f)
  60.     : _M_flag(__f), _M_mask(0), _M_two_args(false)
  61.     {}
  62.  
  63.   _Ios_Setf_Manip(ios_base::fmtflags __f, ios_base::fmtflags __m)
  64.     : _M_flag(__f), _M_mask(__m), _M_two_args(true)
  65.     {}
  66.  
  67.   void operator()(ios_base& __ios) const {
  68.     if (_M_two_args)
  69.       __ios.setf(_M_flag, _M_mask);
  70.     else
  71.       __ios.setf(_M_flag);
  72.   }
  73. };
  74.  
  75.  
  76. template <class _CharT, class _Traits, class _Arg>
  77. inline basic_istream<_CharT, _Traits>& _STLP_CALL
  78. operator>>(basic_istream<_CharT, _Traits>& __in,
  79.            const _Ios_Manip_1<_Arg>& __f)
  80. {
  81.   __f(__in);
  82.   return __in;
  83. }
  84.  
  85. template <class _CharT, class _Traits, class _Arg>
  86. inline basic_ostream<_CharT, _Traits>& _STLP_CALL
  87. operator<<(basic_ostream<_CharT, _Traits>& __os,
  88.            const _Ios_Manip_1<_Arg>& __f)
  89. {
  90.   __f(__os);
  91.   return __os;
  92. }
  93.  
  94. template <class _CharT, class _Traits>
  95. inline basic_istream<_CharT, _Traits>& _STLP_CALL
  96. operator>>(basic_istream<_CharT, _Traits>& __in, const _Ios_Setf_Manip& __f)
  97. {
  98.   __f(__in);
  99.   return __in;
  100. }
  101.  
  102. template <class _CharT, class _Traits>
  103. inline basic_ostream<_CharT, _Traits>& _STLP_CALL
  104. operator<<(basic_ostream<_CharT, _Traits>& __os, const _Ios_Setf_Manip& __f)
  105.  
  106. {
  107.   __f(__os);
  108.   return __os;
  109. }
  110.  
  111. //----------------------------------------------------------------------
  112. // The ios_base manipulators.
  113.  
  114. inline _Ios_Setf_Manip  _STLP_CALL resetiosflags(ios_base::fmtflags __mask) {
  115.   return _Ios_Setf_Manip(0, __mask);
  116. }
  117.  
  118. inline _Ios_Setf_Manip _STLP_CALL setiosflags(ios_base::fmtflags __flag) {
  119.   return _Ios_Setf_Manip(__flag);
  120. }
  121.  
  122. inline _Ios_Setf_Manip _STLP_CALL setbase(int __n) {
  123.   ios_base::fmtflags __base = __n == 8  ? ios_base::oct :
  124.                               __n == 10 ? ios_base::dec :
  125.                               __n == 16 ? ios_base::hex :
  126.                               ios_base::fmtflags(0);
  127.   return _Ios_Setf_Manip(__base, ios_base::basefield);
  128. }
  129.  
  130. inline _Ios_Manip_1<streamsize> _STLP_CALL 
  131. setprecision(int __n) {
  132.   _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::precision;
  133.   return _Ios_Manip_1<streamsize>(__f, __n);
  134. }
  135.  
  136. inline _Ios_Manip_1<streamsize>  _STLP_CALL
  137. setw(int __n) {
  138.   _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::width;    
  139.   return _Ios_Manip_1<streamsize>(__f, __n);
  140. }
  141.  
  142. //----------------------------------------------------------------------
  143. // setfill, a manipulator that operates on basic_ios<> instead of ios_base.
  144.  
  145. template <class _CharT>
  146. struct _Setfill_Manip {
  147.   _Setfill_Manip(_CharT __c) : _M_c(__c) {}
  148.   _CharT _M_c;
  149. };
  150.  
  151. template <class _CharT, class _CharT2, class _Traits>
  152. inline basic_ostream<_CharT, _Traits>& _STLP_CALL 
  153. operator<<(basic_ostream<_CharT, _Traits>& __os, 
  154.            const _Setfill_Manip<_CharT2>& __m)
  155. {
  156.   __os.fill(__m._M_c);
  157.   return __os;
  158. }
  159.  
  160. template <class _CharT, class _CharT2, class _Traits>
  161. inline basic_istream<_CharT, _Traits>& _STLP_CALL 
  162. operator>>(basic_istream<_CharT, _Traits>& __is, 
  163.            const _Setfill_Manip<_CharT2>& __m)
  164. {
  165.   __is.fill(__m._M_c);
  166.   return __is;
  167. }
  168.  
  169. template <class _CharT>
  170. inline _Setfill_Manip<_CharT> _STLP_CALL 
  171. setfill(_CharT __c) {
  172.   return _Setfill_Manip<_CharT>(__c);
  173. }
  174.  
  175. _STLP_END_NAMESPACE
  176.  
  177. # elif !defined (_STLP_USE_NO_IOSTREAMS)
  178. #  include <wrap_std/iomanip>
  179. # endif
  180.  
  181. # if (_STLP_OUTERMOST_HEADER_ID == 0x1030)
  182. #  include <stl/_epilog.h>
  183. #  undef _STLP_OUTERMOST_HEADER_ID
  184. # endif
  185.  
  186. #endif /* _STLP_IOMANIP */
  187.  
  188. // Local Variables:
  189. // mode:C++
  190. // End:
  191.