std_iomanip.h revision 107606
1// Standard stream manipulators -*- C++ -*-
2
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.
10
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.
15
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.
20
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.
29
30//
31// ISO C++ 14882: 27.6.3  Standard manipulators
32//
33
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.
37 */
38
39#ifndef _CPP_IOMANIP
40#define _CPP_IOMANIP 1
41
42#pragma GCC system_header
43
44#include <bits/c++config.h>
45#include <istream>
46#include <functional>
47
48namespace std
49{
50  struct _Resetiosflags { ios_base::fmtflags _M_mask; };
51
52  inline _Resetiosflags
53  resetiosflags(ios_base::fmtflags __mask)
54  {
55    _Resetiosflags __x;
56    __x._M_mask = __mask;
57    return __x;
58  }
59
60  template<typename _CharT, typename _Traits>
61    inline basic_istream<_CharT,_Traits>&
62    operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f)
63    {
64      __is.setf(ios_base::fmtflags(0), __f._M_mask);
65      return __is;
66    }
67
68  template<typename _CharT, typename _Traits>
69    inline basic_ostream<_CharT,_Traits>&
70    operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f)
71    {
72      __os.setf(ios_base::fmtflags(0), __f._M_mask);
73      return __os;
74    }
75
76
77  struct _Setiosflags { ios_base::fmtflags _M_mask; };
78
79  inline _Setiosflags
80  setiosflags(ios_base::fmtflags __mask)
81  {
82    _Setiosflags __x;
83    __x._M_mask = __mask;
84    return __x;
85  }
86
87  template<typename _CharT, typename _Traits>
88    inline basic_istream<_CharT,_Traits>&
89    operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f)
90    {
91      __is.setf(__f._M_mask);
92      return __is;
93    }
94
95  template<typename _CharT, typename _Traits>
96    inline basic_ostream<_CharT,_Traits>&
97    operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f)
98    {
99      __os.setf(__f._M_mask);
100      return __os;
101    }
102
103
104  struct _Setbase { int _M_base; };
105
106  inline _Setbase
107  setbase(int __base)
108  {
109    _Setbase __x;
110    __x._M_base = __base;
111    return __x;
112  }
113
114  template<typename _CharT, typename _Traits>
115    inline basic_istream<_CharT,_Traits>&
116    operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f)
117    {
118      __is.setf(__f._M_base ==  8 ? ios_base::oct :
119	      __f._M_base == 10 ? ios_base::dec :
120	      __f._M_base == 16 ? ios_base::hex :
121	      ios_base::fmtflags(0), ios_base::basefield);
122      return __is;
123    }
124
125  template<typename _CharT, typename _Traits>
126    inline basic_ostream<_CharT,_Traits>&
127    operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f)
128    {
129      __os.setf(__f._M_base ==  8 ? ios_base::oct :
130		__f._M_base == 10 ? ios_base::dec :
131		__f._M_base == 16 ? ios_base::hex :
132		ios_base::fmtflags(0), ios_base::basefield);
133      return __os;
134    }
135
136
137  template<typename _CharT>
138    struct _Setfill { _CharT _M_c; };
139
140  template<typename _CharT>
141    inline _Setfill<_CharT>
142    setfill(_CharT __c)
143    {
144      _Setfill<_CharT> __x;
145      __x._M_c = __c;
146      return __x;
147    }
148
149  template<typename _CharT, typename _Traits>
150    inline basic_istream<_CharT,_Traits>&
151    operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f)
152    {
153      __is.fill(__f._M_c);
154      return __is;
155    }
156
157  template<typename _CharT, typename _Traits>
158    inline basic_ostream<_CharT,_Traits>&
159    operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f)
160    {
161      __os.fill(__f._M_c);
162      return __os;
163    }
164
165
166  struct _Setprecision { int _M_n; };
167
168  inline _Setprecision
169  setprecision(int __n)
170  {
171    _Setprecision __x;
172    __x._M_n = __n;
173    return __x;
174  }
175
176  template<typename _CharT, typename _Traits>
177    inline basic_istream<_CharT,_Traits>&
178    operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f)
179    {
180      __is.precision(__f._M_n);
181      return __is;
182    }
183
184  template<typename _CharT, typename _Traits>
185    inline basic_ostream<_CharT,_Traits>&
186    operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f)
187    {
188      __os.precision(__f._M_n);
189      return __os;
190    }
191
192
193  struct _Setw { int _M_n; };
194
195  inline _Setw
196  setw(int __n)
197  {
198    _Setw __x;
199    __x._M_n = __n;
200    return __x;
201  }
202
203  template<typename _CharT, typename _Traits>
204    inline basic_istream<_CharT,_Traits>&
205    operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f)
206    {
207      __is.width(__f._M_n);
208      return __is;
209    }
210
211  template<typename _CharT, typename _Traits>
212    inline basic_ostream<_CharT,_Traits>&
213    operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f)
214    {
215      __os.width(__f._M_n);
216      return __os;
217    }
218
219  // Inhibit implicit instantiations for required instantiations,
220  // which are defined via explicit instantiations elsewhere.
221  // NB:  This syntax is a GNU extension.
222  extern template ostream& operator<<(ostream&, _Setfill<char>);
223  extern template ostream& operator<<(ostream&, _Setiosflags);
224  extern template ostream& operator<<(ostream&, _Resetiosflags);
225  extern template ostream& operator<<(ostream&, _Setbase);
226  extern template ostream& operator<<(ostream&, _Setprecision);
227  extern template ostream& operator<<(ostream&, _Setw);
228  extern template istream& operator>>(istream&, _Setfill<char>);
229  extern template istream& operator>>(istream&, _Setiosflags);
230  extern template istream& operator>>(istream&, _Resetiosflags);
231  extern template istream& operator>>(istream&, _Setbase);
232  extern template istream& operator>>(istream&, _Setprecision);
233  extern template istream& operator>>(istream&, _Setw);
234
235#ifdef _GLIBCPP_USE_WCHAR_T
236  extern template wostream& operator<<(wostream&, _Setfill<wchar_t>);
237  extern template wostream& operator<<(wostream&, _Setiosflags);
238  extern template wostream& operator<<(wostream&, _Resetiosflags);
239  extern template wostream& operator<<(wostream&, _Setbase);
240  extern template wostream& operator<<(wostream&, _Setprecision);
241  extern template wostream& operator<<(wostream&, _Setw);
242  extern template wistream& operator>>(wistream&, _Setfill<wchar_t>);
243  extern template wistream& operator>>(wistream&, _Setiosflags);
244  extern template wistream& operator>>(wistream&, _Resetiosflags);
245  extern template wistream& operator>>(wistream&, _Setbase);
246  extern template wistream& operator>>(wistream&, _Setprecision);
247  extern template wistream& operator>>(wistream&, _Setw);
248#endif
249} // namespace std
250
251#endif
252