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());
182 if (t2.isStringType())
184 return t1.stringToken() == t2.stringToken();
191 return t1.labelToken() == t2.labelToken();
193 else if (t2.isScalar())
195 return t1.labelToken() == t2.scalarToken();
202 return equal(t1.floatToken(), t2.floatToken());
204 else if (t2.isLabel())
206 return t1.floatToken() == t2.labelToken();
208 else if (t2.isScalar())
210 return t1.scalarToken() == t2.scalarToken();
217 return equal(t1.doubleToken(), t2.doubleToken());
219 else if (t2.isLabel())
221 return t1.doubleToken() == t2.labelToken();
223 else if (t2.isScalar())
225 return t1.scalarToken() == t2.scalarToken();
243 void Foam::functionEntries::ifeqEntry::skipUntil
245 DynamicList<filePos>& stack,
246 const dictionary& parentDict,
247 const word& endDirective,
256 if (!t.isDirective())
260 else if (t.wordToken() ==
"#if" || t.wordToken() ==
"#ifeq")
262 stack.push_back(filePos(is.name(), is.lineNumber()));
263 skipUntil(stack, parentDict,
"#endif", is);
266 else if (t.wordToken() == endDirective)
273 <<
"Did not find matching " << endDirective <<
nl 292 bool pending =
false;
299 execute(stack, parentDict, is);
304 ifEntry::execute(stack, parentDict, is);
313 skipUntil(stack, parentDict,
"#endif", is);
349 DynamicList<filePos>& stack,
350 dictionary& parentDict,
356 evaluate(
true, stack, parentDict, is);
367 if (!t.isDirective())
372 if (t.wordToken() ==
"#if" || t.wordToken() ==
"#ifeq")
374 stack.push_back(filePos(is.name(), is.lineNumber()));
375 skipUntil(stack, parentDict,
"#endif", is);
378 else if (t.wordToken() ==
"#else")
382 else if (t.wordToken() ==
"#elif")
388 dynamic_cast<ISstream&
>(is).getLine(line);
390 IStringStream lineStream(line);
391 const primitiveEntry
e(
"ifEntry", parentDict, lineStream);
393 if (ifEntry::isTrue(
e.stream()))
400 else if (t.wordToken() ==
"#endif")
407 if (t.wordToken() ==
"#else")
410 evaluate(
false, stack, parentDict, is);
412 else if (t.wordToken() ==
"#elif")
415 evaluate(
true, stack, parentDict, is);
424 DynamicList<filePos>& stack,
425 dictionary& parentDict,
429 const label nNested = stack.size();
431 stack.push_back(filePos(is.name(), is.lineNumber()));
435 cond1 = expandToken(parentDict, cond1);
439 cond2 = expandToken(parentDict, cond2);
441 const bool equal = equalToken(cond1, cond2);
450 if (stack.size() != nNested)
453 <<
"Did not find matching #endif for condition starting" 454 <<
" at line " << stack.back().second()
471 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 (copy). 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.
String-variant: plain character content.
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 ...