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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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.
39 #ifndef _GLIBCXX_IOMANIP
40 #define _GLIBCXX_IOMANIP 1
42 #pragma GCC system_header
44 #include <bits/c++config.h>
50 // [27.6.3] standard manipulators
53 struct _Resetiosflags
{ ios_base::fmtflags _M_mask
; };
56 * @brief Manipulator for @c setf.
57 * @param mask A format flags mask.
59 * Sent to a stream object, this manipulator resets the specified flags,
60 * via @e stream.setf(0,mask).
63 resetiosflags(ios_base::fmtflags __mask
)
70 template<typename _CharT
, typename _Traits
>
71 inline basic_istream
<_CharT
,_Traits
>&
72 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Resetiosflags __f
)
74 __is
.setf(ios_base::fmtflags(0), __f
._M_mask
);
78 template<typename _CharT
, typename _Traits
>
79 inline basic_ostream
<_CharT
,_Traits
>&
80 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Resetiosflags __f
)
82 __os
.setf(ios_base::fmtflags(0), __f
._M_mask
);
87 struct _Setiosflags
{ ios_base::fmtflags _M_mask
; };
90 * @brief Manipulator for @c setf.
91 * @param mask A format flags mask.
93 * Sent to a stream object, this manipulator sets the format flags
97 setiosflags(ios_base::fmtflags __mask
)
100 __x
._M_mask
= __mask
;
104 template<typename _CharT
, typename _Traits
>
105 inline basic_istream
<_CharT
,_Traits
>&
106 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setiosflags __f
)
108 __is
.setf(__f
._M_mask
);
112 template<typename _CharT
, typename _Traits
>
113 inline basic_ostream
<_CharT
,_Traits
>&
114 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setiosflags __f
)
116 __os
.setf(__f
._M_mask
);
121 struct _Setbase
{ int _M_base
; };
124 * @brief Manipulator for @c setf.
125 * @param base A numeric base.
127 * Sent to a stream object, this manipulator changes the
128 * @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base
129 * is 8, 10, or 16, accordingly, and to 0 if @a base is any other value.
135 __x
._M_base
= __base
;
139 template<typename _CharT
, typename _Traits
>
140 inline basic_istream
<_CharT
,_Traits
>&
141 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setbase __f
)
143 __is
.setf(__f
._M_base
== 8 ? ios_base::oct
:
144 __f
._M_base
== 10 ? ios_base::dec
:
145 __f
._M_base
== 16 ? ios_base::hex
:
146 ios_base::fmtflags(0), ios_base::basefield
);
150 template<typename _CharT
, typename _Traits
>
151 inline basic_ostream
<_CharT
,_Traits
>&
152 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setbase __f
)
154 __os
.setf(__f
._M_base
== 8 ? ios_base::oct
:
155 __f
._M_base
== 10 ? ios_base::dec
:
156 __f
._M_base
== 16 ? ios_base::hex
:
157 ios_base::fmtflags(0), ios_base::basefield
);
162 template<typename _CharT
>
163 struct _Setfill
{ _CharT _M_c
; };
166 * @brief Manipulator for @c fill.
167 * @param c The new fill character.
169 * Sent to a stream object, this manipulator calls @c fill(c) for that
172 template<typename _CharT
>
173 inline _Setfill
<_CharT
>
176 _Setfill
<_CharT
> __x
;
181 template<typename _CharT
, typename _Traits
>
182 inline basic_istream
<_CharT
,_Traits
>&
183 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setfill
<_CharT
> __f
)
189 template<typename _CharT
, typename _Traits
>
190 inline basic_ostream
<_CharT
,_Traits
>&
191 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setfill
<_CharT
> __f
)
198 struct _Setprecision
{ int _M_n
; };
201 * @brief Manipulator for @c precision.
202 * @param n The new precision.
204 * Sent to a stream object, this manipulator calls @c precision(n) for
208 setprecision(int __n
)
215 template<typename _CharT
, typename _Traits
>
216 inline basic_istream
<_CharT
,_Traits
>&
217 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setprecision __f
)
219 __is
.precision(__f
._M_n
);
223 template<typename _CharT
, typename _Traits
>
224 inline basic_ostream
<_CharT
,_Traits
>&
225 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setprecision __f
)
227 __os
.precision(__f
._M_n
);
232 struct _Setw
{ int _M_n
; };
235 * @brief Manipulator for @c width.
236 * @param n The new width.
238 * Sent to a stream object, this manipulator calls @c width(n) for
249 template<typename _CharT
, typename _Traits
>
250 inline basic_istream
<_CharT
,_Traits
>&
251 operator>>(basic_istream
<_CharT
,_Traits
>& __is
, _Setw __f
)
253 __is
.width(__f
._M_n
);
257 template<typename _CharT
, typename _Traits
>
258 inline basic_ostream
<_CharT
,_Traits
>&
259 operator<<(basic_ostream
<_CharT
,_Traits
>& __os
, _Setw __f
)
261 __os
.width(__f
._M_n
);
265 // Inhibit implicit instantiations for required instantiations,
266 // which are defined via explicit instantiations elsewhere.
267 // NB: This syntax is a GNU extension.
268 #if _GLIBCXX_EXTERN_TEMPLATE
269 extern template ostream
& operator<<(ostream
&, _Setfill
<char>);
270 extern template ostream
& operator<<(ostream
&, _Setiosflags
);
271 extern template ostream
& operator<<(ostream
&, _Resetiosflags
);
272 extern template ostream
& operator<<(ostream
&, _Setbase
);
273 extern template ostream
& operator<<(ostream
&, _Setprecision
);
274 extern template ostream
& operator<<(ostream
&, _Setw
);
275 extern template istream
& operator>>(istream
&, _Setfill
<char>);
276 extern template istream
& operator>>(istream
&, _Setiosflags
);
277 extern template istream
& operator>>(istream
&, _Resetiosflags
);
278 extern template istream
& operator>>(istream
&, _Setbase
);
279 extern template istream
& operator>>(istream
&, _Setprecision
);
280 extern template istream
& operator>>(istream
&, _Setw
);
282 #ifdef _GLIBCXX_USE_WCHAR_T
283 extern template wostream
& operator<<(wostream
&, _Setfill
<wchar_t>);
284 extern template wostream
& operator<<(wostream
&, _Setiosflags
);
285 extern template wostream
& operator<<(wostream
&, _Resetiosflags
);
286 extern template wostream
& operator<<(wostream
&, _Setbase
);
287 extern template wostream
& operator<<(wostream
&, _Setprecision
);
288 extern template wostream
& operator<<(wostream
&, _Setw
);
289 extern template wistream
& operator>>(wistream
&, _Setfill
<wchar_t>);
290 extern template wistream
& operator>>(wistream
&, _Setiosflags
);
291 extern template wistream
& operator>>(wistream
&, _Resetiosflags
);
292 extern template wistream
& operator>>(wistream
&, _Setbase
);
293 extern template wistream
& operator>>(wistream
&, _Setprecision
);
294 extern template wistream
& operator>>(wistream
&, _Setw
);
299 #endif /* _GLIBCXX_IOMANIP */