All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IOmanip.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 InNamespace
25  Foam::IOmanip
26 
27 Description
28  Istream and Ostream manipulators taking arguments.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef IOmanip_H
33 #define IOmanip_H
34 
35 #include "Istream.H"
36 #include "Ostream.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // Forward declaration of friend functions and operators
44 
45 template<class T> class Smanip;
46 template<class T> class Imanip;
47 template<class T> class Omanip;
48 
49 template<class T>
50 inline Istream& operator>>(Istream& is, const Smanip<T>& m);
51 
52 template<class T>
53 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m);
54 
55 template<class T>
56 inline Istream& operator>>(Istream& is, const Imanip<T>& m);
57 
58 template<class T>
59 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m);
60 
61 
62 /*---------------------------------------------------------------------------*\
63  Class Smanip Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class T>
67 class Smanip
68 {
69  T (IOstream::*_fPtr)(const T);
70  T _i;
71 
72 public:
73 
74  Smanip(T (IOstream::*fPtr)(const T), const T i)
75  :
76  _fPtr(fPtr),
77  _i(i)
78  {}
79 
80  friend Istream& operator>> <T>(Istream& is, const Smanip<T>& m);
81  friend Ostream& operator<< <T>(Ostream& os, const Smanip<T>& m);
82 };
83 
84 
85 template<class T>
86 inline Istream& operator>>(Istream& is, const Smanip<T>& m)
87 {
88  (is.*m._fPtr)(m._i);
89  return is;
90 }
91 
92 
93 template<class T>
94 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m)
95 {
96  (os.*m._fPtr)(m._i);
97  return os;
98 }
99 
100 
101 /*---------------------------------------------------------------------------*\
102  Class Imanip Declaration
103 \*---------------------------------------------------------------------------*/
104 
105 template<class T>
106 class Imanip
107 {
108  T (Istream::*_fPtr)(const T);
109  T _i;
110 
111 public:
112 
113  Imanip(T (Istream::*fPtr)(const T), const T i)
114  :
115  _fPtr(fPtr),
116  _i(i)
117  {}
118 
119  friend Istream& operator>> <T>(Istream& is, const Imanip<T>& m);
120 };
121 
122 
123 template<class T>
124 inline Istream& operator>>(Istream& is, const Imanip<T>& m)
125 {
126  (is.*m._fPtr)(m._i);
127  return is;
128 }
129 
130 
131 /*---------------------------------------------------------------------------*\
132  Class Omanip Declaration
133 \*---------------------------------------------------------------------------*/
134 
135 template<class T>
136 class Omanip
137 {
138  T (Ostream::*_fPtr)(const T);
139  T _i;
140 
141 public:
142 
143  Omanip(T (Ostream::*fPtr)(const T), const T i)
144  :
145  _fPtr(fPtr),
146  _i(i)
147  {}
148 
149  friend Ostream& operator<< <T>(Ostream& os, const Omanip<T>& m);
150 };
151 
152 
153 template<class T>
154 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m)
155 {
156  (os.*m._fPtr)(m._i);
157  return os;
158 }
159 
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
164 (
165  const ios_base::fmtflags flags
166 )
167 {
169 }
170 
171 
173 (
174  const IOstream::streamFormat fmt
175 )
176 {
178 }
179 
180 
182 (
183  const IOstream::versionNumber ver
184 )
185 {
187 }
188 
189 
191 (
192  const IOstream::compressionType cmp
193 )
194 {
196 }
197 
198 
199 inline Omanip<int> setw(const int i)
200 {
201  return Omanip<int>(&Ostream::width, i);
202 }
203 
204 
205 inline Omanip<int> setprecision(const int i)
206 {
207  return Omanip<int>(&Ostream::precision, i);
208 }
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #endif
218 
219 // ************************************************************************* //
Omanip< IOstream::versionNumber > setversion(const IOstream::versionNumber ver)
Definition: IOmanip.H:182
Imanip(T(Istream::*fPtr)(const T), const T i)
Definition: IOmanip.H:113
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:496
friend Istream & operator>>(Istream &is, const Smanip< T > &m)
Definition: IOmanip.H:86
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
Omanip< IOstream::compressionType > setcompression(const IOstream::compressionType cmp)
Definition: IOmanip.H:191
Smanip(T(IOstream::*fPtr)(const T), const T i)
Definition: IOmanip.H:74
Omanip< int > setprecision(const int i)
Definition: IOmanip.H:205
Istream & operator>>(Istream &, directionInfo &)
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
Definition: IOmanip.H:164
Omanip(T(Ostream::*fPtr)(const T), const T i)
Definition: IOmanip.H:143
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual int width() const =0
Get width of output field.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
Definition: IOstream.H:71
Version number type.
Definition: IOstream.H:96
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Namespace for OpenFOAM.
virtual int precision() const =0
Get precision of output field.
Omanip< IOstream::streamFormat > setformat(const IOstream::streamFormat fmt)
Definition: IOmanip.H:173