39 bool Foam::JSONformatter::writeToken(
const token& t)
44 case token::tokenType::BOOL:
48 case token::tokenType::LABEL:
49 write(t.labelToken());
52 case token::tokenType::FLOAT:
53 case token::tokenType::DOUBLE:
54 write(t.scalarToken());
57 case token::tokenType::WORD:
58 case token::tokenType::DIRECTIVE:
62 case token::tokenType::STRING:
63 case token::tokenType::EXPRESSION:
64 case token::tokenType::VARIABLE:
65 case token::tokenType::VERBATIM:
66 case token::tokenType::CHAR_DATA:
67 write(t.stringToken());
72 <<
"Problem converting token to JSON:" <<
nl 74 <<
" - treating as null" <<
endl;
115 const auto openBrace = [](
const token& t){
118 const auto closeBrace = [](
const token& t){
123 for (
const entry&
e :
dict)
130 const word& keyword =
e.keyword();
144 const auto& tokens =
e.stream();
146 if (tokens.empty())
continue;
148 if (tokens.size() == 1)
150 writeToken(tokens[0]);
155 if (tokens[0].isLabel() && openBrace(tokens[1]))
160 const token& t = tokens[offset];
165 for (label tokeni=offset; tokeni<tokens.size(); ++tokeni)
167 const token& tk = tokens[tokeni];
175 else if (closeBrace(tk))
182 if (writeToken(tk)) ++i;
184 if (i % 10 == 0) os_ <<
nl;
194 if (tokeni) os_ <<
' ';
195 os_ << tokens[tokeni];
212 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...
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
const dimensionedScalar c
Speed of light in a vacuum.
Ostream & incrIndent(Ostream &os)
Increment the indent level.