OpenFOAM logo
Open Source CFD Toolkit

IOmanip.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     IOmanip
00027 
00028 Description
00029     Istream and Ostream manipulators taking arguments.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #ifndef IOmanip_H
00034 #define IOmanip_H
00035 
00036 #include "Istream.H"
00037 #include "Ostream.H"
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 namespace Foam
00042 {
00043 
00044 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
00045 
00046 template<class T> class Smanip;
00047 template<class T> class Imanip;
00048 template<class T> class Omanip;
00049 
00050 template<class T>
00051 inline Istream& operator>>(Istream& is, const Smanip<T>& m);
00052 
00053 template<class T>
00054 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m);
00055 
00056 template<class T>
00057 inline Istream& operator>>(Istream& is, const Imanip<T>& m);
00058 
00059 template<class T>
00060 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m);
00061 
00062 
00063 /*---------------------------------------------------------------------------*\
00064                         Class Smanip Declaration
00065 \*---------------------------------------------------------------------------*/
00066 
00067 template<class T>
00068 class Smanip
00069 {
00070     T (IOstream::*_fPtr)(const T);
00071     T _i;
00072 
00073 public:
00074 
00075     Smanip(T (IOstream::*fPtr)(const T), const T i)
00076     :
00077         _fPtr(fPtr),
00078         _i(i)
00079     {}
00080 
00081     friend Istream& operator>> <T>(Istream& is, const Smanip<T>& m);
00082     friend Ostream& operator<< <T>(Ostream& os, const Smanip<T>& m);
00083 };
00084 
00085 
00086 template<class T>
00087 inline Istream& operator>>(Istream& is, const Smanip<T>& m)
00088 {
00089     (is.*m._fPtr)(m._i);
00090     return is;
00091 }
00092 
00093 
00094 template<class T>
00095 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m)
00096 {
00097     (os.*m._fPtr)(m._i);
00098     return os;
00099 }
00100 
00101 
00102 /*---------------------------------------------------------------------------*\
00103                         Class Imanip Declaration
00104 \*---------------------------------------------------------------------------*/
00105 
00106 template<class T>
00107 class Imanip
00108 {
00109     T (Istream::*_fPtr)(const T);
00110     T _i;
00111 
00112 public:
00113 
00114     Imanip(T (Istream::*fPtr)(const T), const T i)
00115     :
00116         _fPtr(fPtr),
00117         _i(i)
00118     {}
00119 
00120     friend Istream& operator>> <T>(Istream& is, const Imanip<T>& m);
00121 };
00122 
00123 
00124 template<class T>
00125 inline Istream& operator>>(Istream& is, const Imanip<T>& m)
00126 {
00127     (is.*m._fPtr)(m._i);
00128     return is;
00129 }
00130 
00131 
00132 /*---------------------------------------------------------------------------*\
00133                         Class Omanip Declaration
00134 \*---------------------------------------------------------------------------*/
00135 
00136 template<class T>
00137 class Omanip
00138 {
00139     T (Ostream::*_fPtr)(const T);
00140     T _i;
00141 
00142 public:
00143 
00144     Omanip(T (Ostream::*fPtr)(const T), const T i)
00145     :
00146         _fPtr(fPtr),
00147         _i(i)
00148     {}
00149 
00150     friend Ostream& operator<< <T>(Ostream& os, const Omanip<T>& m);
00151 };
00152 
00153 
00154 template<class T>
00155 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m)
00156 {
00157     (os.*m._fPtr)(m._i);
00158     return os;
00159 }
00160 
00161 
00162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00163 
00164 inline Smanip<ios_base::fmtflags> setf
00165 (
00166     const ios_base::fmtflags flags
00167 )
00168 {
00169     return Smanip<ios_base::fmtflags>(&IOstream::setf, flags);
00170 }
00171 
00172 
00173 inline Omanip<int> setw(const int i)
00174 {
00175     return Omanip<int>(&Ostream::width, i);
00176 }
00177 
00178 
00179 inline Omanip<int> setprecision(const int i)
00180 {
00181     return Omanip<int>(&Ostream::precision, i);
00182 }
00183 
00184 
00185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00186 
00187 } // End namespace Foam
00188 
00189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00190 
00191 #endif
00192 
00193 // ************************************************************************* //
For further information go to www.openfoam.org