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