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-------------------------------------------------------------------------------
10License
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
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
144Foam::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
174bool Foam::OTstream::beginRawWrite(std::streamsize count)
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// ************************************************************************* //
void append(const token &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
virtual Ostream & writeRaw(const char *data, std::streamsize count)
Low-level raw binary output.
Definition: OTstream.C:160
virtual bool beginRawWrite(std::streamsize count)
Begin marker for low-level raw binary output.
Definition: OTstream.C:174
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OTstream.C:94
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
virtual bool write()
Write the output fields.
scalar print()
Print to screen.
A token holds an item read from Istream.
Definition: token.H:69
punctuationToken
Standard punctuation tokens (a character)
Definition: token.H:121
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Definition: tokenI.H:405
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
runTime write()
word format(conversionProperties.get< word >("format"))