43 bool dictionary::writeOptionalEntries
52 const Foam::entry* Foam::dictionary::lookupDotScopedSubEntryPtr
61 if (dotPos == string::npos)
64 return lookupEntryPtr(keyword, recursive, patternMatch);
72 const dictionary* dictPtr =
this;
75 string::const_iterator iter = keyword.begin() + begVar;
77 while (iter != keyword.end() && *iter ==
'.')
83 if (&dictPtr->parent_ == &dictionary::null)
88 ) <<
"No parent of current dictionary" 89 <<
" when searching for " 90 << keyword.substr(begVar, keyword.size() - begVar)
93 dictPtr = &dictPtr->parent_;
96 return dictPtr->lookupScopedSubEntryPtr
98 keyword.substr(endVar),
106 word firstWord = keyword.substr(0, dotPos);
108 const entry* entPtr = lookupDotScopedSubEntryPtr
129 const entry* subEntPtr = lookupEntryPtr
131 keyword.substr(0, nextDotPos),
135 if (nextDotPos == string::npos)
141 if (subEntPtr && subEntPtr->isDict())
143 return subEntPtr->dict().lookupDotScopedSubEntryPtr
148 keyword.size() - nextDotPos
155 nextDotPos = keyword.find(
'.', nextDotPos + 1);
159 if (entPtr->isDict())
161 return entPtr->dict().lookupDotScopedSubEntryPtr
163 keyword.substr(dotPos, keyword.size() - dotPos),
177 const Foam::entry* Foam::dictionary::lookupSlashScopedSubEntryPtr
186 if (slashPos == string::npos)
189 return lookupEntryPtr(keyword, recursive, patternMatch);
194 word firstWord = keyword.substr(0, slashPos);
197 if (firstWord ==
".")
199 return lookupScopedSubEntryPtr
201 keyword.substr(slashPos),
206 else if (firstWord ==
"..")
209 if (&parent_ == &dictionary::null)
214 ) <<
"No parent of current dictionary" 215 <<
" when searching for " 216 << keyword.substr(slashPos, keyword.size() - slashPos)
220 return parent_.lookupScopedSubEntryPtr
222 keyword.substr(slashPos),
229 const entry* entPtr = lookupScopedSubEntryPtr
250 const entry* subEntPtr = lookupEntryPtr
252 keyword.substr(0, nextSlashPos),
257 if (nextSlashPos == string::npos)
265 if (subEntPtr && subEntPtr->isDict())
267 return subEntPtr->dict().lookupScopedSubEntryPtr
272 keyword.size() - nextSlashPos
279 nextSlashPos = keyword.find(
'/', nextSlashPos);
283 if (entPtr->isDict())
285 return entPtr->dict().lookupScopedSubEntryPtr
287 keyword.substr(slashPos, keyword.size() - slashPos),
301 const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
310 return lookupDotScopedSubEntryPtr(keyword, recursive, patternMatch);
317 if (emarkPos == string::npos || emarkPos == 0)
321 return lookupSlashScopedSubEntryPtr
333 fileName fName = keyword.substr(0, emarkPos);
335 if (!fName.isAbsolute())
337 fName = topDict().name().path()/fName;
340 if (fName == topDict().
name())
345 ) <<
"Attempt to re-read current dictionary " << fName
351 const word localKeyword = keyword.substr
354 keyword.size() - emarkPos - 1
357 autoPtr<ISstream> ifsPtr
361 ISstream& ifs = ifsPtr();
363 if (!ifs || !ifs.good())
368 ) <<
"dictionary file " << fName
369 <<
" cannot be found for keyword " 374 dictionary
dict(ifs);
388 ) <<
"keyword " << localKeyword
389 <<
" is undefined in dictionary " 394 return hmm->
clone(*this).ptr();
400 bool Foam::dictionary::findInPatterns
402 const bool patternMatch,
405 DLList<autoPtr<regExp>>::const_iterator& reLink
408 if (patternEntries_.size())
410 while (wcLink != patternEntries_.end())
415 ? reLink()->match(Keyword)
416 : wcLink()->keyword() == Keyword
431 bool Foam::dictionary::findInPatterns
433 const bool patternMatch,
436 DLList<autoPtr<regExp>>::iterator& reLink
439 if (patternEntries_.size())
441 while (wcLink != patternEntries_.end())
446 ? reLink()->match(Keyword)
447 : wcLink()->keyword() == Keyword
489 hashedEntries_.insert(iter().keyword(), &iter());
491 if (iter().keyword().isPattern())
493 patternEntries_.insert(&iter());
494 patternRegexps_.insert
510 parent_(dictionary::null)
514 hashedEntries_.insert(iter().keyword(), &iter());
516 if (iter().keyword().isPattern())
518 patternEntries_.insert(&iter());
519 patternRegexps_.insert
535 hashedEntries_(move(dict.hashedEntries_)),
536 parent_(dict.parent_),
537 patternEntries_(move(dict.patternEntries_)),
538 patternRegexps_(move(dict.patternRegexps_))
547 parent_(dictionary::null)
564 hashedEntries_(move(dict.hashedEntries_)),
566 patternEntries_(move(dict.patternEntries_)),
567 patternRegexps_(move(dict.patternRegexps_))
596 if (&p !=
this && !p.
name().empty())
611 return first()->startLineNumber();
624 return last()->endLineNumber();
673 if (hashedEntries_.found(keyword))
679 if (patternMatch && patternEntries_.size())
682 patternEntries_.begin();
684 patternRegexps_.begin();
687 if (findInPatterns(patternMatch, keyword, wcLink, reLink))
693 if (recursive && &parent_ != &dictionary::null)
695 return parent_.
found(keyword, recursive, patternMatch);
714 if (iter == hashedEntries_.end())
716 if (patternMatch && patternEntries_.size())
719 patternEntries_.begin();
721 patternRegexps_.begin();
724 if (findInPatterns(patternMatch, keyword, wcLink, reLink))
730 if (recursive && &parent_ != &dictionary::null)
753 if (iter == hashedEntries_.end())
755 if (patternMatch && patternEntries_.size())
758 patternEntries_.begin();
760 patternRegexps_.begin();
763 if (findInPatterns(patternMatch, keyword, wcLink, reLink))
769 if (recursive && &parent_ != &dictionary::null)
797 if (entryPtr ==
nullptr)
802 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 839 while (&dictPtr->parent_ != &dictionary::null)
841 dictPtr = &dictPtr->parent_;
845 return dictPtr->lookupScopedSubEntryPtr
847 keyword.substr(1, keyword.size() - 1),
854 return lookupScopedSubEntryPtr
866 word varName = keyword(1, keyword.size() - 1);
895 return entryPtr->
isDict();
910 return &entryPtr->
dict();
925 return &entryPtr->
dict();
938 if (entryPtr ==
nullptr)
943 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 947 return entryPtr->
dict();
955 if (entryPtr ==
nullptr)
960 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 964 return entryPtr->
dict();
976 if (entryPtr ==
nullptr)
983 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 986 return entryPtr->
dict();
995 return entryPtr->
dict();
1009 return entryPtr->
dict();
1025 keys[nKeys++] = iter().keyword();
1034 return hashedEntries_.sortedToc();
1045 if (iter().keyword().isPattern() ? patterns : !patterns)
1047 keys[nKeys++] = iter().keyword();
1063 if (mergeEntry && iter != hashedEntries_.end())
1066 if (iter()->isDict() && entryPtr->
isDict())
1068 iter()->dict().merge(entryPtr->
dict());
1078 hashedEntries_.erase(iter);
1080 if (hashedEntries_.insert(entryPtr->
keyword(), entryPtr))
1086 patternEntries_.insert(entryPtr);
1087 patternRegexps_.insert
1098 <<
"problem replacing entry "<< entryPtr->
keyword()
1099 <<
" in dictionary " <<
name() <<
endl;
1108 if (hashedEntries_.insert(entryPtr->
keyword(), entryPtr))
1115 patternEntries_.insert(entryPtr);
1116 patternRegexps_.insert
1137 <<
"attempt to add entry "<< entryPtr->
keyword()
1138 <<
" which already exists in dictionary " <<
name()
1150 add(e.
clone(*this).ptr(), mergeEntry);
1199 if (existingPtr && existingPtr->
isDict())
1203 add(entryPtr,
true);
1209 set(e.
clone(*this).ptr());
1223 if (iter != hashedEntries_.end())
1227 patternEntries_.begin();
1229 patternRegexps_.begin();
1232 if (findInPatterns(
false, Keyword, wcLink, reLink))
1234 patternEntries_.remove(wcLink);
1235 patternRegexps_.remove(reLink);
1240 hashedEntries_.erase(iter);
1259 if (oldKeyword == newKeyword)
1267 if (iter == hashedEntries_.end())
1272 if (iter()->keyword().isPattern())
1277 ) <<
"Old keyword "<< oldKeyword
1279 <<
"Pattern replacement not yet implemented." 1287 if (iter2 != hashedEntries_.end())
1291 if (iter2()->keyword().isPattern())
1295 patternEntries_.begin();
1297 patternRegexps_.begin();
1300 if (findInPatterns(
false, iter2()->keyword(), wcLink, reLink))
1302 patternEntries_.remove(wcLink);
1303 patternRegexps_.remove(reLink);
1309 hashedEntries_.erase(iter2);
1317 ) <<
"cannot rename keyword "<< oldKeyword
1318 <<
" to existing keyword " << newKeyword
1319 <<
" in dictionary " <<
name() <<
endl;
1325 iter()->keyword() = newKeyword;
1326 iter()->name() =
name() +
'/' + newKeyword;
1327 hashedEntries_.erase(oldKeyword);
1328 hashedEntries_.insert(newKeyword, iter());
1332 patternEntries_.insert(iter());
1333 patternRegexps_.insert
1349 <<
"attempted merge to self for dictionary " <<
name()
1353 bool changed =
false;
1359 if (fnd != hashedEntries_.end())
1363 if (fnd()->isDict() && iter().isDict())
1365 if (fnd()->dict().merge(iter().
dict()))
1372 add(iter().
clone(*this).ptr(),
true);
1391 hashedEntries_.clear();
1392 patternEntries_.clear();
1393 patternRegexps_.clear();
1404 hashedEntries_.transfer(dict.hashedEntries_);
1405 patternEntries_.transfer(dict.patternEntries_);
1406 patternRegexps_.transfer(dict.patternRegexps_);
1424 <<
"attempted assignment to self for dictionary " <<
name()
1447 <<
"attempted assignment to self for dictionary " <<
name()
1453 hashedEntries_ = move(rhs.hashedEntries_);
1454 patternEntries_ = move(rhs.patternEntries_);
1455 patternRegexps_ = move(rhs.patternRegexps_);
1465 <<
"attempted addition assignment to self for dictionary " <<
name()
1482 <<
"attempted assignment to self for dictionary " <<
name()
1488 if (!
found(iter().keyword()))
1502 <<
"attempted assignment to self for dictionary " <<
name()
1508 set(iter().clone(*this).ptr());
static bool slash()
Return true if the inputSyntax is slash.
Template class for intrusive linked lists.
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
A class for handling keywords in dictionaries.
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
bool remove(const word &)
Remove an entry specified by keyword.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
label endLineNumber() const
Return line number of last token in dictionary.
void operator=(const dictionary &)
tokenList tokens() const
Return the dictionary as a list of tokens.
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
const keyType & keyword() const
Return keyword.
An STL-conforming const_iterator.
Wrapper around POSIX extended regular expressions.
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void operator+=(const dictionary &)
Include entries from the given dictionary.
List< token > tokenList
List of tokens, used for a IOdictionary entry.
A list of keyword definitions, which are a keyword followed by any number of values (e...
void transfer(ILList< LListBase, T > &)
Transfer the contents of the argument into this List.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Template class for non-intrusive linked lists.
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
dictionaryName()
Construct dictionaryName null.
static const dictionary null
Null dictionary.
An STL-conforming const_iterator.
A token holds items read from Istream.
static const fileName null
An empty fileName.
static bool dot()
Return true if the inputSyntax is dot.
Ostream & endl(Ostream &os)
Add newline and flush stream.
An STL-conforming iterator.
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
const entry & lookupEntry(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream if present otherwise error.
The output stream for calculating SHA1 digests.
T * last()
Return the last entry.
A keyword and a list of tokens is a 'dictionaryEntry'.
void transfer(dictionary &)
Transfer the contents of the argument and annul the argument.
autoPtr< dictionary > clone() const
Construct and return clone.
An STL-conforming const_iterator.
const entry * lookupScopedEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
wordList toc() const
Return the table of contents.
int infoSwitch(const char *name, const int defaultValue=0)
Lookup info switch or add default value.
bool isDict(const word &) const
Check if entry is a sub-dictionary.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
A keyword and a list of tokens is a 'primitiveEntry'. An primitiveEntry can be read, written and printed, and the types and values of its tokens analysed.
dictionary()
Construct top-level dictionary null.
An STL-conforming iterator.
bool changeKeyword(const keyType &oldKeyword, const keyType &newKeyword, bool forceOverwrite=false)
Change the keyword for an entry,.
void operator<<=(const dictionary &)
Unconditionally include entries from the given dictionary.
static int disableFunctionEntries
const fileName & name() const
Return the dictionary name.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
A class for handling words, derived from string.
const dictionary & parent() const
Return the parent dictionary.
void clear()
Clear the contents of the list.
An STL-conforming iterator.
const dictionary & topDict() const
Return the top of the tree.
const fileOperation & fileHandler()
Get current file handler.
T * remove(T *p)
Remove and return element.
graph_traits< Graph >::vertices_size_type size_type
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
virtual bool isDict() const
Return true if this entry is a dictionary.
defineTypeNameAndDebug(combustionModel, 0)
word name(const complex &)
Return a string representation of a complex.
LList< DLListBase, T > DLList
List< keyType > keys(bool patterns=false) const
Return the list of available keys or patterns.
friend class const_iterator
void setSize(const label)
Reset size of List.
void operator|=(const dictionary &)
Conditionally include entries from the given dictionary.
ITstream & operator[](const word &) const
Find and return entry.
void operator=(const dictionaryName &name)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Input from memory buffer stream.
string str() const
Return the string.
virtual const fileName & name() const =0
Return the dictionary name.
virtual ~dictionary()
Destructor.
void set(entry *)
Assign a new entry, overwrite any existing entry.
bool substituteScopedKeyword(const word &keyword)
Substitute the given scoped keyword prepended by '$' with the.
bool merge(const dictionary &)
Merge entries from the given dictionary.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
const doubleScalar e
Elementary charge.
T * first()
Return the first entry.
void clear()
Clear the dictionary.
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
void operator=(const ILList< LListBase, T > &)
Assignment operator.
A class for handling character strings derived from std::string.
Output to memory buffer stream.
label startLineNumber() const
Return line number of first token in dictionary.
wordList sortedToc() const
Return the sorted table of contents.
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Foam::SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
A keyword and a list of tokens is an 'entry'.
bool isPattern() const
Should be treated as a match rather than a literal string.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.