39bool Foam::entry::getKeyword(keyType& keyword, token& keyToken, Istream& is)
46 is.read(keyToken).bad()
57 if (keyToken.isWord())
63 if (keyToken.isString())
66 keyword = keyToken.stringToken();
77 const bool valid = getKeyword(keyword, keyToken, is);
92 <<
"--> FOAM Warning :" <<
nl
94 <<
" in file " << __FILE__ <<
" at line " << __LINE__ <<
nl
95 <<
" Reading " << is.relativeName() <<
nl
96 <<
" found " << keyToken <<
nl
115 inpMode == inputMode::GLOBAL
121 if (
mode == inputMode::GLOBAL)
124 <<
"Cannot use 'GLOBAL' as an inputMode"
134 const bool valid = getKeyword(keyword, keyToken, is);
140 return parentDict.
add
142 new dictionaryListEntry(parentDict, is),
157 <<
"Unexpected '}' while reading dictionary entry"
167 <<
"Unexpected EOF while reading dictionary entry"
177 <<
"Found " << keyToken
178 <<
" but expected " << char(endChar)
184 <<
"Found " << keyToken
185 <<
" but expected EOF, or perhaps a '}' char"
197 if (disableFunctionEntries)
199 return parentDict.
add
211 const word functionName(keyword.substr(1),
false);
228 string expanded = keyword.substr(2, keyword.size()-3);
236 keyword.std::string::replace(1, keyword.size()-1, expanded);
241 const word varName = keyword.substr(1);
250 const keyType newKeyword(finder.stream());
252 return parentDict.
add
260 <<
"Attempt to use undefined variable " << varName
268 const bool mergeEntry =
270 mode == inputMode::MERGE
271 ||
mode == inputMode::OVERWRITE
289 <<
"Unexpected token encountered for "
290 << keyword <<
" - " << nextToken.info()
297 !disableFunctionEntries
298 && keyword.contains(
'/')
310 bool mergeEntry =
false;
317 if (
mode == inputMode::PROTECT || keyword ==
"FoamFile")
339 if (
mode == inputMode::ERROR)
342 <<
"duplicate entry: " <<
key
348 if (
mode == inputMode::MERGE)
352 else if (
mode == inputMode::OVERWRITE)
357 finder.dict().clear();
366 return finder.context().add
374 return finder.context().add
385 string fullPath(keyword);
402 if (keyName.find_first_of(
"\"'") == 0)
419 return subDictPtr->add
427 return subDictPtr->add
444 return parentDict.
add
452 return parentDict.
add
471 if (getKeyword(keyword, is))
475 is.putBack(nextToken);
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
bool eof() const noexcept
True if end of input seen.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
A keyword and a list of tokens is a 'dictionaryEntry'.
Read/write List of dictionaries.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const_searcher csearchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using scoping.
dictionary * makeScopedDict(const fileName &dictPath)
Locate existing or create sub-dictionary using slash-scoping.
const_searcher search(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
bool substituteScopedKeyword(const word &keyword, bool mergeEntry=false)
Substitute the given scoped keyword (which is prefixed by '$').
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
const_searcher searchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using dot or slash scoping.
A keyword and a list of tokens is an 'entry'.
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.
static inputMode globalInputMode
The current global input-mode.
inputMode
The input mode options.
@ OVERWRITE
Keep last entry. Silently remove previous ones.
@ PROTECT
Keep initial entry. Silently ignore subsequent ones.
@ GLOBAL
Use global value from globalInputMode variable.
@ MERGE
Merge sub-dictionaries when possible.
@ ERROR
FatalError for duplicate entries.
const keyType & keyword() const noexcept
Return keyword.
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
bool clean()
Cleanup filename (inplace).
word name() const
Return basename (part beyond last /), including its extension.
static std::string path(const std::string &str)
Return directory path name (part before last /).
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
static bool execute(const word &functionName, dictionary &parentDict, Istream &is)
Execute the functionEntry in a sub-dict context.
A class for handling keywords in dictionaries.
@ REGEX
Regular expression.
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
static StringType validate(const std::string &str)
Return a valid String from the given string.
A token holds an item read from Istream.
bool isPunctuation() const noexcept
Token is PUNCTUATION.
@ BEGIN_BLOCK
Begin block [isseparator].
@ END_BLOCK
End block [isseparator].
@ HASH
Hash - directive or start verbatim string.
@ END_STATEMENT
End entry [isseparator].
@ BEGIN_LIST
Begin list [isseparator].
@ DOLLAR
Dollar - start variable or expression.
@ END_LIST
End list [isseparator].
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
A class for handling words, derived from Foam::string.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OBJstream os(runTime.globalPath()/outputName)
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
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.
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).