IOmanip.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2018-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 InNamespace
28  Foam::IOmanip
29 
30 Description
31  Istream and Ostream manipulators taking arguments.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef IOmanip_H
36 #define IOmanip_H
37 
38 #include "Istream.H"
39 #include "Ostream.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward Declarations
47 
48 template<class T> class Smanip;
49 template<class T> class Imanip;
50 template<class T> class Omanip;
51 
52 template<class T>
53 inline Istream& operator>>(Istream& is, const Smanip<T>& m);
54 
55 template<class T>
56 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m);
57 
58 template<class T>
59 inline Istream& operator>>(Istream& is, const Imanip<T>& m);
60 
61 template<class T>
62 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m);
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class Smanip Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 //- An IOstream manipulator taking arguments
70 template<class T>
71 class Smanip
72 {
73  T (IOstream::*_fPtr)(const T);
74  T _i;
75 
76 public:
77 
78  Smanip(T (IOstream::*fPtr)(const T), const T i)
79  :
80  _fPtr(fPtr),
81  _i(i)
82  {}
83 
84  friend Istream& operator>> <T>(Istream& is, const Smanip<T>& m);
85  friend Ostream& operator<< <T>(Ostream& os, const Smanip<T>& m);
86 };
87 
88 
89 template<class T>
90 inline Istream& operator>>(Istream& is, const Smanip<T>& m)
91 {
92  (is.*m._fPtr)(m._i);
93  return is;
94 }
95 
96 
97 template<class T>
98 inline Ostream& operator<<(Ostream& os, const Smanip<T>& m)
99 {
100  (os.*m._fPtr)(m._i);
101  return os;
102 }
103 
104 
105 /*---------------------------------------------------------------------------*\
106  Class Imanip Declaration
107 \*---------------------------------------------------------------------------*/
108 
109 //- An Istream manipulator taking arguments
110 template<class T>
111 class Imanip
112 {
113  T (Istream::*_fPtr)(const T);
114  T _i;
115 
116 public:
117 
118  Imanip(T (Istream::*fPtr)(const T), const T i)
119  :
120  _fPtr(fPtr),
121  _i(i)
122  {}
123 
124  friend Istream& operator>> <T>(Istream& is, const Imanip<T>& m);
125 };
126 
127 
128 template<class T>
129 inline Istream& operator>>(Istream& is, const Imanip<T>& m)
130 {
131  (is.*m._fPtr)(m._i);
132  return is;
133 }
134 
135 
136 /*---------------------------------------------------------------------------*\
137  Class Omanip Declaration
138 \*---------------------------------------------------------------------------*/
139 
140 //- An Ostream manipulator taking arguments
141 template<class T>
142 class Omanip
143 {
144  T (Ostream::*_fPtr)(const T);
145  T _i;
146 
147 public:
148 
149  Omanip(T (Ostream::*fPtr)(const T), const T i)
150  :
151  _fPtr(fPtr),
152  _i(i)
153  {}
154 
155  friend Ostream& operator<< <T>(Ostream& os, const Omanip<T>& m);
156 };
157 
158 
159 template<class T>
160 inline Ostream& operator<<(Ostream& os, const Omanip<T>& m)
161 {
162  (os.*m._fPtr)(m._i);
163  return os;
164 }
165 
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 inline Smanip<ios_base::fmtflags> setf(const ios_base::fmtflags flags)
170 {
172 }
173 
174 
175 inline Omanip<char> setfill(char fillch)
176 {
177  return Omanip<char>(&Ostream::fill, fillch);
178 }
179 
180 
181 inline Omanip<IOstream::streamFormat> setformat
182 (
183  const IOstream::streamFormat fmt
184 )
185 {
187 }
188 
189 
190 inline Omanip<IOstream::versionNumber> setversion
191 (
192  const IOstream::versionNumber ver
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 // ************************************************************************* //
Foam::setf
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
Definition: IOmanip.H:169
Foam::IOstream
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:79
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:286
Foam::Imanip
An Istream manipulator taking arguments.
Definition: IOmanip.H:49
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::Omanip::Omanip
Omanip(T(Ostream::*fPtr)(const T), const T i)
Definition: IOmanip.H:149
Foam::Ostream::precision
virtual int precision() const =0
Get precision of output field.
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Istream.H
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:338
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::setw
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Foam::IOstream::setf
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:378
Foam::Smanip::Smanip
Smanip(T(IOstream::*fPtr)(const T), const T i)
Definition: IOmanip.H:78
Foam::setversion
Omanip< IOstream::versionNumber > setversion(const IOstream::versionNumber ver)
Definition: IOmanip.H:191
Ostream.H
Foam::setprecision
Omanip< int > setprecision(const int i)
Definition: IOmanip.H:205
Foam::setformat
Omanip< IOstream::streamFormat > setformat(const IOstream::streamFormat fmt)
Definition: IOmanip.H:182
Foam::Smanip
An IOstream manipulator taking arguments.
Definition: IOmanip.H:48
Foam::Omanip
An Ostream manipulator taking arguments.
Definition: IOmanip.H:50
Foam::setfill
Omanip< char > setfill(char fillch)
Definition: IOmanip.H:175
Foam::Ostream::fill
virtual char fill() const =0
Get padding character.
Foam::Imanip::Imanip
Imanip(T(Istream::*fPtr)(const T), const T i)
Definition: IOmanip.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Ostream::width
virtual int width() const =0
Get width of output field.