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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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.
00037  */
00038 
00039 #ifndef _GLIBCXX_IOMANIP
00040 #define _GLIBCXX_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   // [27.6.3] standard manipulators
00051   // Also see DR 183.
00052 
00053   struct _Resetiosflags { ios_base::fmtflags _M_mask; };
00054 
00055   /**
00056    *  @brief  Manipulator for @c setf.
00057    *  @param  mask  A format flags mask.
00058    *
00059    *  Sent to a stream object, this manipulator resets the specified flags,
00060    *  via @e stream.setf(0,mask).
00061   */
00062   inline _Resetiosflags 
00063   resetiosflags(ios_base::fmtflags __mask)
00064   { 
00065     _Resetiosflags __x; 
00066     __x._M_mask = __mask; 
00067     return __x; 
00068   }
00069 
00070   template<typename _CharT, typename _Traits>
00071     inline basic_istream<_CharT,_Traits>& 
00072     operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f)
00073     { 
00074       __is.setf(ios_base::fmtflags(0), __f._M_mask); 
00075       return __is; 
00076     }
00077 
00078   template<typename _CharT, typename _Traits>
00079     inline basic_ostream<_CharT,_Traits>& 
00080     operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f)
00081     { 
00082       __os.setf(ios_base::fmtflags(0), __f._M_mask); 
00083       return __os; 
00084     }
00085 
00086 
00087   struct _Setiosflags { ios_base::fmtflags _M_mask; };
00088 
00089   /**
00090    *  @brief  Manipulator for @c setf.
00091    *  @param  mask  A format flags mask.
00092    *
00093    *  Sent to a stream object, this manipulator sets the format flags
00094    *  to @a mask.
00095   */
00096   inline _Setiosflags 
00097   setiosflags(ios_base::fmtflags __mask)
00098   { 
00099     _Setiosflags __x; 
00100     __x._M_mask = __mask; 
00101     return __x; 
00102   }
00103 
00104   template<typename _CharT, typename _Traits>
00105     inline basic_istream<_CharT,_Traits>& 
00106     operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f)
00107     { 
00108       __is.setf(__f._M_mask); 
00109       return __is; 
00110     }
00111 
00112   template<typename _CharT, typename _Traits>
00113     inline basic_ostream<_CharT,_Traits>& 
00114     operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f)
00115     { 
00116       __os.setf(__f._M_mask); 
00117       return __os; 
00118     }
00119 
00120 
00121   struct _Setbase { int _M_base; };
00122 
00123   /**
00124    *  @brief  Manipulator for @c setf.
00125    *  @param  base  A numeric base.
00126    *
00127    *  Sent to a stream object, this manipulator changes the
00128    *  @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base
00129    *  is 8, 10, or 16, accordingly, and to 0 if @a base is any other value.
00130   */
00131   inline _Setbase 
00132   setbase(int __base)
00133   { 
00134     _Setbase __x; 
00135     __x._M_base = __base; 
00136     return __x; 
00137   }
00138 
00139   template<typename _CharT, typename _Traits>
00140     inline basic_istream<_CharT,_Traits>& 
00141     operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f)
00142     {
00143       __is.setf(__f._M_base ==  8 ? ios_base::oct : 
00144           __f._M_base == 10 ? ios_base::dec : 
00145           __f._M_base == 16 ? ios_base::hex : 
00146           ios_base::fmtflags(0), ios_base::basefield);
00147       return __is; 
00148     }
00149   
00150   template<typename _CharT, typename _Traits>
00151     inline basic_ostream<_CharT,_Traits>& 
00152     operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f)
00153     {
00154       __os.setf(__f._M_base ==  8 ? ios_base::oct : 
00155         __f._M_base == 10 ? ios_base::dec : 
00156         __f._M_base == 16 ? ios_base::hex : 
00157         ios_base::fmtflags(0), ios_base::basefield);
00158       return __os; 
00159     }
00160   
00161 
00162   template<typename _CharT> 
00163     struct _Setfill { _CharT _M_c; };
00164 
00165   /**
00166    *  @brief  Manipulator for @c fill.
00167    *  @param  c  The new fill character.
00168    *
00169    *  Sent to a stream object, this manipulator calls @c fill(c) for that
00170    *  object.
00171   */
00172   template<typename _CharT> 
00173     inline _Setfill<_CharT> 
00174     setfill(_CharT __c)
00175     { 
00176       _Setfill<_CharT> __x; 
00177       __x._M_c = __c; 
00178       return __x; 
00179     }
00180 
00181   template<typename _CharT, typename _Traits>
00182     inline basic_istream<_CharT,_Traits>& 
00183     operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f)
00184     { 
00185       __is.fill(__f._M_c); 
00186       return __is; 
00187     }
00188 
00189   template<typename _CharT, typename _Traits>
00190     inline basic_ostream<_CharT,_Traits>& 
00191     operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f)
00192     { 
00193       __os.fill(__f._M_c); 
00194       return __os; 
00195     }
00196 
00197 
00198   struct _Setprecision { int _M_n; };
00199 
00200   /**
00201    *  @brief  Manipulator for @c precision.
00202    *  @param  n  The new precision.
00203    *
00204    *  Sent to a stream object, this manipulator calls @c precision(n) for
00205    *  that object.
00206   */
00207   inline _Setprecision 
00208   setprecision(int __n)
00209   { 
00210     _Setprecision __x; 
00211     __x._M_n = __n; 
00212     return __x; 
00213   }
00214 
00215   template<typename _CharT, typename _Traits>
00216     inline basic_istream<_CharT,_Traits>& 
00217     operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f)
00218     { 
00219       __is.precision(__f._M_n); 
00220       return __is; 
00221     }
00222 
00223   template<typename _CharT, typename _Traits>
00224     inline basic_ostream<_CharT,_Traits>& 
00225     operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f)
00226     { 
00227       __os.precision(__f._M_n); 
00228       return __os; 
00229     }
00230 
00231 
00232   struct _Setw { int _M_n; };
00233 
00234   /**
00235    *  @brief  Manipulator for @c width.
00236    *  @param  n  The new width.
00237    *
00238    *  Sent to a stream object, this manipulator calls @c width(n) for
00239    *  that object.
00240   */
00241   inline _Setw 
00242   setw(int __n)
00243   { 
00244     _Setw __x; 
00245     __x._M_n = __n; 
00246     return __x; 
00247   }
00248 
00249   template<typename _CharT, typename _Traits>
00250     inline basic_istream<_CharT,_Traits>& 
00251     operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f)
00252     { 
00253       __is.width(__f._M_n); 
00254       return __is; 
00255     }
00256 
00257   template<typename _CharT, typename _Traits>
00258     inline basic_ostream<_CharT,_Traits>& 
00259     operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f)
00260     { 
00261       __os.width(__f._M_n); 
00262       return __os; 
00263     }
00264 
00265   // Inhibit implicit instantiations for required instantiations,
00266   // which are defined via explicit instantiations elsewhere.  
00267   // NB:  This syntax is a GNU extension.
00268 #if _GLIBCXX_EXTERN_TEMPLATE
00269   extern template ostream& operator<<(ostream&, _Setfill<char>);
00270   extern template ostream& operator<<(ostream&, _Setiosflags);
00271   extern template ostream& operator<<(ostream&, _Resetiosflags);
00272   extern template ostream& operator<<(ostream&, _Setbase);
00273   extern template ostream& operator<<(ostream&, _Setprecision);
00274   extern template ostream& operator<<(ostream&, _Setw);
00275   extern template istream& operator>>(istream&, _Setfill<char>);
00276   extern template istream& operator>>(istream&, _Setiosflags);
00277   extern template istream& operator>>(istream&, _Resetiosflags);
00278   extern template istream& operator>>(istream&, _Setbase);
00279   extern template istream& operator>>(istream&, _Setprecision);
00280   extern template istream& operator>>(istream&, _Setw);
00281 
00282 #ifdef _GLIBCXX_USE_WCHAR_T
00283   extern template wostream& operator<<(wostream&, _Setfill<wchar_t>);
00284   extern template wostream& operator<<(wostream&, _Setiosflags);
00285   extern template wostream& operator<<(wostream&, _Resetiosflags);
00286   extern template wostream& operator<<(wostream&, _Setbase);
00287   extern template wostream& operator<<(wostream&, _Setprecision);
00288   extern template wostream& operator<<(wostream&, _Setw);
00289   extern template wistream& operator>>(wistream&, _Setfill<wchar_t>);
00290   extern template wistream& operator>>(wistream&, _Setiosflags);
00291   extern template wistream& operator>>(wistream&, _Resetiosflags);
00292   extern template wistream& operator>>(wistream&, _Setbase);
00293   extern template wistream& operator>>(wistream&, _Setprecision);
00294   extern template wistream& operator>>(wistream&, _Setw);
00295 #endif
00296 #endif
00297 } // namespace std
00298 
00299 #endif /* _GLIBCXX_IOMANIP */

Generated on Thu Nov 1 17:35:58 2007 for libstdc++ by  doxygen 1.5.1