OTstream.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) 2019-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "error.H"
29 #include "OTstream.H"
30 #include <cctype>
31 
32 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
33 
34 bool Foam::OTstream::write(const token& tok)
35 {
36  if (tok.good())
37  {
38  append(tok);
39  return true;
40  }
41 
42  return false;
43 }
44 
45 
47 {
48  if (!std::isspace(c) && std::isprint(c))
49  {
50  // Should generally work, but need to verify corner cases
52  }
53 
54  return *this;
55 }
56 
57 
59 {
60  const word nonWhiteChars(string::validate<word>(str));
61 
62  if (nonWhiteChars.size() == 1)
63  {
64  // Like punctuation
65  write(nonWhiteChars[0]);
66  }
67  else if (nonWhiteChars.size())
68  {
69  // As a word
70  write(nonWhiteChars);
71  }
72 
73  return *this;
74 }
75 
76 
78 {
79  append(token(str)); // tokenType::WORD
80 
81  return *this;
82 }
83 
84 
86 {
87  append(token(str)); // tokenType::STRING
88 
89  return *this;
90 }
91 
92 
94 (
95  const std::string& str,
96  const bool quoted
97 )
98 {
99  if (quoted)
100  {
101  append(token(string(str))); // tokenType::STRING
102  }
103  else if (!str.empty())
104  {
105  append(token(word(str, false))); // tokenType::WORD
106  }
107 
108  return *this;
109 }
110 
111 
113 {
114  append(token(label(val))); // tokenType::LABEL
115 
116  return *this;
117 }
118 
119 
121 {
122  append(token(label(val))); // tokenType::LABEL
123 
124  return *this;
125 }
126 
127 
129 {
130  append(token(val)); // tokenType::FLOAT
131 
132  return *this;
133 }
134 
135 
137 {
138  append(token(val)); // tokenType::DOUBLE
139 
140  return *this;
141 }
142 
143 
144 Foam::Ostream& Foam::OTstream::write(const char* data, std::streamsize count)
145 {
147  {
149  << "stream format not binary"
151  }
152 
154 
155  return *this;
156 }
157 
158 
160 (
161  const char* data,
162  std::streamsize count
163 )
164 {
165  // No check for format() == BINARY since this is either done in the
166  // beginRawWrite() method, or the caller knows what they are doing.
167 
169 
170  return *this;
171 }
172 
173 
175 {
177  {
179  << "stream format not binary"
181  }
182 
184 
185  return true;
186 }
187 
188 
190 {
191  os << "OTstream : " << name().c_str() << ", " << size() << " tokens, ";
193 }
194 
195 
196 // ************************************************************************* //
Foam::OTstream::write
virtual bool write(const token &tok)
Write token to stream or otherwise handle it.
Definition: OTstream.C:34
Foam::doubleScalar
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
Foam::OTstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OTstream.C:94
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::isspace
bool isspace(char c) noexcept
Test for whitespace (C-locale)
Definition: char.H:65
Foam::floatScalar
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45
Foam::IOstream::print
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: IOstream.C:80
Foam::OTstream::print
void print(Ostream &os) const
Print stream description to Ostream.
Definition: OTstream.C:189
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
format
word format(conversionProperties.get< word >("format"))
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
error.H
Foam::OTstream::writeRaw
virtual Ostream & writeRaw(const char *data, std::streamsize count)
Low-level raw binary output.
Definition: OTstream.C:160
Foam::DynamicList< token >::append
DynamicList< token, 16 > & append(const token &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::token::good
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Definition: tokenI.H:405
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:73
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
OTstream.H
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
Foam::OTstream::beginRawWrite
virtual bool beginRawWrite(std::streamsize count)
Begin marker for low-level raw binary output.
Definition: OTstream.C:174
Foam::token::punctuationToken
punctuationToken
Standard punctuation tokens (a character)
Definition: token.H:120