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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
28 
29 #include "prefixOSstream.H"
30 #include "Pstream.H"
31 #include "token.H"
32 
33 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
34 
35 inline 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 // ************************************************************************* //
token.H
Foam::doubleScalar
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
prefixOSstream.H
Foam::OSstream::write
virtual bool write(const token &tok)
Write token to stream or otherwise handle it.
Definition: OSstream.C:36
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::prefixOSstream::print
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: prefixOSstream.C:62
Foam::prefixOSstream::indent
virtual void indent()
Add indentation characters.
Definition: prefixOSstream.C:168
Foam::floatScalar
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45
Foam::OSstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OSstream.C:119
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::prefixOSstream::write
virtual bool write(const token &tok)
Write token to stream or otherwise handle it.
Definition: prefixOSstream.C:69
Foam::prefixOSstream::prefixOSstream
prefixOSstream(std::ostream &os, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct and set stream status.
Definition: prefixOSstream.C:48
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::OSstream
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:54
Foam::prefixOSstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &val, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: prefixOSstream.C:119
Foam::token::NL
Newline [isspace].
Definition: token.H:124
os
OBJstream os(runTime.globalPath()/outputName)
Pstream.H
Foam::OSstream::indent
virtual void indent()
Add indentation characters.
Definition: OSstream.C:266
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::OSstream::print
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: SstreamsPrint.C:45
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56