initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOstreams / IOstreams / IOmanip.H
blob5b98a05ae7d25216c3fafb1f0189cd44c82b3a34
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 InNamespace
26     Foam::IOmanip
28 Description
29     Istream and Ostream manipulators taking arguments.
31 \*---------------------------------------------------------------------------*/
33 #ifndef IOmanip_H
34 #define IOmanip_H
36 #include "Istream.H"
37 #include "Ostream.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 namespace Foam
44 // Forward declaration of friend functions and operators
46 template<class T> class Smanip;
47 template<class T> class Imanip;
48 template<class T> class Omanip;
50 template<class T>
51 inline Istream& operator>>(Istream& is, const Smanip<T>& m);
53 template<class T>
54 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m);
56 template<class T>
57 inline Istream& operator>>(Istream& is, const Imanip<T>& m);
59 template<class T>
60 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m);
63 /*---------------------------------------------------------------------------*\
64                         Class Smanip Declaration
65 \*---------------------------------------------------------------------------*/
67 template<class T>
68 class Smanip
70     T (IOstream::*_fPtr)(const T);
71     T _i;
73 public:
75     Smanip(T (IOstream::*fPtr)(const T), const T i)
76     :
77         _fPtr(fPtr),
78         _i(i)
79     {}
81     friend Istream& operator>> <T>(Istream& is, const Smanip<T>& m);
82     friend Ostream& operator<< <T>(Ostream& os, const Smanip<T>& m);
86 template<class T>
87 inline Istream& operator>>(Istream& is, const Smanip<T>& m)
89     (is.*m._fPtr)(m._i);
90     return is;
94 template<class T>
95 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m)
97     (os.*m._fPtr)(m._i);
98     return os;
102 /*---------------------------------------------------------------------------*\
103                         Class Imanip Declaration
104 \*---------------------------------------------------------------------------*/
106 template<class T>
107 class Imanip
109     T (Istream::*_fPtr)(const T);
110     T _i;
112 public:
114     Imanip(T (Istream::*fPtr)(const T), const T i)
115     :
116         _fPtr(fPtr),
117         _i(i)
118     {}
120     friend Istream& operator>> <T>(Istream& is, const Imanip<T>& m);
124 template<class T>
125 inline Istream& operator>>(Istream& is, const Imanip<T>& m)
127     (is.*m._fPtr)(m._i);
128     return is;
132 /*---------------------------------------------------------------------------*\
133                         Class Omanip Declaration
134 \*---------------------------------------------------------------------------*/
136 template<class T>
137 class Omanip
139     T (Ostream::*_fPtr)(const T);
140     T _i;
142 public:
144     Omanip(T (Ostream::*fPtr)(const T), const T i)
145     :
146         _fPtr(fPtr),
147         _i(i)
148     {}
150     friend Ostream& operator<< <T>(Ostream& os, const Omanip<T>& m);
154 template<class T>
155 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m)
157     (os.*m._fPtr)(m._i);
158     return os;
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 inline Smanip<ios_base::fmtflags> setf
166     const ios_base::fmtflags flags
169     return Smanip<ios_base::fmtflags>(&IOstream::setf, flags);
173 inline Omanip<IOstream::streamFormat> setformat
175     const IOstream::streamFormat fmt
178     return Omanip<IOstream::streamFormat>(&IOstream::format, fmt);
182 inline Omanip<IOstream::versionNumber> setversion
184     const IOstream::versionNumber ver
187     return Omanip<IOstream::versionNumber>(&IOstream::version, ver);
191 inline Omanip<IOstream::compressionType> setcompression
193     const IOstream::compressionType cmp
196     return Omanip<IOstream::compressionType>(&IOstream::compression, cmp);
200 inline Omanip<int> setw(const int i)
202     return Omanip<int>(&Ostream::width, i);
206 inline Omanip<int> setprecision(const int i)
208     return Omanip<int>(&Ostream::precision, i);
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 } // End namespace Foam
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 #endif
220 // ************************************************************************* //