prefixOSstream.C
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 OpenFOAM Foundation
9 Copyright (C) 2020 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
27\*---------------------------------------------------------------------------*/
28
29#include "prefixOSstream.H"
30#include "Pstream.H"
31#include "token.H"
32
33// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
34
35inline void Foam::prefixOSstream::checkWritePrefix()
36{
37 if (printPrefix_ && !prefix_.empty())
38 {
39 OSstream::write(prefix_.c_str());
40 printPrefix_ = false;
41 }
42}
43
44
45// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46
48(
49 std::ostream& os,
50 const string& streamName,
51 IOstreamOption streamOpt
52)
53:
54 OSstream(os, streamName, streamOpt),
55 printPrefix_(true),
56 prefix_()
57{}
58
59
60// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
61
63{
64 os << "prefixOSstream ";
66}
67
68
70{
71 return OSstream::write(tok);
72}
73
74
76{
77 checkWritePrefix();
79
80 if (c == token::NL)
81 {
82 printPrefix_ = true;
83 }
84
85 return *this;
86}
87
88
90{
91 checkWritePrefix();
92 OSstream::write(str);
93
94 const size_t len = strlen(str);
95 if (len && str[len-1] == token::NL)
96 {
97 printPrefix_ = true;
98 }
99
100 return *this;
101}
102
103
105{
106 checkWritePrefix();
107 return OSstream::write(val);
108}
109
110
112{
113 checkWritePrefix();
114 return OSstream::write(val);
115}
116
117
119(
120 const std::string& val,
121 const bool quoted
122)
123{
124 checkWritePrefix();
125 return OSstream::writeQuoted(val, quoted);
126}
127
128
130{
131 checkWritePrefix();
132 return OSstream::write(val);
133}
134
135
137{
138 checkWritePrefix();
139 return OSstream::write(val);
140}
141
142
144{
145 checkWritePrefix();
146 return OSstream::write(val);
147}
148
149
151{
152 checkWritePrefix();
153 return OSstream::write(val);
154}
155
156
158(
159 const char* buf,
160 std::streamsize count
161)
162{
163 checkWritePrefix();
164 return OSstream::write(buf, count);
165}
166
167
169{
170 checkWritePrefix();
172}
173
174
175// ************************************************************************* //
The IOstreamOption is a simple container for options an IOstream can normally have.
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:57
virtual void indent()
Add indentation characters.
Definition: OSstream.C:266
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OSstream.C:119
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool write()
Write the output fields.
scalar print()
Print to screen.
Version of OSstream that prints a prefix on each line.
virtual Ostream & writeQuoted(const std::string &val, const bool quoted=true)
Write std::string surrounded by quotes.
virtual void indent()
Add indentation characters.
A token holds an item read from Istream.
Definition: token.H:69
@ NL
Newline [isspace].
Definition: token.H:124
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45