1 // Standard stream manipulators -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 27.6.3 Standard manipulators
36 * This is a Standard C++ Library header. You should @c #include this header
37 * in your programs, rather than any of the "st[dl]_*.h" implementation files.
40 #ifndef _GLIBCXX_IOMANIP
41 #define _GLIBCXX_IOMANIP 1
43 #pragma GCC system_header
45 #include <bits/c++config.h>
51 // [27.6.3] standard manipulators
54 struct _Resetiosflags
{ ios_base::fmtflags _M_mask
; };
57 * @brief Manipulator for @c setf.
58 * @param mask A format flags mask.
60 * Sent to a stream object, this manipulator resets the specified flags,
61 * via @e stream.setf(0,mask).
64 resetiosflags(ios_base::fmtflags __mask
)
71 template<typename _CharT
, typename _Traits
>
72 inline basic_istream
<_CharT
,_Traits
>&
73 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Resetiosflags __f
)
75 __is
.setf(ios_base::fmtflags(0), __f
._M_mask
);
79 template<typename _CharT
, typename _Traits
>
80 inline basic_ostream
<_CharT
,_Traits
>&
81 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Resetiosflags __f
)
83 __os
.setf(ios_base::fmtflags(0), __f
._M_mask
);
88 struct _Setiosflags
{ ios_base::fmtflags _M_mask
; };
91 * @brief Manipulator for @c setf.
92 * @param mask A format flags mask.
94 * Sent to a stream object, this manipulator sets the format flags
98 setiosflags(ios_base::fmtflags __mask
)
101 __x
._M_mask
= __mask
;
105 template<typename _CharT
, typename _Traits
>
106 inline basic_istream
<_CharT
,_Traits
>&
107 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setiosflags __f
)
109 __is
.setf(__f
._M_mask
);
113 template<typename _CharT
, typename _Traits
>
114 inline basic_ostream
<_CharT
,_Traits
>&
115 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setiosflags __f
)
117 __os
.setf(__f
._M_mask
);
122 struct _Setbase
{ int _M_base
; };
125 * @brief Manipulator for @c setf.
126 * @param base A numeric base.
128 * Sent to a stream object, this manipulator changes the
129 * @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base
130 * is 8, 10, or 16, accordingly, and to 0 if @a base is any other value.
136 __x
._M_base
= __base
;
140 template<typename _CharT
, typename _Traits
>
141 inline basic_istream
<_CharT
,_Traits
>&
142 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setbase __f
)
144 __is
.setf(__f
._M_base
== 8 ? ios_base::oct
:
145 __f
._M_base
== 10 ? ios_base::dec
:
146 __f
._M_base
== 16 ? ios_base::hex
:
147 ios_base::fmtflags(0), ios_base::basefield
);
151 template<typename _CharT
, typename _Traits
>
152 inline basic_ostream
<_CharT
,_Traits
>&
153 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setbase __f
)
155 __os
.setf(__f
._M_base
== 8 ? ios_base::oct
:
156 __f
._M_base
== 10 ? ios_base::dec
:
157 __f
._M_base
== 16 ? ios_base::hex
:
158 ios_base::fmtflags(0), ios_base::basefield
);
163 template<typename _CharT
>
164 struct _Setfill
{ _CharT _M_c
; };
167 * @brief Manipulator for @c fill.
168 * @param c The new fill character.
170 * Sent to a stream object, this manipulator calls @c fill(c) for that
173 template<typename _CharT
>
174 inline _Setfill
<_CharT
>
177 _Setfill
<_CharT
> __x
;
182 template<typename _CharT
, typename _Traits
>
183 inline basic_istream
<_CharT
,_Traits
>&
184 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setfill
<_CharT
> __f
)
190 template<typename _CharT
, typename _Traits
>
191 inline basic_ostream
<_CharT
,_Traits
>&
192 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setfill
<_CharT
> __f
)
199 struct _Setprecision
{ int _M_n
; };
202 * @brief Manipulator for @c precision.
203 * @param n The new precision.
205 * Sent to a stream object, this manipulator calls @c precision(n) for
209 setprecision(int __n
)
216 template<typename _CharT
, typename _Traits
>
217 inline basic_istream
<_CharT
,_Traits
>&
218 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setprecision __f
)
220 __is
.precision(__f
._M_n
);
224 template<typename _CharT
, typename _Traits
>
225 inline basic_ostream
<_CharT
,_Traits
>&
226 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setprecision __f
)
228 __os
.precision(__f
._M_n
);
233 struct _Setw
{ int _M_n
; };
236 * @brief Manipulator for @c width.
237 * @param n The new width.
239 * Sent to a stream object, this manipulator calls @c width(n) for
250 template<typename _CharT
, typename _Traits
>
251 inline basic_istream
<_CharT
,_Traits
>&
252 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setw __f
)
254 __is
.width(__f
._M_n
);
258 template<typename _CharT
, typename _Traits
>
259 inline basic_ostream
<_CharT
,_Traits
>&
260 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setw __f
)
262 __os
.width(__f
._M_n
);
266 // Inhibit implicit instantiations for required instantiations,
267 // which are defined via explicit instantiations elsewhere.
268 // NB: This syntax is a GNU extension.
269 #if _GLIBCXX_EXTERN_TEMPLATE
270 extern template ostream
& operator<<(ostream
&, _Setfill
<char>);
271 extern template ostream
& operator<<(ostream
&, _Setiosflags
);
272 extern template ostream
& operator<<(ostream
&, _Resetiosflags
);
273 extern template ostream
& operator<<(ostream
&, _Setbase
);
274 extern template ostream
& operator<<(ostream
&, _Setprecision
);
275 extern template ostream
& operator<<(ostream
&, _Setw
);
276 extern template istream
& operator>>(istream
&, _Setfill
<char>);
277 extern template istream
& operator>>(istream
&, _Setiosflags
);
278 extern template istream
& operator>>(istream
&, _Resetiosflags
);
279 extern template istream
& operator>>(istream
&, _Setbase
);
280 extern template istream
& operator>>(istream
&, _Setprecision
);
281 extern template istream
& operator>>(istream
&, _Setw
);
283 #ifdef _GLIBCXX_USE_WCHAR_T
284 extern template wostream
& operator<<(wostream
&, _Setfill
<wchar_t>);
285 extern template wostream
& operator<<(wostream
&, _Setiosflags
);
286 extern template wostream
& operator<<(wostream
&, _Resetiosflags
);
287 extern template wostream
& operator<<(wostream
&, _Setbase
);
288 extern template wostream
& operator<<(wostream
&, _Setprecision
);
289 extern template wostream
& operator<<(wostream
&, _Setw
);
290 extern template wistream
& operator>>(wistream
&, _Setfill
<wchar_t>);
291 extern template wistream
& operator>>(wistream
&, _Setiosflags
);
292 extern template wistream
& operator>>(wistream
&, _Resetiosflags
);
293 extern template wistream
& operator>>(wistream
&, _Setbase
);
294 extern template wistream
& operator>>(wistream
&, _Setprecision
);
295 extern template wistream
& operator>>(wistream
&, _Setw
);
300 #endif /* _GLIBCXX_IOMANIP */