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