Loading...
Searching...
No Matches
OSstream.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-2014,2024 OpenFOAM Foundation
9 Copyright (C) 2017-2023 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
27Class
28 Foam::OSstream
29
30Description
31 Generic output stream using a standard (STL) stream.
32
33SourceFiles
34 OSstreamI.H
35 OSstream.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_OSstream_H
40#define Foam_OSstream_H
41
42#include "Ostream.H"
43#include "fileName.H"
44#include <iostream>
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
51/*---------------------------------------------------------------------------*\
52 Class OSstream Declaration
53\*---------------------------------------------------------------------------*/
54
55class OSstream
56:
57 public Ostream
58{
59 // Private Data
60
61 //- The output stream path
62 fileName name_;
63
64 //- The output stream
65 std::ostream& os_;
66
67
68public:
69
70 // Generated Methods
71
72 //- Copy construct
73 OSstream(const OSstream&) = default;
75 //- No copy assignment
76 void operator=(const OSstream&) = delete;
77
78
79 // Constructors
80
81 //- Construct wrapper around std::ostream, set stream status
82 // Default stream options (ASCII, uncompressed)
83 inline OSstream
84 (
85 std::ostream& os,
86 const string& streamName,
87 IOstreamOption streamOpt = IOstreamOption()
88 );
89
90 //- Construct wrapper around std::ostream, set stream status
92 (
93 std::ostream& os,
94 const string& streamName,
97 )
98 :
99 OSstream(os, streamName, IOstreamOption(fmt, cmp))
100 {}
101
102 //- Construct wrapper around std::ostream, set stream status
104 (
105 std::ostream& os,
106 const string& streamName,
110 )
111 :
112 OSstream(os, streamName, IOstreamOption(fmt, ver, cmp))
113 {}
114
115
116 // Member Functions
117
118 // Characteristics
119
120 //- Get the name of the output serial stream.
121 //- (eg, the name of the Fstream file name)
122 virtual const fileName& name() const override { return name_; }
123
124 //- The name of the output serial stream, for modification.
125 // Use with caution since some classes (eg, Fstream)
126 // also use this for filesystem information!
127 virtual fileName& name() { return name_; }
128
129
130 // STL stream
131
132 //- Const access to underlying std::ostream
133 virtual const std::ostream& stdStream() const { return os_; }
135 //- Access to underlying std::ostream
136 virtual std::ostream& stdStream() { return os_; }
137
138
139 // Stream State
140
141 //- Get current stream flags
142 virtual std::ios_base::fmtflags flags() const override
143 {
144 return os_.flags();
145 }
146
147 //- Set stream flags, return old stream flags
148 virtual std::ios_base::fmtflags flags
149 (
150 std::ios_base::fmtflags f
151 ) override
152 {
153 return os_.flags(f);
154 }
156 //- Set stream state to match that of the std::ostream
157 void syncState()
158 {
159 setState(os_.rdstate());
160 }
161
162
163 // Write Functions
164
165 //- Inherit write methods from Ostream
167
168 //- Write token to stream or otherwise handle it.
169 // \return false if the token type was not handled by this method
170 virtual bool write(const token& tok) override;
172 //- Write character
173 virtual Ostream& write(const char c) override;
174
175 //- Write character/string content, with/without surrounding quotes
176 virtual Ostream& writeQuoted
177 (
178 const char* str,
179 std::streamsize len,
180 const bool quoted=true
181 ) override;
183 //- Write character string
184 virtual Ostream& write(const char* str) override;
185
186 //- Write word
187 virtual Ostream& write(const word& str) override;
188
189 //- Write string (quoted)
190 // In the rare case that the string contains a final trailing
191 // backslash, it will be dropped to the appearance of an escaped
192 // double-quote.
193 virtual Ostream& write(const std::string& str) override;
194
195 //- Write int32_t
196 virtual Ostream& write(const int32_t val) override;
197
198 //- Write int64_t
199 virtual Ostream& write(const int64_t val) override;
200
201 //- Write uint32_t
202 virtual Ostream& write(const uint32_t val) override;
203
204 //- Write uint64_t
205 virtual Ostream& write(const uint64_t val) override;
206
207 //- Write float
208 virtual Ostream& write(const float val) override;
209
210 //- Write double
211 virtual Ostream& write(const double val) override;
212
213 //- Write binary block
214 virtual Ostream& write
215 (
216 const char* data,
217 std::streamsize count
218 ) override;
219
220 //- Low-level raw binary output
221 virtual Ostream& writeRaw
222 (
223 const char* data,
224 std::streamsize count
225 ) override;
226
227 //- Begin marker for low-level raw binary output.
228 // The count indicates the number of bytes for subsequent
229 // writeRaw calls.
230 virtual bool beginRawWrite(std::streamsize count) override;
231
232 //- End marker for low-level raw binary output.
233 virtual bool endRawWrite() override;
234
235 //- Add indentation characters
236 virtual void indent() override;
237
238
239 // Stream state functions
240
241 //- Flush stream
242 virtual void flush() override;
243
244 //- Add newline and flush stream
245 virtual void endl() override;
246
247 //- Get the current padding character
248 virtual char fill() const override;
249
250 //- Set padding character for formatted field up to field width
251 // \return previous padding character
252 virtual char fill(const char fillch) override;
253
254 //- Get width of output field
255 virtual int width() const override;
256
257 //- Set width of output field
258 // \return previous width
259 virtual int width(const int w) override;
260
261 //- Get precision of output field
262 virtual int precision() const override;
263
264 //- Set precision of output field
265 // \return old precision
266 virtual int precision(const int p) override;
267
268
269 // Print
270
271 //- Print stream description to Ostream
272 virtual void print(Ostream& os) const override;
273};
274
275
276// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277
278} // End namespace Foam
279
280// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281
282#include "OSstreamI.H"
283
284// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285
286#endif
287
288// ************************************************************************* //
Representation of a major/minor version number.
A simple container for options an IOstream can normally have.
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression.
streamFormat
Data format (ascii | binary | coherent).
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED).
@ UNCOMPRESSED
compression = false
void setState(std::ios_base::iostate state) noexcept
Set stream state.
Definition IOstream.H:166
Generic output stream using a standard (STL) stream.
Definition OSstream.H:53
virtual void flush() override
Flush stream.
Definition OSstream.C:304
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name).
Definition OSstream.H:134
OSstream(std::ostream &os, const string &streamName, IOstreamOption::streamFormat fmt, IOstreamOption::versionNumber ver, IOstreamOption::compressionType cmp=IOstreamOption::UNCOMPRESSED)
Construct wrapper around std::ostream, set stream status.
Definition OSstream.H:114
virtual std::ios_base::fmtflags flags() const override
Get current stream flags.
Definition OSstream.H:163
virtual fileName & name()
The name of the output serial stream, for modification.
Definition OSstream.H:142
virtual std::ios_base::fmtflags flags(std::ios_base::fmtflags f) override
Set stream flags, return old stream flags.
Definition OSstream.H:172
OSstream(const OSstream &)=default
Copy construct.
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true) override
Write character/string content, with/without surrounding quotes.
Definition OSstream.C:101
virtual const std::ostream & stdStream() const
Const access to underlying std::ostream.
Definition OSstream.H:150
virtual void print(Ostream &os) const override
Print stream description to Ostream.
virtual void indent() override
Add indentation characters.
Definition OSstream.C:294
virtual char fill() const override
Get the current padding character.
Definition OSstream.C:319
virtual int precision() const override
Get precision of output field.
Definition OSstream.C:343
virtual Ostream & writeRaw(const char *data, std::streamsize count) override
Low-level raw binary output.
Definition OSstream.C:280
virtual bool beginRawWrite(std::streamsize count) override
Begin marker for low-level raw binary output.
Definition OSstream.C:256
void syncState()
Set stream state to match that of the std::ostream.
Definition OSstream.H:182
virtual bool endRawWrite() override
End marker for low-level raw binary output.
Definition OSstream.C:271
void operator=(const OSstream &)=delete
No copy assignment.
virtual void endl() override
Add newline and flush stream.
Definition OSstream.C:310
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition OSstream.H:155
OSstream(std::ostream &os, const string &streamName, IOstreamOption::streamFormat fmt, IOstreamOption::compressionType cmp=IOstreamOption::UNCOMPRESSED)
Construct wrapper around std::ostream, set stream status.
Definition OSstream.H:100
virtual int width() const override
Get width of output field.
Definition OSstream.C:331
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true)=0
Write character/string content, with/without surrounding quotes.
Ostream(const Ostream &)=default
Copy construct.
A class for handling file names.
Definition fileName.H:75
A token holds an item read from Istream.
Definition token.H:70
A class for handling words, derived from Foam::string.
Definition word.H:66
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
runTime write()
labelList f(nPoints)