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 | Copyright (C) 2011-2014 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 
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,
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();
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  const char* buf,
171  std::streamsize count
172 )
173 {
174  checkWritePrefix();
175  return OSstream::write(buf, count);
176 }
177 
178 
180 {
181  checkWritePrefix();
183 }
184 
185 // ************************************************************************* //
token.H
Foam::prefixOSstream::checkWritePrefix
void checkWritePrefix()
Definition: prefixOSstream.C:32
format
word format(conversionProperties.lookup("format"))
Foam::doubleScalar
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:49
prefixOSstream.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::prefixOSstream::indent
virtual void indent()
Add indentation characters.
Definition: prefixOSstream.C:179
Foam::IOstream::compressionType
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
Foam::floatScalar
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:49
Foam::OSstream::print
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:43
Foam::OSstream::write
virtual Ostream & write(const token &)
Write next token to stream.
Definition: OSstream.C:32
Foam::token
A token holds items read from Istream.
Definition: token.H:67
Foam::prefixOSstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: prefixOSstream.C:130
Foam::prefixOSstream::write
virtual Ostream & write(const token &)
Write next token to stream.
Definition: prefixOSstream.C:68
Foam::token::NL
@ NL
Definition: token.H:97
Foam::token::stringToken
const string & stringToken() const
Definition: tokenI.H:249
Foam::IOstream::versionNumber
Version number type.
Definition: IOstream.H:96
Foam::token::type
tokenType type() const
Definition: tokenI.H:178
Foam::token::VARIABLE
@ VARIABLE
Definition: token.H:79
Foam::OSstream
Generic output stream.
Definition: OSstream.H:51
Pstream.H
Foam::prefixOSstream::print
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: prefixOSstream.C:61
Foam::prefixOSstream::prefixOSstream
prefixOSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: prefixOSstream.C:45
Foam::OSstream::indent
virtual void indent()
Add indentation characters.
Definition: OSstream.C:237
Foam::token::END_BLOCK
@ END_BLOCK
Definition: token.H:105
Foam::OSstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OSstream.C:125
Foam::prefixOSstream::printPrefix_
bool printPrefix_
Definition: prefixOSstream.H:57
Foam::token::HASH
@ HASH
Definition: token.H:108
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Definition: token.H:104
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::token::VERBATIMSTRING
@ VERBATIMSTRING
Definition: token.H:81
write
Tcoeff write()
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::prefixOSstream::prefix_
string prefix_
Definition: prefixOSstream.H:58
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86