OSDN Git Service

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