Mark as release
[official-gcc.git] / libstdc++-v3 / include / std / std_iomanip.h
blob13b21d579bd9bac7bb19db7719a62cbed3157df1
1 // Standard stream manipulators -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2005
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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,
20 // USA.
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.
31 /** @file iomanip
32 * This is a Standard C++ Library header.
36 // ISO C++ 14882: 27.6.3 Standard manipulators
39 #ifndef _GLIBCXX_IOMANIP
40 #define _GLIBCXX_IOMANIP 1
42 #pragma GCC system_header
44 #include <bits/c++config.h>
45 #include <istream>
46 #include <functional>
48 _GLIBCXX_BEGIN_NAMESPACE(std)
50 // [27.6.3] standard manipulators
51 // Also see DR 183.
53 struct _Resetiosflags { ios_base::fmtflags _M_mask; };
55 /**
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).
62 inline _Resetiosflags
63 resetiosflags(ios_base::fmtflags __mask)
65 _Resetiosflags __x;
66 __x._M_mask = __mask;
67 return __x;
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);
75 return __is;
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);
83 return __os;
87 struct _Setiosflags { ios_base::fmtflags _M_mask; };
89 /**
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
94 * to @a mask.
96 inline _Setiosflags
97 setiosflags(ios_base::fmtflags __mask)
99 _Setiosflags __x;
100 __x._M_mask = __mask;
101 return __x;
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);
109 return __is;
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);
117 return __os;
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.
131 inline _Setbase
132 setbase(int __base)
134 _Setbase __x;
135 __x._M_base = __base;
136 return __x;
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);
147 return __is;
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);
158 return __os;
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
170 * object.
172 template<typename _CharT>
173 inline _Setfill<_CharT>
174 setfill(_CharT __c)
176 _Setfill<_CharT> __x;
177 __x._M_c = __c;
178 return __x;
181 template<typename _CharT, typename _Traits>
182 inline basic_istream<_CharT,_Traits>&
183 operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f)
185 __is.fill(__f._M_c);
186 return __is;
189 template<typename _CharT, typename _Traits>
190 inline basic_ostream<_CharT,_Traits>&
191 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f)
193 __os.fill(__f._M_c);
194 return __os;
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
205 * that object.
207 inline _Setprecision
208 setprecision(int __n)
210 _Setprecision __x;
211 __x._M_n = __n;
212 return __x;
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);
220 return __is;
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);
228 return __os;
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
239 * that object.
241 inline _Setw
242 setw(int __n)
244 _Setw __x;
245 __x._M_n = __n;
246 return __x;
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);
254 return __is;
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);
262 return __os;
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);
295 #endif
296 #endif
298 _GLIBCXX_END_NAMESPACE
300 #endif /* _GLIBCXX_IOMANIP */