Loading...
Searching...
No Matches
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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27InNamespace
28 Foam::IOmanip
29
30Description
31 Istream and Ostream manipulators taking arguments.
32
33\*---------------------------------------------------------------------------*/
34
35#ifndef Foam_IOmanip_H
36#define Foam_IOmanip_H
37
38#include "Istream.H"
39#include "Ostream.H"
40
41// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42
43namespace Foam
44{
45
46// Forward Declarations
47
48template<class T> class Smanip;
49template<class T> class Imanip;
50template<class T> class Omanip;
51
52template<class T>
53inline Istream& operator>>(Istream& is, const Smanip<T>& m);
54
55template<class T>
56inline Ostream& operator<<(Ostream& os, const Smanip<T>& m);
57
58template<class T>
59inline Istream& operator>>(Istream& is, const Imanip<T>& m);
60
61template<class T>
62inline Ostream& operator<<(Ostream& os, const Omanip<T>& m);
63
64
65/*---------------------------------------------------------------------------*\
66 Class Smanip Declaration
67\*---------------------------------------------------------------------------*/
68
69//- An IOstream manipulator taking arguments
70template<class T>
71class Smanip
72{
73 T (IOstream::*_fPtr)(const T);
74 T _i;
75
76public:
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
89template<class T>
90inline Istream& operator>>(Istream& is, const Smanip<T>& m)
91{
92 (is.*m._fPtr)(m._i);
93 return is;
95
96
97template<class T>
98inline 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
110template<class T>
111class Imanip
112{
113 T (Istream::*_fPtr)(const T);
114 T _i;
115
116public:
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
128template<class T>
129inline 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
141template<class T>
143{
144 T (Ostream::*_fPtr)(const T);
145 T _i;
146
147public:
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
159template<class T>
161{
162 (os.*m._fPtr)(m._i);
163 return os;
164}
165
166
167// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168
169inline Smanip<std::ios_base::fmtflags> setf(std::ios_base::fmtflags flags)
170{
172}
173
174
175inline Omanip<char> setfill(char fillch)
176{
177 return Omanip<char>(&Ostream::fill, fillch);
178}
179
180
188
189
197
198
199inline Omanip<int> setw(const int i)
200{
201 return Omanip<int>(&Ostream::width, i);
202}
203
204
205inline Omanip<int> setprecision(const int i)
206{
208}
209
210
211// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212
213} // End namespace Foam
214
215// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216
217#endif
218
219// ************************************************************************* //
Representation of a major/minor version number.
versionNumber version() const noexcept
Get the stream version.
streamFormat format() const noexcept
Get the current stream format.
streamFormat
Data format (ascii | binary | coherent).
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition IOstream.H:85
std::ios_base::fmtflags setf(std::ios_base::fmtflags f)
Set stream flag(s), return old stream flags.
Definition IOstream.H:506
An Istream manipulator taking arguments.
Definition IOmanip.H:110
Imanip(T(Istream::*fPtr)(const T), const T i)
Definition IOmanip.H:116
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream manipulator taking arguments.
Definition IOmanip.H:143
Omanip(T(Ostream::*fPtr)(const T), const T i)
Definition IOmanip.H:149
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual char fill() const =0
Get padding character.
virtual int precision() const =0
Get precision of output field.
virtual int width() const =0
Get width of output field.
An IOstream manipulator taking arguments.
Definition IOmanip.H:68
Smanip(T(IOstream::*fPtr)(const T), const T i)
Definition IOmanip.H:74
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Smanip< std::ios_base::fmtflags > setf(std::ios_base::fmtflags flags)
Definition IOmanip.H:169
Omanip< int > setprecision(const int i)
Definition IOmanip.H:205
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Omanip< int > setw(const int i)
Definition IOmanip.H:199
Istream & operator>>(Istream &, directionInfo &)
Omanip< char > setfill(char fillch)
Definition IOmanip.H:175
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Omanip< IOstreamOption::streamFormat > setformat(const IOstreamOption::streamFormat fmt)
Definition IOmanip.H:182
Omanip< IOstreamOption::versionNumber > setversion(const IOstreamOption::versionNumber ver)
Definition IOmanip.H:191