39 bool Foam::JSONformatter::writeToken(
const token& t)
44 case token::tokenType::BOOL:
48 case token::tokenType::INTEGER_32 :
49 write(t.int32Token());
52 case token::tokenType::INTEGER_64 :
53 write(t.int64Token());
56 case token::tokenType::FLOAT:
57 case token::tokenType::DOUBLE:
58 write(t.scalarToken());
61 case token::tokenType::WORD:
62 case token::tokenType::DIRECTIVE:
66 case token::tokenType::STRING:
67 case token::tokenType::EXPRESSION:
68 case token::tokenType::VARIABLE:
69 case token::tokenType::VERBATIM:
70 case token::tokenType::CHAR_DATA:
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){
127 for (
const entry&
e :
dict)
134 const word& keyword =
e.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");
A class for handling keywords in dictionaries.
Ostream & indent(Ostream &os)
Indent stream.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Begin dimensions [isseparator].
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Begin list [isseparator].
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true)=0
Write character/string content, with/without surrounding quotes.
End dimensions [isseparator].
#define forAll(list, i)
Loop across all elements in list.
const dimensionedScalar e
Elementary charge.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
#define DebugInfo
Report an information message using Foam::Info.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
defineTypeNameAndDebug(combustionModel, 0)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionedScalar c
Speed of light in a vacuum.
Ostream & incrIndent(Ostream &os)
Increment the indent level.