38 namespace functionEntries
56 void Foam::functionEntries::ifeqEntry::readToken(token& t, Istream& is)
61 if (is.read(t).bad() || is.eof() || !t.good())
70 Foam::token Foam::functionEntries::ifeqEntry::expandToken
72 const dictionary&
dict,
73 const string& keyword,
77 if (keyword[0] ==
'$')
79 const word varName(keyword.substr(1));
85 return token(ePtr->stream());
90 string expanded(keyword);
94 return token(expanded, t.lineNumber());
97 else if (!t.isString())
100 return token(keyword, t.lineNumber());
107 Foam::token Foam::functionEntries::ifeqEntry::expandToken
109 const dictionary&
dict,
115 return expandToken(
dict, t.wordToken(), t);
117 else if (t.isVariable())
119 return expandToken(
dict, t.stringToken(), t);
121 else if (t.isString())
123 return expandToken(
dict, t.stringToken(), t);
130 bool Foam::functionEntries::ifeqEntry::equalToken
136 const bool eqType = (t1.type() == t2.type());
144 return (eqType && t1.boolToken() == t2.boolToken());
147 return (eqType && t1.flagToken() == t2.flagToken());
150 return (eqType && t1.pToken() == t2.pToken());
156 return t1.wordToken() == t2.wordToken();
158 else if (t2.isString())
161 return w2.match(t1.wordToken());
170 return w1.match(
w2) ||
w2.match(
w1);
172 else if (t2.isWord())
175 return w1.match(t2.wordToken());
181 if (t2.isStringType())
183 return t1.stringToken() == t2.stringToken();
190 return t1.labelToken() == t2.labelToken();
192 else if (t2.isScalar())
194 return t1.labelToken() == t2.scalarToken();
201 return equal(t1.floatToken(), t2.floatToken());
203 else if (t2.isLabel())
205 return t1.floatToken() == t2.labelToken();
207 else if (t2.isScalar())
209 return t1.scalarToken() == t2.scalarToken();
216 return equal(t1.doubleToken(), t2.doubleToken());
218 else if (t2.isLabel())
220 return t1.doubleToken() == t2.labelToken();
222 else if (t2.isScalar())
224 return t1.scalarToken() == t2.scalarToken();
242 void Foam::functionEntries::ifeqEntry::skipUntil
244 DynamicList<filePos>& stack,
245 const dictionary& parentDict,
246 const word& endDirective,
255 if (!t.isDirective())
259 else if (t.wordToken() ==
"#if" || t.wordToken() ==
"#ifeq")
261 stack.push_back(filePos(is.name(), is.lineNumber()));
262 skipUntil(stack, parentDict,
"#endif", is);
265 else if (t.wordToken() == endDirective)
272 <<
"Did not find matching " << endDirective <<
nl 291 bool pending =
false;
298 execute(stack, parentDict, is);
303 ifEntry::execute(stack, parentDict, is);
312 skipUntil(stack, parentDict,
"#endif", is);
348 DynamicList<filePos>& stack,
349 dictionary& parentDict,
355 evaluate(
true, stack, parentDict, is);
366 if (!t.isDirective())
371 if (t.wordToken() ==
"#if" || t.wordToken() ==
"#ifeq")
373 stack.push_back(filePos(is.name(), is.lineNumber()));
374 skipUntil(stack, parentDict,
"#endif", is);
377 else if (t.wordToken() ==
"#else")
381 else if (t.wordToken() ==
"#elif")
387 dynamic_cast<ISstream&
>(is).getLine(line);
389 IStringStream lineStream(line);
390 const primitiveEntry
e(
"ifEntry", parentDict, lineStream);
392 if (ifEntry::isTrue(
e.stream()))
399 else if (t.wordToken() ==
"#endif")
406 if (t.wordToken() ==
"#else")
409 evaluate(
false, stack, parentDict, is);
411 else if (t.wordToken() ==
"#elif")
414 evaluate(
true, stack, parentDict, is);
423 DynamicList<filePos>& stack,
424 dictionary& parentDict,
428 const label nNested = stack.size();
430 stack.push_back(filePos(is.name(), is.lineNumber()));
434 cond1 = expandToken(parentDict, cond1);
438 cond2 = expandToken(parentDict, cond2);
440 const bool equal = equalToken(cond1, cond2);
449 if (stack.size() != nNested)
452 <<
"Did not find matching #endif for condition starting" 453 <<
" at line " << stack.back().second()
470 return execute(stack, parentDict, is);
single character punctuation
errorManipArg< error, int > exit(error &err, const int errNo=1)
defineTypeNameAndDebug(codeStream, 0)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
bool equal(const T &a, const T &b)
Compare two values for equality.
stream flag (1-byte bitmask)
const word & wordToken() const
Return const reference to the word contents.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
A token holds an item read from Istream.
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
Compound type such as List<label> etc.
const dimensionedScalar e
Elementary charge.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
float (single-precision) type
void inplaceExpand(std::string &s, const HashTable< string > &mapping, const char sigil='$')
Inplace expand occurrences of variables according to the mapping. Does not use environment values...
Foam::string (usually double-quoted)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static bool evaluate(const bool doIf, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
double (double-precision) type
Macros for easy insertion into member function selection tables.
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Construct from an Istream and insert into the dictionary.
bool isDirective() const noexcept
Token is DIRECTIVE (word variant)
static bool execute(const bool equal, DynamicList< filePos > &stack, dictionary &parentDict, Istream &is)
Main driver: depending on 'equal' starts evaluating or skips forward to else.
bool eof() const noexcept
True if end of input seen.
Detect if the string contains meta-characters.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...