epoc32/include/stdapis/stlportv5/iomanip
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     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 #ifdef _STLP_PRAGMA_ONCE
    28 #  pragma once
    29 #endif
    30 
    31 #include <stl/_ioserr.h>
    32 #include <stl/_istream.h>              // includes <ostream> and <ios>
    33 
    34 _STLP_BEGIN_NAMESPACE
    35 
    36 //----------------------------------------------------------------------
    37 // Machinery for defining manipulators.
    38 
    39 // Class that calls one of ios_base's single-argument member functions.
    40 template <class _Arg>
    41 struct _Ios_Manip_1 {
    42    typedef _Arg (ios_base::*__f_ptr_type)(_Arg);
    43 
    44   _Ios_Manip_1(__f_ptr_type __f, const _Arg& __arg)
    45     : _M_f(__f), _M_arg(__arg) {}
    46 
    47   void operator()(ios_base& __ios) const
    48   { (__ios.*_M_f)(_M_arg); }
    49 
    50   __f_ptr_type _M_f;
    51   _Arg _M_arg;
    52 };
    53 
    54 // Class that calls one of ios_base's two-argument member functions.
    55 struct _Ios_Setf_Manip {
    56   ios_base::fmtflags _M_flag;
    57   ios_base::fmtflags _M_mask;
    58   bool _M_two_args;
    59 
    60   _Ios_Setf_Manip(ios_base::fmtflags __f)
    61     : _M_flag(__f), _M_mask(0), _M_two_args(false) {}
    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   void operator()(ios_base& __ios) const {
    67     if (_M_two_args)
    68       __ios.setf(_M_flag, _M_mask);
    69     else
    70       __ios.setf(_M_flag);
    71   }
    72 };
    73 
    74 
    75 template <class _CharT, class _Traits, class _Arg>
    76 inline basic_istream<_CharT, _Traits>& _STLP_CALL
    77 operator>>(basic_istream<_CharT, _Traits>& __istr,
    78            const _Ios_Manip_1<_Arg>& __f) {
    79   __f(__istr);
    80   return __istr;
    81 }
    82 
    83 template <class _CharT, class _Traits, class _Arg>
    84 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
    85 operator<<(basic_ostream<_CharT, _Traits>& __os,
    86            const _Ios_Manip_1<_Arg>& __f) {
    87   __f(__os);
    88   return __os;
    89 }
    90 
    91 template <class _CharT, class _Traits>
    92 inline basic_istream<_CharT, _Traits>& _STLP_CALL
    93 operator>>(basic_istream<_CharT, _Traits>& __istr, const _Ios_Setf_Manip& __f) {
    94   __f(__istr);
    95   return __istr;
    96 }
    97 
    98 template <class _CharT, class _Traits>
    99 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   100 operator<<(basic_ostream<_CharT, _Traits>& __os, const _Ios_Setf_Manip& __f) {
   101   __f(__os);
   102   return __os;
   103 }
   104 
   105 //----------------------------------------------------------------------
   106 // The ios_base manipulators.
   107 inline _Ios_Setf_Manip  _STLP_CALL resetiosflags(ios_base::fmtflags __mask)
   108 { return _Ios_Setf_Manip(0, __mask); }
   109 
   110 inline _Ios_Setf_Manip _STLP_CALL setiosflags(ios_base::fmtflags __flag)
   111 { return _Ios_Setf_Manip(__flag); }
   112 
   113 inline _Ios_Setf_Manip _STLP_CALL setbase(int __n) {
   114   ios_base::fmtflags __base = __n == 8  ? ios_base::oct :
   115                               __n == 10 ? ios_base::dec :
   116                               __n == 16 ? ios_base::hex :
   117                               ios_base::fmtflags(0);
   118   return _Ios_Setf_Manip(__base, ios_base::basefield);
   119 }
   120 
   121 inline _Ios_Manip_1<streamsize> _STLP_CALL
   122 setprecision(int __n) {
   123   _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::precision;
   124   return _Ios_Manip_1<streamsize>(__f, __n);
   125 }
   126 
   127 inline _Ios_Manip_1<streamsize>  _STLP_CALL
   128 setw(int __n) {
   129   _Ios_Manip_1<streamsize>::__f_ptr_type __f = &ios_base::width;  
   130   return _Ios_Manip_1<streamsize>(__f, __n);
   131 }
   132 
   133 //----------------------------------------------------------------------
   134 // setfill, a manipulator that operates on basic_ios<> instead of ios_base.
   135 
   136 template <class _CharT>
   137 struct _Setfill_Manip {
   138   _Setfill_Manip(_CharT __c) : _M_c(__c) {}
   139   _CharT _M_c;
   140 };
   141 
   142 template <class _CharT, class _CharT2, class _Traits>
   143 inline basic_ostream<_CharT, _Traits>& _STLP_CALL
   144 operator<<(basic_ostream<_CharT, _Traits>& __os,
   145            const _Setfill_Manip<_CharT2>& __m) {
   146   __os.fill(__m._M_c);
   147   return __os;
   148 }
   149 
   150 template <class _CharT, class _CharT2, class _Traits>
   151 inline basic_istream<_CharT, _Traits>& _STLP_CALL
   152 operator>>(basic_istream<_CharT, _Traits>& __is,
   153            const _Setfill_Manip<_CharT2>& __m) {
   154   __is.fill(__m._M_c);
   155   return __is;
   156 }
   157 
   158 template <class _CharT>
   159 inline _Setfill_Manip<_CharT> _STLP_CALL
   160 setfill(_CharT __c) {
   161   return _Setfill_Manip<_CharT>(__c);
   162 }
   163 
   164 _STLP_END_NAMESPACE
   165 
   166 #if (_STLP_OUTERMOST_HEADER_ID == 0x1030)
   167 #  include <stl/_epilog.h>
   168 #  undef _STLP_OUTERMOST_HEADER_ID
   169 #endif
   170 
   171 #endif /* _STLP_IOMANIP */
   172 
   173 // Local Variables:
   174 // mode:C++
   175 // End: