2002-11-21 Phil Edwards <pme@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / include / std / std_iomanip.h
blob26756a8041cc93cf5c3744d530dd36a6bbc15d07
1 // Standard stream manipulators -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 27.6.3 Standard manipulators
34 /** @file iomanip
35 * This is a Standard C++ Library header. You should @c #include this header
36 * in your programs, rather than any of the "st[dl]_*.h" implementation files.
39 #ifndef _CPP_IOMANIP
40 #define _CPP_IOMANIP 1
42 #pragma GCC system_header
44 #include <bits/c++config.h>
45 #include <istream>
46 #include <functional>
48 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 extern template ostream& operator<<(ostream&, _Setfill<char>);
269 extern template ostream& operator<<(ostream&, _Setiosflags);
270 extern template ostream& operator<<(ostream&, _Resetiosflags);
271 extern template ostream& operator<<(ostream&, _Setbase);
272 extern template ostream& operator<<(ostream&, _Setprecision);
273 extern template ostream& operator<<(ostream&, _Setw);
274 extern template istream& operator>>(istream&, _Setfill<char>);
275 extern template istream& operator>>(istream&, _Setiosflags);
276 extern template istream& operator>>(istream&, _Resetiosflags);
277 extern template istream& operator>>(istream&, _Setbase);
278 extern template istream& operator>>(istream&, _Setprecision);
279 extern template istream& operator>>(istream&, _Setw);
281 #ifdef _GLIBCPP_USE_WCHAR_T
282 extern template wostream& operator<<(wostream&, _Setfill<wchar_t>);
283 extern template wostream& operator<<(wostream&, _Setiosflags);
284 extern template wostream& operator<<(wostream&, _Resetiosflags);
285 extern template wostream& operator<<(wostream&, _Setbase);
286 extern template wostream& operator<<(wostream&, _Setprecision);
287 extern template wostream& operator<<(wostream&, _Setw);
288 extern template wistream& operator>>(wistream&, _Setfill<wchar_t>);
289 extern template wistream& operator>>(wistream&, _Setiosflags);
290 extern template wistream& operator>>(wistream&, _Resetiosflags);
291 extern template wistream& operator>>(wistream&, _Setbase);
292 extern template wistream& operator>>(wistream&, _Setprecision);
293 extern template wistream& operator>>(wistream&, _Setw);
294 #endif
295 } // namespace std
297 #endif