# iomanip

Go to the documentation of this file.

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