sl@0: /* sl@0: * Copyright (c) 1999 sl@0: * Silicon Graphics Computer Systems, Inc. sl@0: * sl@0: * Copyright (c) 1999 sl@0: * Boris Fomitchev sl@0: * sl@0: * This material is provided "as is", with absolutely no warranty expressed sl@0: * or implied. Any use is at your own risk. sl@0: * sl@0: * Permission to use or copy this software for any purpose is hereby granted sl@0: * without fee, provided the above notices are retained on all copies. sl@0: * Permission to modify the code and to distribute modified code is granted, sl@0: * provided the above notices are retained, and a notice that the code was sl@0: * modified is included with the above copyright notice. sl@0: * sl@0: */ sl@0: sl@0: #ifndef _STLP_IOMANIP sl@0: #define _STLP_IOMANIP sl@0: sl@0: #ifndef _STLP_OUTERMOST_HEADER_ID sl@0: # define _STLP_OUTERMOST_HEADER_ID 0x1030 sl@0: # include sl@0: #endif sl@0: sl@0: #ifdef _STLP_PRAGMA_ONCE sl@0: # pragma once sl@0: #endif sl@0: sl@0: #include sl@0: #include // includes and sl@0: sl@0: _STLP_BEGIN_NAMESPACE sl@0: sl@0: //---------------------------------------------------------------------- sl@0: // Machinery for defining manipulators. sl@0: sl@0: // Class that calls one of ios_base's single-argument member functions. sl@0: template sl@0: struct _Ios_Manip_1 { sl@0: typedef _Arg (ios_base::*__f_ptr_type)(_Arg); sl@0: sl@0: _Ios_Manip_1(__f_ptr_type __f, const _Arg& __arg) sl@0: : _M_f(__f), _M_arg(__arg) {} sl@0: sl@0: void operator()(ios_base& __ios) const sl@0: { (__ios.*_M_f)(_M_arg); } sl@0: sl@0: __f_ptr_type _M_f; sl@0: _Arg _M_arg; sl@0: }; sl@0: sl@0: // Class that calls one of ios_base's two-argument member functions. sl@0: struct _Ios_Setf_Manip { sl@0: ios_base::fmtflags _M_flag; sl@0: ios_base::fmtflags _M_mask; sl@0: bool _M_two_args; sl@0: sl@0: _Ios_Setf_Manip(ios_base::fmtflags __f) sl@0: : _M_flag(__f), _M_mask(0), _M_two_args(false) {} sl@0: sl@0: _Ios_Setf_Manip(ios_base::fmtflags __f, ios_base::fmtflags __m) sl@0: : _M_flag(__f), _M_mask(__m), _M_two_args(true) {} sl@0: sl@0: void operator()(ios_base& __ios) const { sl@0: if (_M_two_args) sl@0: __ios.setf(_M_flag, _M_mask); sl@0: else sl@0: __ios.setf(_M_flag); sl@0: } sl@0: }; sl@0: sl@0: sl@0: template sl@0: inline basic_istream<_CharT, _Traits>& _STLP_CALL sl@0: operator>>(basic_istream<_CharT, _Traits>& __istr, sl@0: const _Ios_Manip_1<_Arg>& __f) { sl@0: __f(__istr); sl@0: return __istr; sl@0: } sl@0: sl@0: template sl@0: inline basic_ostream<_CharT, _Traits>& _STLP_CALL sl@0: operator<<(basic_ostream<_CharT, _Traits>& __os, sl@0: const _Ios_Manip_1<_Arg>& __f) { sl@0: __f(__os); sl@0: return __os; sl@0: } sl@0: sl@0: template sl@0: inline basic_istream<_CharT, _Traits>& _STLP_CALL sl@0: operator>>(basic_istream<_CharT, _Traits>& __istr, const _Ios_Setf_Manip& __f) { sl@0: __f(__istr); sl@0: return __istr; sl@0: } sl@0: sl@0: template sl@0: inline basic_ostream<_CharT, _Traits>& _STLP_CALL sl@0: operator<<(basic_ostream<_CharT, _Traits>& __os, const _Ios_Setf_Manip& __f) { sl@0: __f(__os); sl@0: return __os; sl@0: } sl@0: sl@0: //---------------------------------------------------------------------- sl@0: // The ios_base manipulators. sl@0: inline _Ios_Setf_Manip _STLP_CALL resetiosflags(ios_base::fmtflags __mask) sl@0: { return _Ios_Setf_Manip(0, __mask); } sl@0: sl@0: inline _Ios_Setf_Manip _STLP_CALL setiosflags(ios_base::fmtflags __flag) sl@0: { return _Ios_Setf_Manip(__flag); } sl@0: sl@0: inline _Ios_Setf_Manip _STLP_CALL setbase(int __n) { sl@0: ios_base::fmtflags __base = __n == 8 ? ios_base::oct : sl@0: __n == 10 ? ios_base::dec : sl@0: __n == 16 ? ios_base::hex : sl@0: ios_base::fmtflags(0); sl@0: return _Ios_Setf_Manip(__base, ios_base::basefield); sl@0: } sl@0: sl@0: inline _Ios_Manip_1 _STLP_CALL sl@0: setprecision(int __n) { sl@0: _Ios_Manip_1::__f_ptr_type __f = &ios_base::precision; sl@0: return _Ios_Manip_1(__f, __n); sl@0: } sl@0: sl@0: inline _Ios_Manip_1 _STLP_CALL sl@0: setw(int __n) { sl@0: _Ios_Manip_1::__f_ptr_type __f = &ios_base::width; sl@0: return _Ios_Manip_1(__f, __n); sl@0: } sl@0: sl@0: //---------------------------------------------------------------------- sl@0: // setfill, a manipulator that operates on basic_ios<> instead of ios_base. sl@0: sl@0: template sl@0: struct _Setfill_Manip { sl@0: _Setfill_Manip(_CharT __c) : _M_c(__c) {} sl@0: _CharT _M_c; sl@0: }; sl@0: sl@0: template sl@0: inline basic_ostream<_CharT, _Traits>& _STLP_CALL sl@0: operator<<(basic_ostream<_CharT, _Traits>& __os, sl@0: const _Setfill_Manip<_CharT2>& __m) { sl@0: __os.fill(__m._M_c); sl@0: return __os; sl@0: } sl@0: sl@0: template sl@0: inline basic_istream<_CharT, _Traits>& _STLP_CALL sl@0: operator>>(basic_istream<_CharT, _Traits>& __is, sl@0: const _Setfill_Manip<_CharT2>& __m) { sl@0: __is.fill(__m._M_c); sl@0: return __is; sl@0: } sl@0: sl@0: template sl@0: inline _Setfill_Manip<_CharT> _STLP_CALL sl@0: setfill(_CharT __c) { sl@0: return _Setfill_Manip<_CharT>(__c); sl@0: } sl@0: sl@0: _STLP_END_NAMESPACE sl@0: sl@0: #if (_STLP_OUTERMOST_HEADER_ID == 0x1030) sl@0: # include sl@0: # undef _STLP_OUTERMOST_HEADER_ID sl@0: #endif sl@0: sl@0: #endif /* _STLP_IOMANIP */ sl@0: sl@0: // Local Variables: sl@0: // mode:C++ sl@0: // End: