iomanip

Go to the documentation of this file.
00001 // Standard stream manipulators -*- C++ -*- 00002 00003 // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // You should have received a copy of the GNU General Public License along 00018 // with this library; see the file COPYING. If not, write to the Free 00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00020 // USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 // 00032 // ISO C++ 14882: 27.6.3 Standard manipulators 00033 // 00034 00035 /** @file iomanip 00036 * This is a Standard C++ Library header. You should @c #include this header 00037 * in your programs, rather than any of the "st[dl]_*.h" implementation files. 00038 */ 00039 00040 #ifndef _CPP_IOMANIP 00041 #define _CPP_IOMANIP 1 00042 00043 #pragma GCC system_header 00044 00045 #include <bits/c++config.h> 00046 #include <istream> 00047 #include <functional> 00048 00049 namespace std 00050 { 00051 // [27.6.3] standard manipulators 00052 // Also see DR 183. 00053 00054 struct _Resetiosflags { ios_base::fmtflags _M_mask; }; 00055 00056 /** 00057 * @brief Manipulator for @c setf. 00058 * @param mask A format flags mask. 00059 * 00060 * Sent to a stream object, this manipulator resets the specified flags, 00061 * via @e stream.setf(0,mask). 00062 */ 00063 inline _Resetiosflags 00064 resetiosflags(ios_base::fmtflags __mask) 00065 { 00066 _Resetiosflags __x; 00067 __x._M_mask = __mask; 00068 return __x; 00069 } 00070 00071 template<typename _CharT, typename _Traits> 00072 inline basic_istream<_CharT,_Traits>& 00073 operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f) 00074 { 00075 __is.setf(ios_base::fmtflags(0), __f._M_mask); 00076 return __is; 00077 } 00078 00079 template<typename _CharT, typename _Traits> 00080 inline basic_ostream<_CharT,_Traits>& 00081 operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f) 00082 { 00083 __os.setf(ios_base::fmtflags(0), __f._M_mask); 00084 return __os; 00085 } 00086 00087 00088 struct _Setiosflags { ios_base::fmtflags _M_mask; }; 00089 00090 /** 00091 * @brief Manipulator for @c setf. 00092 * @param mask A format flags mask. 00093 * 00094 * Sent to a stream object, this manipulator sets the format flags 00095 * to @a mask. 00096 */ 00097 inline _Setiosflags 00098 setiosflags(ios_base::fmtflags __mask) 00099 { 00100 _Setiosflags __x; 00101 __x._M_mask = __mask; 00102 return __x; 00103 } 00104 00105 template<typename _CharT, typename _Traits> 00106 inline basic_istream<_CharT,_Traits>& 00107 operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f) 00108 { 00109 __is.setf(__f._M_mask); 00110 return __is; 00111 } 00112 00113 template<typename _CharT, typename _Traits> 00114 inline basic_ostream<_CharT,_Traits>& 00115 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f) 00116 { 00117 __os.setf(__f._M_mask); 00118 return __os; 00119 } 00120 00121 00122 struct _Setbase { int _M_base; }; 00123 00124 /** 00125 * @brief Manipulator for @c setf. 00126 * @param base A numeric base. 00127 * 00128 * Sent to a stream object, this manipulator changes the 00129 * @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base 00130 * is 8, 10, or 16, accordingly, and to 0 if @a base is any other value. 00131 */ 00132 inline _Setbase 00133 setbase(int __base) 00134 { 00135 _Setbase __x; 00136 __x._M_base = __base; 00137 return __x; 00138 } 00139 00140 template<typename _CharT, typename _Traits> 00141 inline basic_istream<_CharT,_Traits>& 00142 operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f) 00143 { 00144 __is.setf(__f._M_base == 8 ? ios_base::oct : 00145 __f._M_base == 10 ? ios_base::dec : 00146 __f._M_base == 16 ? ios_base::hex : 00147 ios_base::fmtflags(0), ios_base::basefield); 00148 return __is; 00149 } 00150 00151 template<typename _CharT, typename _Traits> 00152 inline basic_ostream<_CharT,_Traits>& 00153 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f) 00154 { 00155 __os.setf(__f._M_base == 8 ? ios_base::oct : 00156 __f._M_base == 10 ? ios_base::dec : 00157 __f._M_base == 16 ? ios_base::hex : 00158 ios_base::fmtflags(0), ios_base::basefield); 00159 return __os; 00160 } 00161 00162 00163 template<typename _CharT> 00164 struct _Setfill { _CharT _M_c; }; 00165 00166 /** 00167 * @brief Manipulator for @c fill. 00168 * @param c The new fill character. 00169 * 00170 * Sent to a stream object, this manipulator calls @c fill(c) for that 00171 * object. 00172 */ 00173 template<typename _CharT> 00174 inline _Setfill<_CharT> 00175 setfill(_CharT __c) 00176 { 00177 _Setfill<_CharT> __x; 00178 __x._M_c = __c; 00179 return __x; 00180 } 00181 00182 template<typename _CharT, typename _Traits> 00183 inline basic_istream<_CharT,_Traits>& 00184 operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f) 00185 { 00186 __is.fill(__f._M_c); 00187 return __is; 00188 } 00189 00190 template<typename _CharT, typename _Traits> 00191 inline basic_ostream<_CharT,_Traits>& 00192 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f) 00193 { 00194 __os.fill(__f._M_c); 00195 return __os; 00196 } 00197 00198 00199 struct _Setprecision { int _M_n; }; 00200 00201 /** 00202 * @brief Manipulator for @c precision. 00203 * @param n The new precision. 00204 * 00205 * Sent to a stream object, this manipulator calls @c precision(n) for 00206 * that object. 00207 */ 00208 inline _Setprecision 00209 setprecision(int __n) 00210 { 00211 _Setprecision __x; 00212 __x._M_n = __n; 00213 return __x; 00214 } 00215 00216 template<typename _CharT, typename _Traits> 00217 inline basic_istream<_CharT,_Traits>& 00218 operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f) 00219 { 00220 __is.precision(__f._M_n); 00221 return __is; 00222 } 00223 00224 template<typename _CharT, typename _Traits> 00225 inline basic_ostream<_CharT,_Traits>& 00226 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f) 00227 { 00228 __os.precision(__f._M_n); 00229 return __os; 00230 } 00231 00232 00233 struct _Setw { int _M_n; }; 00234 00235 /** 00236 * @brief Manipulator for @c width. 00237 * @param n The new width. 00238 * 00239 * Sent to a stream object, this manipulator calls @c width(n) for 00240 * that object. 00241 */ 00242 inline _Setw 00243 setw(int __n) 00244 { 00245 _Setw __x; 00246 __x._M_n = __n; 00247 return __x; 00248 } 00249 00250 template<typename _CharT, typename _Traits> 00251 inline basic_istream<_CharT,_Traits>& 00252 operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f) 00253 { 00254 __is.width(__f._M_n); 00255 return __is; 00256 } 00257 00258 template<typename _CharT, typename _Traits> 00259 inline basic_ostream<_CharT,_Traits>& 00260 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f) 00261 { 00262 __os.width(__f._M_n); 00263 return __os; 00264 } 00265 00266 // Inhibit implicit instantiations for required instantiations, 00267 // which are defined via explicit instantiations elsewhere. 00268 // NB: This syntax is a GNU extension. 00269 #if _GLIBCPP_EXTERN_TEMPLATE 00270 extern template ostream& operator<<(ostream&, _Setfill<char>); 00271 extern template ostream& operator<<(ostream&, _Setiosflags); 00272 extern template ostream& operator<<(ostream&, _Resetiosflags); 00273 extern template ostream& operator<<(ostream&, _Setbase); 00274 extern template ostream& operator<<(ostream&, _Setprecision); 00275 extern template ostream& operator<<(ostream&, _Setw); 00276 extern template istream& operator>>(istream&, _Setfill<char>); 00277 extern template istream& operator>>(istream&, _Setiosflags); 00278 extern template istream& operator>>(istream&, _Resetiosflags); 00279 extern template istream& operator>>(istream&, _Setbase); 00280 extern template istream& operator>>(istream&, _Setprecision); 00281 extern template istream& operator>>(istream&, _Setw); 00282 00283 #ifdef _GLIBCPP_USE_WCHAR_T 00284 extern template wostream& operator<<(wostream&, _Setfill<wchar_t>); 00285 extern template wostream& operator<<(wostream&, _Setiosflags); 00286 extern template wostream& operator<<(wostream&, _Resetiosflags); 00287 extern template wostream& operator<<(wostream&, _Setbase); 00288 extern template wostream& operator<<(wostream&, _Setprecision); 00289 extern template wostream& operator<<(wostream&, _Setw); 00290 extern template wistream& operator>>(wistream&, _Setfill<wchar_t>); 00291 extern template wistream& operator>>(wistream&, _Setiosflags); 00292 extern template wistream& operator>>(wistream&, _Resetiosflags); 00293 extern template wistream& operator>>(wistream&, _Setbase); 00294 extern template wistream& operator>>(wistream&, _Setprecision); 00295 extern template wistream& operator>>(wistream&, _Setw); 00296 #endif 00297 #endif 00298 } // namespace std 00299 00300 #endif

Generated on Sun Sep 19 16:33:50 2004 for libstdc++-v3 Source by doxygen 1.3.8