]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/std_iomanip.h
include: New directory.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / std_iomanip.h
1 // Standard stream manipulators -*- C++ -*-
2
3 // Copyright (C) 1997-1999 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 #ifndef _CPP_IOMANIP
35 #define _CPP_IOMANIP 1
36
37 #include <bits/c++config.h>
38 #include <bits/std_istream.h>
39 #include <bits/std_functional.h>
40
41 namespace std {
42
43 struct _Resetiosflags { ios_base::fmtflags _M_mask; };
44
45 inline _Resetiosflags
46 resetiosflags(ios_base::fmtflags __mask)
47 {
48 _Resetiosflags __x;
49 __x._M_mask = __mask;
50 return __x;
51 }
52
53 template <class _CharT, class _Traits>
54 basic_istream<_CharT,_Traits>&
55 operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f)
56 {
57 __is.setf(ios_base::fmtflags(0), __f._M_mask);
58 return __is;
59 }
60
61 template <class _CharT, class _Traits>
62 basic_ostream<_CharT,_Traits>&
63 operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f)
64 {
65 __os.setf(ios_base::fmtflags(0), __f._M_mask);
66 return __os;
67 }
68
69
70 struct _Setiosflags { ios_base::fmtflags _M_mask; };
71
72 inline _Setiosflags
73 setiosflags (ios_base::fmtflags __mask)
74 {
75 _Setiosflags __x;
76 __x._M_mask = __mask;
77 return __x;
78 }
79
80 template <class _CharT, class _Traits>
81 basic_istream<_CharT,_Traits>&
82 operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f)
83 {
84 __is.setf(__f._M_mask);
85 return __is;
86 }
87
88 template <class _CharT, class _Traits>
89 basic_ostream<_CharT,_Traits>&
90 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f)
91 {
92 __os.setf(__f._M_mask);
93 return __os;
94 }
95
96
97 struct _Setbase { int _M_base; };
98
99 inline _Setbase
100 setbase (int __base)
101 {
102 _Setbase __x;
103 __x._M_base = __base;
104 return __x;
105 }
106
107 template <class _CharT, class _Traits>
108 basic_istream<_CharT,_Traits>&
109 operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f)
110 {
111 __is.setf(__f._M_base == 8 ? ios_base::oct :
112 __f._M_base == 10 ? ios_base::dec :
113 __f._M_base == 16 ? ios_base::hex :
114 ios_base::fmtflags(0), ios_base::basefield);
115 return __is;
116 }
117
118 template <class _CharT, class _Traits>
119 basic_ostream<_CharT,_Traits>&
120 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f)
121 {
122 __os.setf(__f._M_base == 8 ? ios_base::oct :
123 __f._M_base == 10 ? ios_base::dec :
124 __f._M_base == 16 ? ios_base::hex :
125 ios_base::fmtflags(0), ios_base::basefield);
126 return __os;
127 }
128
129
130 template<class _CharT>
131 struct _Setfill { _CharT _M_c; };
132
133 template<class _CharT>
134 _Setfill<_CharT>
135 setfill(_CharT __c)
136 {
137 _Setfill<_CharT> __x;
138 __x._M_c = __c;
139 return __x;
140 }
141
142 template <class _CharT, class _Traits>
143 basic_istream<_CharT,_Traits>&
144 operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f)
145 {
146 __is.fill(__f._M_c);
147 return __is;
148 }
149
150 template <class _CharT, class _Traits>
151 basic_ostream<_CharT,_Traits>&
152 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f)
153 {
154 __os.fill(__f._M_c);
155 return __os;
156 }
157
158
159 struct _Setprecision { int _M_n; };
160
161 inline _Setprecision
162 setprecision(int __n)
163 {
164 _Setprecision __x;
165 __x._M_n = __n;
166 return __x;
167 }
168
169 template <class _CharT, class _Traits>
170 basic_istream<_CharT,_Traits>&
171 operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f)
172 {
173 __is.precision(__f._M_n);
174 return __is;
175 }
176
177 template <class _CharT, class _Traits>
178 basic_ostream<_CharT,_Traits>&
179 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f)
180 {
181 __os.precision(__f._M_n);
182 return __os;
183 }
184
185
186 struct _Setw { int _M_n; };
187
188 inline _Setw
189 setw(int __n)
190 {
191 _Setw __x;
192 __x._M_n = __n;
193 return __x;
194 }
195
196 template <class _CharT, class _Traits>
197 basic_istream<_CharT,_Traits>&
198 operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f)
199 {
200 __is.width(__f._M_n);
201 return __is;
202 }
203
204 template <class _CharT, class _Traits>
205 basic_ostream<_CharT,_Traits>&
206 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f)
207 {
208 __os.width(__f._M_n);
209 return __os;
210 }
211
212 } // namespace std
213
214 #endif /* __IOMANIP */
215
216
217
218
219