FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 InNamespace
00025     Foam::IOmanip
00026 
00027 Description
00028     Istream and Ostream manipulators taking arguments.
00029 
00030 \*---------------------------------------------------------------------------*/
00031 
00032 #ifndef IOmanip_H
00033 #define IOmanip_H
00034 
00035 #include <OpenFOAM/Istream.H>
00036 #include <OpenFOAM/Ostream.H>
00037 
00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00039 
00040 namespace Foam
00041 {
00042 
00043 // Forward declaration of friend functions and operators
00044 
00045 template<class T> class Smanip;
00046 template<class T> class Imanip;
00047 template<class T> class Omanip;
00048 
00049 template<class T>
00050 inline Istream& operator>>(Istream& is, const Smanip<T>& m);
00051 
00052 template<class T>
00053 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m);
00054 
00055 template<class T>
00056 inline Istream& operator>>(Istream& is, const Imanip<T>& m);
00057 
00058 template<class T>
00059 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m);
00060 
00061 
00062 /*---------------------------------------------------------------------------*\
00063                         Class Smanip Declaration
00064 \*---------------------------------------------------------------------------*/
00065 
00066 template<class T>
00067 class Smanip
00068 {
00069     T (IOstream::*_fPtr)(const T);
00070     T _i;
00071 
00072 public:
00073 
00074     Smanip(T (IOstream::*fPtr)(const T), const T i)
00075     :
00076         _fPtr(fPtr),
00077         _i(i)
00078     {}
00079 
00080     friend Istream& operator>> <T>(Istream& is, const Smanip<T>& m);
00081     friend Ostream& operator<< <T>(Ostream& os, const Smanip<T>& m);
00082 };
00083 
00084 
00085 template<class T>
00086 inline Istream& operator>>(Istream& is, const Smanip<T>& m)
00087 {
00088     (is.*m._fPtr)(m._i);
00089     return is;
00090 }
00091 
00092 
00093 template<class T>
00094 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m)
00095 {
00096     (os.*m._fPtr)(m._i);
00097     return os;
00098 }
00099 
00100 
00101 /*---------------------------------------------------------------------------*\
00102                         Class Imanip Declaration
00103 \*---------------------------------------------------------------------------*/
00104 
00105 template<class T>
00106 class Imanip
00107 {
00108     T (Istream::*_fPtr)(const T);
00109     T _i;
00110 
00111 public:
00112 
00113     Imanip(T (Istream::*fPtr)(const T), const T i)
00114     :
00115         _fPtr(fPtr),
00116         _i(i)
00117     {}
00118 
00119     friend Istream& operator>> <T>(Istream& is, const Imanip<T>& m);
00120 };
00121 
00122 
00123 template<class T>
00124 inline Istream& operator>>(Istream& is, const Imanip<T>& m)
00125 {
00126     (is.*m._fPtr)(m._i);
00127     return is;
00128 }
00129 
00130 
00131 /*---------------------------------------------------------------------------*\
00132                         Class Omanip Declaration
00133 \*---------------------------------------------------------------------------*/
00134 
00135 template<class T>
00136 class Omanip
00137 {
00138     T (Ostream::*_fPtr)(const T);
00139     T _i;
00140 
00141 public:
00142 
00143     Omanip(T (Ostream::*fPtr)(const T), const T i)
00144     :
00145         _fPtr(fPtr),
00146         _i(i)
00147     {}
00148 
00149     friend Ostream& operator<< <T>(Ostream& os, const Omanip<T>& m);
00150 };
00151 
00152 
00153 template<class T>
00154 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m)
00155 {
00156     (os.*m._fPtr)(m._i);
00157     return os;
00158 }
00159 
00160 
00161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00162 
00163 inline Smanip<ios_base::fmtflags> setf
00164 (
00165     const ios_base::fmtflags flags
00166 )
00167 {
00168     return Smanip<ios_base::fmtflags>(&IOstream::setf, flags);
00169 }
00170 
00171 
00172 inline Omanip<IOstream::streamFormat> setformat
00173 (
00174     const IOstream::streamFormat fmt
00175 )
00176 {
00177     return Omanip<IOstream::streamFormat>(&IOstream::format, fmt);
00178 }
00179 
00180 
00181 inline Omanip<IOstream::versionNumber> setversion
00182 (
00183     const IOstream::versionNumber ver
00184 )
00185 {
00186     return Omanip<IOstream::versionNumber>(&IOstream::version, ver);
00187 }
00188 
00189 
00190 inline Omanip<IOstream::compressionType> setcompression
00191 (
00192     const IOstream::compressionType cmp
00193 )
00194 {
00195     return Omanip<IOstream::compressionType>(&IOstream::compression, cmp);
00196 }
00197 
00198 
00199 inline Omanip<int> setw(const int i)
00200 {
00201     return Omanip<int>(&Ostream::width, i);
00202 }
00203 
00204 
00205 inline Omanip<int> setprecision(const int i)
00206 {
00207     return Omanip<int>(&Ostream::precision, i);
00208 }
00209 
00210 
00211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00212 
00213 } // End namespace Foam
00214 
00215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00216 
00217 #endif
00218 
00219 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines