1*404b540aSrobert // Standard stream manipulators -*- C++ -*- 2*404b540aSrobert 3*404b540aSrobert // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2005 4*404b540aSrobert // Free Software Foundation, Inc. 5*404b540aSrobert // 6*404b540aSrobert // This file is part of the GNU ISO C++ Library. This library is free 7*404b540aSrobert // software; you can redistribute it and/or modify it under the 8*404b540aSrobert // terms of the GNU General Public License as published by the 9*404b540aSrobert // Free Software Foundation; either version 2, or (at your option) 10*404b540aSrobert // any later version. 11*404b540aSrobert 12*404b540aSrobert // This library is distributed in the hope that it will be useful, 13*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of 14*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*404b540aSrobert // GNU General Public License for more details. 16*404b540aSrobert 17*404b540aSrobert // You should have received a copy of the GNU General Public License along 18*404b540aSrobert // with this library; see the file COPYING. If not, write to the Free 19*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20*404b540aSrobert // USA. 21*404b540aSrobert 22*404b540aSrobert // As a special exception, you may use this file as part of a free software 23*404b540aSrobert // library without restriction. Specifically, if other files instantiate 24*404b540aSrobert // templates or use macros or inline functions from this file, or you compile 25*404b540aSrobert // this file and link it with other files to produce an executable, this 26*404b540aSrobert // file does not by itself cause the resulting executable to be covered by 27*404b540aSrobert // the GNU General Public License. This exception does not however 28*404b540aSrobert // invalidate any other reasons why the executable file might be covered by 29*404b540aSrobert // the GNU General Public License. 30*404b540aSrobert 31*404b540aSrobert /** @file iomanip 32*404b540aSrobert * This is a Standard C++ Library header. 33*404b540aSrobert */ 34*404b540aSrobert 35*404b540aSrobert // 36*404b540aSrobert // ISO C++ 14882: 27.6.3 Standard manipulators 37*404b540aSrobert // 38*404b540aSrobert 39*404b540aSrobert #ifndef _GLIBCXX_IOMANIP 40*404b540aSrobert #define _GLIBCXX_IOMANIP 1 41*404b540aSrobert 42*404b540aSrobert #pragma GCC system_header 43*404b540aSrobert 44*404b540aSrobert #include <bits/c++config.h> 45*404b540aSrobert #include <istream> 46*404b540aSrobert #include <functional> 47*404b540aSrobert 48*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std) 49*404b540aSrobert 50*404b540aSrobert // [27.6.3] standard manipulators 51*404b540aSrobert // Also see DR 183. 52*404b540aSrobert 53*404b540aSrobert struct _Resetiosflags { ios_base::fmtflags _M_mask; }; 54*404b540aSrobert 55*404b540aSrobert /** 56*404b540aSrobert * @brief Manipulator for @c setf. 57*404b540aSrobert * @param mask A format flags mask. 58*404b540aSrobert * 59*404b540aSrobert * Sent to a stream object, this manipulator resets the specified flags, 60*404b540aSrobert * via @e stream.setf(0,mask). 61*404b540aSrobert */ 62*404b540aSrobert inline _Resetiosflags resetiosflags(ios_base::fmtflags __mask)63*404b540aSrobert resetiosflags(ios_base::fmtflags __mask) 64*404b540aSrobert { 65*404b540aSrobert _Resetiosflags __x; 66*404b540aSrobert __x._M_mask = __mask; 67*404b540aSrobert return __x; 68*404b540aSrobert } 69*404b540aSrobert 70*404b540aSrobert template<typename _CharT, typename _Traits> 71*404b540aSrobert inline basic_istream<_CharT,_Traits>& 72*404b540aSrobert operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f) 73*404b540aSrobert { 74*404b540aSrobert __is.setf(ios_base::fmtflags(0), __f._M_mask); 75*404b540aSrobert return __is; 76*404b540aSrobert } 77*404b540aSrobert 78*404b540aSrobert template<typename _CharT, typename _Traits> 79*404b540aSrobert inline basic_ostream<_CharT,_Traits>& 80*404b540aSrobert operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f) 81*404b540aSrobert { 82*404b540aSrobert __os.setf(ios_base::fmtflags(0), __f._M_mask); 83*404b540aSrobert return __os; 84*404b540aSrobert } 85*404b540aSrobert 86*404b540aSrobert 87*404b540aSrobert struct _Setiosflags { ios_base::fmtflags _M_mask; }; 88*404b540aSrobert 89*404b540aSrobert /** 90*404b540aSrobert * @brief Manipulator for @c setf. 91*404b540aSrobert * @param mask A format flags mask. 92*404b540aSrobert * 93*404b540aSrobert * Sent to a stream object, this manipulator sets the format flags 94*404b540aSrobert * to @a mask. 95*404b540aSrobert */ 96*404b540aSrobert inline _Setiosflags setiosflags(ios_base::fmtflags __mask)97*404b540aSrobert setiosflags(ios_base::fmtflags __mask) 98*404b540aSrobert { 99*404b540aSrobert _Setiosflags __x; 100*404b540aSrobert __x._M_mask = __mask; 101*404b540aSrobert return __x; 102*404b540aSrobert } 103*404b540aSrobert 104*404b540aSrobert template<typename _CharT, typename _Traits> 105*404b540aSrobert inline basic_istream<_CharT,_Traits>& 106*404b540aSrobert operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f) 107*404b540aSrobert { 108*404b540aSrobert __is.setf(__f._M_mask); 109*404b540aSrobert return __is; 110*404b540aSrobert } 111*404b540aSrobert 112*404b540aSrobert template<typename _CharT, typename _Traits> 113*404b540aSrobert inline basic_ostream<_CharT,_Traits>& 114*404b540aSrobert operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f) 115*404b540aSrobert { 116*404b540aSrobert __os.setf(__f._M_mask); 117*404b540aSrobert return __os; 118*404b540aSrobert } 119*404b540aSrobert 120*404b540aSrobert 121*404b540aSrobert struct _Setbase { int _M_base; }; 122*404b540aSrobert 123*404b540aSrobert /** 124*404b540aSrobert * @brief Manipulator for @c setf. 125*404b540aSrobert * @param base A numeric base. 126*404b540aSrobert * 127*404b540aSrobert * Sent to a stream object, this manipulator changes the 128*404b540aSrobert * @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base 129*404b540aSrobert * is 8, 10, or 16, accordingly, and to 0 if @a base is any other value. 130*404b540aSrobert */ 131*404b540aSrobert inline _Setbase setbase(int __base)132*404b540aSrobert setbase(int __base) 133*404b540aSrobert { 134*404b540aSrobert _Setbase __x; 135*404b540aSrobert __x._M_base = __base; 136*404b540aSrobert return __x; 137*404b540aSrobert } 138*404b540aSrobert 139*404b540aSrobert template<typename _CharT, typename _Traits> 140*404b540aSrobert inline basic_istream<_CharT,_Traits>& 141*404b540aSrobert operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f) 142*404b540aSrobert { 143*404b540aSrobert __is.setf(__f._M_base == 8 ? ios_base::oct : 144*404b540aSrobert __f._M_base == 10 ? ios_base::dec : 145*404b540aSrobert __f._M_base == 16 ? ios_base::hex : 146*404b540aSrobert ios_base::fmtflags(0), ios_base::basefield); 147*404b540aSrobert return __is; 148*404b540aSrobert } 149*404b540aSrobert 150*404b540aSrobert template<typename _CharT, typename _Traits> 151*404b540aSrobert inline basic_ostream<_CharT,_Traits>& 152*404b540aSrobert operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f) 153*404b540aSrobert { 154*404b540aSrobert __os.setf(__f._M_base == 8 ? ios_base::oct : 155*404b540aSrobert __f._M_base == 10 ? ios_base::dec : 156*404b540aSrobert __f._M_base == 16 ? ios_base::hex : 157*404b540aSrobert ios_base::fmtflags(0), ios_base::basefield); 158*404b540aSrobert return __os; 159*404b540aSrobert } 160*404b540aSrobert 161*404b540aSrobert 162*404b540aSrobert template<typename _CharT> 163*404b540aSrobert struct _Setfill { _CharT _M_c; }; 164*404b540aSrobert 165*404b540aSrobert /** 166*404b540aSrobert * @brief Manipulator for @c fill. 167*404b540aSrobert * @param c The new fill character. 168*404b540aSrobert * 169*404b540aSrobert * Sent to a stream object, this manipulator calls @c fill(c) for that 170*404b540aSrobert * object. 171*404b540aSrobert */ 172*404b540aSrobert template<typename _CharT> 173*404b540aSrobert inline _Setfill<_CharT> setfill(_CharT __c)174*404b540aSrobert setfill(_CharT __c) 175*404b540aSrobert { 176*404b540aSrobert _Setfill<_CharT> __x; 177*404b540aSrobert __x._M_c = __c; 178*404b540aSrobert return __x; 179*404b540aSrobert } 180*404b540aSrobert 181*404b540aSrobert template<typename _CharT, typename _Traits> 182*404b540aSrobert inline basic_istream<_CharT,_Traits>& 183*404b540aSrobert operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f) 184*404b540aSrobert { 185*404b540aSrobert __is.fill(__f._M_c); 186*404b540aSrobert return __is; 187*404b540aSrobert } 188*404b540aSrobert 189*404b540aSrobert template<typename _CharT, typename _Traits> 190*404b540aSrobert inline basic_ostream<_CharT,_Traits>& 191*404b540aSrobert operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f) 192*404b540aSrobert { 193*404b540aSrobert __os.fill(__f._M_c); 194*404b540aSrobert return __os; 195*404b540aSrobert } 196*404b540aSrobert 197*404b540aSrobert 198*404b540aSrobert struct _Setprecision { int _M_n; }; 199*404b540aSrobert 200*404b540aSrobert /** 201*404b540aSrobert * @brief Manipulator for @c precision. 202*404b540aSrobert * @param n The new precision. 203*404b540aSrobert * 204*404b540aSrobert * Sent to a stream object, this manipulator calls @c precision(n) for 205*404b540aSrobert * that object. 206*404b540aSrobert */ 207*404b540aSrobert inline _Setprecision setprecision(int __n)208*404b540aSrobert setprecision(int __n) 209*404b540aSrobert { 210*404b540aSrobert _Setprecision __x; 211*404b540aSrobert __x._M_n = __n; 212*404b540aSrobert return __x; 213*404b540aSrobert } 214*404b540aSrobert 215*404b540aSrobert template<typename _CharT, typename _Traits> 216*404b540aSrobert inline basic_istream<_CharT,_Traits>& 217*404b540aSrobert operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f) 218*404b540aSrobert { 219*404b540aSrobert __is.precision(__f._M_n); 220*404b540aSrobert return __is; 221*404b540aSrobert } 222*404b540aSrobert 223*404b540aSrobert template<typename _CharT, typename _Traits> 224*404b540aSrobert inline basic_ostream<_CharT,_Traits>& 225*404b540aSrobert operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f) 226*404b540aSrobert { 227*404b540aSrobert __os.precision(__f._M_n); 228*404b540aSrobert return __os; 229*404b540aSrobert } 230*404b540aSrobert 231*404b540aSrobert 232*404b540aSrobert struct _Setw { int _M_n; }; 233*404b540aSrobert 234*404b540aSrobert /** 235*404b540aSrobert * @brief Manipulator for @c width. 236*404b540aSrobert * @param n The new width. 237*404b540aSrobert * 238*404b540aSrobert * Sent to a stream object, this manipulator calls @c width(n) for 239*404b540aSrobert * that object. 240*404b540aSrobert */ 241*404b540aSrobert inline _Setw setw(int __n)242*404b540aSrobert setw(int __n) 243*404b540aSrobert { 244*404b540aSrobert _Setw __x; 245*404b540aSrobert __x._M_n = __n; 246*404b540aSrobert return __x; 247*404b540aSrobert } 248*404b540aSrobert 249*404b540aSrobert template<typename _CharT, typename _Traits> 250*404b540aSrobert inline basic_istream<_CharT,_Traits>& 251*404b540aSrobert operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f) 252*404b540aSrobert { 253*404b540aSrobert __is.width(__f._M_n); 254*404b540aSrobert return __is; 255*404b540aSrobert } 256*404b540aSrobert 257*404b540aSrobert template<typename _CharT, typename _Traits> 258*404b540aSrobert inline basic_ostream<_CharT,_Traits>& 259*404b540aSrobert operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f) 260*404b540aSrobert { 261*404b540aSrobert __os.width(__f._M_n); 262*404b540aSrobert return __os; 263*404b540aSrobert } 264*404b540aSrobert 265*404b540aSrobert // Inhibit implicit instantiations for required instantiations, 266*404b540aSrobert // which are defined via explicit instantiations elsewhere. 267*404b540aSrobert // NB: This syntax is a GNU extension. 268*404b540aSrobert #if _GLIBCXX_EXTERN_TEMPLATE 269*404b540aSrobert extern template ostream& operator<<(ostream&, _Setfill<char>); 270*404b540aSrobert extern template ostream& operator<<(ostream&, _Setiosflags); 271*404b540aSrobert extern template ostream& operator<<(ostream&, _Resetiosflags); 272*404b540aSrobert extern template ostream& operator<<(ostream&, _Setbase); 273*404b540aSrobert extern template ostream& operator<<(ostream&, _Setprecision); 274*404b540aSrobert extern template ostream& operator<<(ostream&, _Setw); 275*404b540aSrobert extern template istream& operator>>(istream&, _Setfill<char>); 276*404b540aSrobert extern template istream& operator>>(istream&, _Setiosflags); 277*404b540aSrobert extern template istream& operator>>(istream&, _Resetiosflags); 278*404b540aSrobert extern template istream& operator>>(istream&, _Setbase); 279*404b540aSrobert extern template istream& operator>>(istream&, _Setprecision); 280*404b540aSrobert extern template istream& operator>>(istream&, _Setw); 281*404b540aSrobert 282*404b540aSrobert #ifdef _GLIBCXX_USE_WCHAR_T 283*404b540aSrobert extern template wostream& operator<<(wostream&, _Setfill<wchar_t>); 284*404b540aSrobert extern template wostream& operator<<(wostream&, _Setiosflags); 285*404b540aSrobert extern template wostream& operator<<(wostream&, _Resetiosflags); 286*404b540aSrobert extern template wostream& operator<<(wostream&, _Setbase); 287*404b540aSrobert extern template wostream& operator<<(wostream&, _Setprecision); 288*404b540aSrobert extern template wostream& operator<<(wostream&, _Setw); 289*404b540aSrobert extern template wistream& operator>>(wistream&, _Setfill<wchar_t>); 290*404b540aSrobert extern template wistream& operator>>(wistream&, _Setiosflags); 291*404b540aSrobert extern template wistream& operator>>(wistream&, _Resetiosflags); 292*404b540aSrobert extern template wistream& operator>>(wistream&, _Setbase); 293*404b540aSrobert extern template wistream& operator>>(wistream&, _Setprecision); 294*404b540aSrobert extern template wistream& operator>>(wistream&, _Setw); 295*404b540aSrobert #endif 296*404b540aSrobert #endif 297*404b540aSrobert 298*404b540aSrobert _GLIBCXX_END_NAMESPACE 299*404b540aSrobert 300*404b540aSrobert #endif /* _GLIBCXX_IOMANIP */ 301