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-2018 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  if (t.type() == token::VERBATIMSTRING)
71  {
72  write(char(token::HASH));
74  writeQuoted(t.stringToken(), false);
75  write(char(token::HASH));
76  write(char(token::END_BLOCK));
77  }
78  else if (t.type() == token::VARIABLE)
79  {
80  writeQuoted(t.stringToken(), false);
81  }
82  return *this;
83 }
84 
85 
87 {
88  checkWritePrefix();
89  OSstream::write(c);
90 
91  if (c == token::NL)
92  {
93  printPrefix_ = true;
94  }
95 
96  return *this;
97 }
98 
99 
101 {
102  checkWritePrefix();
103  OSstream::write(str);
104 
105  size_t len = strlen(str);
106  if (len && str[len-1] == token::NL)
107  {
108  printPrefix_ = true;
109  }
110 
111  return *this;
112 }
113 
114 
116 {
117  checkWritePrefix();
118  return OSstream::write(val);
119 }
120 
121 
123 {
124  checkWritePrefix();
125  return OSstream::write(val);
126 }
127 
128 
130 (
131  const std::string& val,
132  const bool quoted
133 )
134 {
135  checkWritePrefix();
136  return OSstream::writeQuoted(val, quoted);
137 }
138 
139 
141 {
142  checkWritePrefix();
143  return OSstream::write(val);
144 }
145 
146 
148 {
149  checkWritePrefix();
150  return OSstream::write(val);
151 }
152 
153 
155 {
156  checkWritePrefix();
157  return OSstream::write(val);
158 }
159 
160 
162 {
163  checkWritePrefix();
164  return OSstream::write(val);
165 }
166 
167 
169 {
170  checkWritePrefix();
171  return OSstream::write(val);
172 }
173 
174 
176 (
177  const char* buf,
178  std::streamsize count
179 )
180 {
181  checkWritePrefix();
182  return OSstream::write(buf, count);
183 }
184 
185 
187 {
188  checkWritePrefix();
190 }
191 
192 // ************************************************************************* //
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.
A token holds items read from Istream.
Definition: token.H:69
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OSstream.C:125
virtual void indent()
Add indentation characters.
Definition: OSstream.C:245
OSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: OSstreamI.H:31
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:53
virtual void indent()
Add indentation characters.
const string & stringToken() const
Definition: tokenI.H:258
virtual Ostream & write(const token &)
Write next token to stream.
Definition: OSstream.C:32
long double longDoubleScalar
Lang double precision floating point scalar type.
virtual Ostream & write(const token &)
Write next token to stream.
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
tokenType type() const
Definition: tokenI.H:187
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:43
const dimensionedScalar c
Speed of light in a vacuum.
Version number type.
Definition: IOstream.H:96