39bool Foam::JSONformatter::writeToken(
const token& t)
49 write(t.int32Token());
53 write(t.int64Token());
58 write(t.scalarToken());
71 write(t.stringToken());
76 <<
"Problem converting token to JSON:" <<
nl
78 <<
" - treating as null" <<
endl;
119 const auto openBrace = [](
const token& t){
122 const auto closeBrace = [](
const token& t){
134 const word& keyword =
e.keyword();
137 os_.writeQuoted(keyword) <<
" : ";
148 const auto& tokens =
e.stream();
153 <<
"Empty entry for keyword " << keyword <<
nl
154 <<
" - treating value as null" <<
endl;
158 else if (tokens.size() == 1)
160 writeToken(tokens[0]);
165 if (tokens[0].isLabel() && openBrace(tokens[1]))
170 const token& t = tokens[offset];
175 for (label tokeni=offset; tokeni<tokens.size(); ++tokeni)
177 const token& tk = tokens[tokeni];
185 else if (closeBrace(tk))
192 if (writeToken(tk)) ++i;
194 if (i % 10 == 0) os_ <<
nl;
204 if (tokeni) os_ <<
' ';
205 os_ << tokens[tokeni];
222 os_ << (val ?
"true" :
"false");
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true)=0
Write character/string content, with/without surrounding quotes.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A keyword and a list of tokens is an 'entry'.
A class for handling keywords in dictionaries.
A token holds an item read from Istream.
@ DOUBLE
double (double-precision) type
@ CHAR_DATA
String-variant: plain character content.
@ FLOAT
float (single-precision) type
@ STRING
Foam::string (usually double-quoted).
@ BEGIN_SQR
Begin dimensions [isseparator].
@ BEGIN_LIST
Begin list [isseparator].
@ END_LIST
End list [isseparator].
@ END_SQR
End dimensions [isseparator].
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
OBJstream os(runTime.globalPath()/outputName)
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Ostream & indent(Ostream &os)
Indent stream.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.