prefixOSstream.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "prefixOSstream.H"
27 #include "Pstream.H"
28 #include "token.H"
29 
30 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
31 
32 inline void Foam::prefixOSstream::checkWritePrefix()
33 {
34  if (printPrefix_ && prefix_.size())
35  {
36  OSstream::write(prefix_.c_str());
37  printPrefix_ = false;
38  }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  ostream& os,
47  const string& name,
48  streamFormat format,
49  versionNumber version,
50  compressionType compression
51 )
52 :
53  OSstream(os, name, format, version, compression),
54  printPrefix_(true),
55  prefix_("")
56 {}
57 
58 
59 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
60 
62 {
63  os << "prefixOSstream ";
64  OSstream::print(os);
65 }
66 
67 
69 {
70  checkWritePrefix();
71  OSstream::write(c);
72 
73  if (c == token::NL)
74  {
75  printPrefix_ = true;
76  }
77 
78  return *this;
79 }
80 
81 
83 {
84  checkWritePrefix();
85  OSstream::write(str);
86 
87  size_t len = strlen(str);
88  if (len && str[len-1] == token::NL)
89  {
90  printPrefix_ = true;
91  }
92 
93  return *this;
94 }
95 
96 
98 {
99  checkWritePrefix();
100  return OSstream::write(val);
101 }
102 
103 
105 {
106  checkWritePrefix();
107  return OSstream::write(val);
108 }
109 
110 
112 {
113  checkWritePrefix();
114  return OSstream::write(vs);
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  checkWritePrefix();
160  return OSstream::write(val);
161 }
162 
163 
165 (
166  const char* buf,
167  std::streamsize count
168 )
169 {
170  checkWritePrefix();
171  return OSstream::write(buf, count);
172 }
173 
174 
176 {
177  checkWritePrefix();
179 }
180 
181 // ************************************************************************* //
A class for handling verbatimStrings, derived from string.
prefixOSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string with optional double quotes.
Definition: OSstream.C:78
virtual void indent()
Add indentation characters.
Definition: OSstream.C:198
OSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: OSstreamI.H:31
const dimensionedScalar c
Speed of light in a vacuum.
A class for handling words, derived from string.
Definition: word.H:59
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void indent()
Add indentation characters.
virtual Ostream & write(const char)
Write character.
Definition: OSstream.C:32
long double longDoubleScalar
Lang double precision floating point scalar type.
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:43
Version number type.
Definition: IOstream.H:96
virtual Ostream & write(const char)
Write character.