3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
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.
19 #ifndef _STLP_INTERNAL_IOMANIP
20 #define _STLP_INTERNAL_IOMANIP
22 #ifndef _STLP_INTERNAL_ISTREAM
23 # include <stl/_istream.h> // Includes <ostream> and <ios>
28 _STLP_MOVE_TO_PRIV_NAMESPACE
30 //----------------------------------------------------------------------
31 // Machinery for defining manipulators.
33 // Class that calls one of ios_base's single-argument member functions.
36 typedef _Arg (ios_base::*__f_ptr_type
)(_Arg
);
38 _Ios_Manip_1(__f_ptr_type __f
, const _Arg
& __arg
)
39 : _M_f(__f
), _M_arg(__arg
) {}
41 void operator()(ios_base
& __ios
) const
42 { (__ios
.*_M_f
)(_M_arg
); }
48 // Class that calls one of ios_base's two-argument member functions.
49 struct _Ios_Setf_Manip
{
50 ios_base::fmtflags _M_flag
;
51 ios_base::fmtflags _M_mask
;
54 _Ios_Setf_Manip(ios_base::fmtflags __f
)
55 : _M_flag(__f
), _M_mask(0), _M_two_args(false) {}
57 _Ios_Setf_Manip(ios_base::fmtflags __f
, ios_base::fmtflags __m
)
58 : _M_flag(__f
), _M_mask(__m
), _M_two_args(true) {}
60 void operator()(ios_base
& __ios
) const {
62 __ios
.setf(_M_flag
, _M_mask
);
68 _STLP_MOVE_TO_STD_NAMESPACE
70 template <class _CharT
, class _Traits
, class _Arg
>
71 inline basic_istream
<_CharT
, _Traits
>& _STLP_CALL
72 operator>>(basic_istream
<_CharT
, _Traits
>& __istr
,
73 const _STLP_PRIV _Ios_Manip_1
<_Arg
>& __f
) {
78 template <class _CharT
, class _Traits
, class _Arg
>
79 inline basic_ostream
<_CharT
, _Traits
>& _STLP_CALL
80 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
81 const _STLP_PRIV _Ios_Manip_1
<_Arg
>& __f
) {
86 template <class _CharT
, class _Traits
>
87 inline basic_istream
<_CharT
, _Traits
>& _STLP_CALL
88 operator>>(basic_istream
<_CharT
, _Traits
>& __istr
,
89 const _STLP_PRIV _Ios_Setf_Manip
& __f
) {
94 template <class _CharT
, class _Traits
>
95 inline basic_ostream
<_CharT
, _Traits
>& _STLP_CALL
96 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
97 const _STLP_PRIV _Ios_Setf_Manip
& __f
) {
102 //----------------------------------------------------------------------
103 // The ios_base manipulators.
104 inline _STLP_PRIV _Ios_Setf_Manip _STLP_CALL
resetiosflags(ios_base::fmtflags __mask
)
105 { return _STLP_PRIV
_Ios_Setf_Manip(0, __mask
); }
107 inline _STLP_PRIV _Ios_Setf_Manip _STLP_CALL
setiosflags(ios_base::fmtflags __flag
)
108 { return _STLP_PRIV
_Ios_Setf_Manip(__flag
); }
110 inline _STLP_PRIV _Ios_Setf_Manip _STLP_CALL
setbase(int __n
) {
111 ios_base::fmtflags __base
= __n
== 8 ? ios_base::oct
:
112 __n
== 10 ? ios_base::dec
:
113 __n
== 16 ? ios_base::hex
:
114 ios_base::fmtflags(0);
115 return _STLP_PRIV
_Ios_Setf_Manip(__base
, ios_base::basefield
);
118 inline _STLP_PRIV _Ios_Manip_1
<streamsize
> _STLP_CALL
119 setprecision(int __n
) {
120 _STLP_PRIV _Ios_Manip_1
<streamsize
>::__f_ptr_type __f
= &ios_base::precision
;
121 return _STLP_PRIV _Ios_Manip_1
<streamsize
>(__f
, __n
);
124 inline _STLP_PRIV _Ios_Manip_1
<streamsize
> _STLP_CALL
126 _STLP_PRIV _Ios_Manip_1
<streamsize
>::__f_ptr_type __f
= &ios_base::width
;
127 return _STLP_PRIV _Ios_Manip_1
<streamsize
>(__f
, __n
);
130 //----------------------------------------------------------------------
131 // setfill, a manipulator that operates on basic_ios<> instead of ios_base.
133 _STLP_MOVE_TO_PRIV_NAMESPACE
135 template <class _CharT
>
136 struct _Setfill_Manip
{
137 _Setfill_Manip(_CharT __c
) : _M_c(__c
) {}
141 _STLP_MOVE_TO_STD_NAMESPACE
143 template <class _CharT
, class _CharT2
, class _Traits
>
144 inline basic_ostream
<_CharT
, _Traits
>& _STLP_CALL
145 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
146 const _STLP_PRIV _Setfill_Manip
<_CharT2
>& __m
) {
151 template <class _CharT
, class _CharT2
, class _Traits
>
152 inline basic_istream
<_CharT
, _Traits
>& _STLP_CALL
153 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
154 const _STLP_PRIV _Setfill_Manip
<_CharT2
>& __m
) {
159 template <class _CharT
>
160 inline _STLP_PRIV _Setfill_Manip
<_CharT
> _STLP_CALL
setfill(_CharT __c
)
161 { return _STLP_PRIV _Setfill_Manip
<_CharT
>(__c
); }
165 #endif /* _STLP_INTERNAL_IOMANIP */