Loading...
Searching...
No Matches
prefixOSstream.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) 2020-2025 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::prefixOSstream
29
30Description
31 Version of OSstream that prints a prefix on each line.
32
33 This is useful for running in parallel as it allows the processor number
34 to be automatically prepended to each message line.
35
36SourceFiles
37 prefixOSstream.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_prefixOSstream_H
42#define Foam_prefixOSstream_H
43
44#include "OSstream.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
51/*---------------------------------------------------------------------------*\
52 Class prefixOSstream Declaration
53\*---------------------------------------------------------------------------*/
54
56:
57 public OSstream
58{
59 // Private Data
60
61 //- Prefix printing is active
62 bool printPrefix_;
63
64 //- The prefix to add
65 string prefix_;
66
67
68 // Private Member Functions
69
70 //- Emit pending prefix before any output
71 inline void checkWritePrefix();
72
73
74public:
75
76 // Constructors
77
78 //- Construct and set stream status
80 (
81 std::ostream& os,
82 const string& streamName,
83 IOstreamOption streamOpt = IOstreamOption()
84 );
85
86
87 // Member Functions
88
89 // Decorators
90
91 //- The stream prefix
92 const string& prefix() const noexcept { return prefix_; }
93
94 //- Return non-const access to the stream prefix
95 string& prefix() noexcept { return prefix_; }
96
98 // Write Functions
99
100 //- Inherit write methods from OSstream
103 //- Write token to stream or otherwise handle it.
104 // \return false if the token type was not handled by this method
105 virtual bool write(const token& tok) override;
106
107 //- Write character
108 virtual Ostream& write(const char c) override;
109
110 //- Write character/string content, with/without surrounding quotes
111 virtual Ostream& writeQuoted
112 (
113 const char* str,
114 std::streamsize len,
115 const bool quoted=true
116 ) override;
117
118 //- Write character string
119 virtual Ostream& write(const char* str) override;
120
121 //- Write word
122 virtual Ostream& write(const word& val) override;
123
124 //- Write string
125 virtual Ostream& write(const std::string& val) override;
126
127 //- Write int32_t
128 virtual Ostream& write(const int32_t val) override;
129
130 //- Write int64_t
131 virtual Ostream& write(const int64_t val) override;
132
133 //- Write uint32_t
134 virtual Ostream& write(const uint32_t val) override;
135
136 //- Write uint64_t
137 virtual Ostream& write(const uint64_t val) override;
138
139 //- Write float
140 virtual Ostream& write(const float val) override;
141
142 //- Write double
143 virtual Ostream& write(const double val) override;
144
145 //- Write binary block
146 virtual Ostream& write(const char* buf, std::streamsize count) override;
147
148 //- Add indentation characters
149 virtual void indent() override;
150
151
152 // Print
153
154 //- Print stream description to Ostream
155 virtual void print(Ostream& os) const override;
156};
157
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
161} // End namespace Foam
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164
165#endif
166
167// ************************************************************************* //
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.
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
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) override
Write character/string content, with/without surrounding quotes.
virtual void print(Ostream &os) const override
Print stream description to Ostream.
virtual void indent() override
Add indentation characters.
prefixOSstream(std::ostream &os, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct and set stream status.
const string & prefix() const noexcept
The stream prefix.
string & prefix() noexcept
Return non-const access to the stream prefix.
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
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265
runTime write()