/home/ntakagi/work/STLport-5.1.5/stlport/iomanip

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 #ifndef _STLP_IOMANIP
00020 #define _STLP_IOMANIP
00021 
00022 #ifndef _STLP_OUTERMOST_HEADER_ID
00023 #  define _STLP_OUTERMOST_HEADER_ID 0x1030
00024 #  include <stl/_prolog.h>
00025 #endif
00026 
00027 #ifdef _STLP_PRAGMA_ONCE
00028 #  pragma once
00029 #endif
00030 
00031 #include <stl/_ioserr.h>
00032 #include <stl/_istream.h>              // Includes <ostream> and <ios>
00033 
00034 _STLP_BEGIN_NAMESPACE
00035 
00036 //----------------------------------------------------------------------
00037 // Machinery for defining manipulators.
00038 
00039 // Class that calls one of ios_base's single-argument member functions.
00040 template <class _Arg>
00041 struct _Ios_Manip_1 {
00042    typedef _Arg (ios_base::*__f_ptr_type)(_Arg);
00043 
00044   _Ios_Manip_1(__f_ptr_type __f, const _Arg& __arg)
00045     : _M_f(__f), _M_arg(__arg) {}
00046 
00047   void operator()(ios_base& __ios) const
00048   { (__ios.*_M_f)(_M_arg); }
00049 
00050   __f_ptr_type _M_f;
00051   _Arg _M_arg;
00052 };
00053 
00054 // Class that calls one of ios_base's two-argument member functions.
00055 struct _Ios_Setf_Manip {
00056   ios_base::fmtflags _M_flag;
00057   ios_base::fmtflags _M_mask;
00058   bool _M_two_args;
00059 
00060   _Ios_Setf_Manip(ios_base::fmtflags __f)
00061     : _M_flag(__f), _M_mask(0), _M_two_args(false) {}
00062 
00063   _Ios_Setf_Manip(ios_base::fmtflags __f, ios_base::fmtflags __m)
00064     : _M_flag(__f), _M_mask(__m), _M_two_args(true) {}
00065 
00066   void operator()(ios_base& __ios) const {
00067     if (_M_two_args)
00068       __ios.setf(_M_flag, _M_mask);
00069     else
00070       __ios.setf(_M_flag);
00071   }
00072 };
00073 
00074 
00075 template <class _CharT, class _Traits, class _Arg>
00076 inline basic_istream<_CharT, _Traits>& _STLP_CALL
00077 operator>>(basic_istream<_CharT, _Traits>& __istr,
00078            const _Ios_Manip_1<_Arg>& __f) {
00079   __f(__istr);
00080   return __istr;
00081 }
00082 
00083 template <class _CharT, class _Traits, class _Arg>
00084 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00085 operator<<(basic_ostream<_CharT, _Traits>& __os,
00086            const _Ios_Manip_1<_Arg>& __f) {
00087   __f(__os);
00088   return __os;
00089 }
00090 
00091 template <class _CharT, class _Traits>
00092 inline basic_istream<_CharT, _Traits>& _STLP_CALL
00093 operator>>(basic_istream<_CharT, _Traits>& __istr, const _Ios_Setf_Manip& __f) {
00094   __f(__istr);
00095   return __istr;
00096 }
00097 
00098 template <class _CharT, class _Traits>
00099 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00100 operator<<(basic_ostream<_CharT, _Traits>& __os, const _Ios_Setf_Manip& __f) {
00101   __f(__os);
00102   return __os;
00103 }
00104 
00105 //----------------------------------------------------------------------
00106 // The ios_base manipulators.
00107 inline _Ios_Setf_Manip  _STLP_CALL resetiosflags(ios_base::fmtflags __mask)
00108 { return _Ios_Setf_Manip(0, __mask); }
00109 
00110 inline _Ios_Setf_Manip _STLP_CALL setiosflags(ios_base::fmtflags __flag)
00111 { return _Ios_Setf_Manip(__flag); }
00112 
00113 inline _Ios_Setf_Manip _STLP_CALL setbase(int __n) {
00114   ios_base::fmtflags __base = __n == 8  ? ios_base::oct :
00115                               __n == 10 ? ios_base::dec :
00116                               __n == 16 ? ios_base::hex :
00117                               ios_base::fmtflags(0);
00118   return _Ios_Setf_Manip(__base, ios_base::basefield);
00119 }
00120 
00121 inline _Ios_Manip_1<streamsize> _STLP_CALL
00122 setprecision(int __n) {
00123   _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::precision;
00124   return _Ios_Manip_1<streamsize>(__f, __n);
00125 }
00126 
00127 inline _Ios_Manip_1<streamsize>  _STLP_CALL
00128 setw(int __n) {
00129   _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::width;  
00130   return _Ios_Manip_1<streamsize>(__f, __n);
00131 }
00132 
00133 //----------------------------------------------------------------------
00134 // setfill, a manipulator that operates on basic_ios<> instead of ios_base.
00135 
00136 template <class _CharT>
00137 struct _Setfill_Manip {
00138   _Setfill_Manip(_CharT __c) : _M_c(__c) {}
00139   _CharT _M_c;
00140 };
00141 
00142 template <class _CharT, class _CharT2, class _Traits>
00143 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
00144 operator<<(basic_ostream<_CharT, _Traits>& __os,
00145            const _Setfill_Manip<_CharT2>& __m) {
00146   __os.fill(__m._M_c);
00147   return __os;
00148 }
00149 
00150 template <class _CharT, class _CharT2, class _Traits>
00151 inline basic_istream<_CharT, _Traits>& _STLP_CALL
00152 operator>>(basic_istream<_CharT, _Traits>& __is,
00153            const _Setfill_Manip<_CharT2>& __m) {
00154   __is.fill(__m._M_c);
00155   return __is;
00156 }
00157 
00158 template <class _CharT>
00159 inline _Setfill_Manip<_CharT> _STLP_CALL
00160 setfill(_CharT __c) {
00161   return _Setfill_Manip<_CharT>(__c);
00162 }
00163 
00164 _STLP_END_NAMESPACE
00165 
00166 #if (_STLP_OUTERMOST_HEADER_ID == 0x1030)
00167 #  include <stl/_epilog.h>
00168 #  undef _STLP_OUTERMOST_HEADER_ID
00169 #endif
00170 
00171 #endif /* _STLP_IOMANIP */
00172 
00173 // Local Variables:
00174 // mode:C++
00175 // End:



Generated on Mon Mar 10 15:32:17 2008 by  doxygen 1.5.1