40 bool dictionary::writeOptionalEntries
49 const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
58 if (dotPos == string::npos)
61 return lookupEntryPtr(keyword, recursive, patternMatch);
69 const dictionary* dictPtr =
this;
72 string::const_iterator iter = keyword.begin() + begVar;
74 while (iter != keyword.end() && *iter ==
'.')
80 if (&dictPtr->parent_ == &dictionary::null)
85 ) <<
"No parent of current dictionary" 86 <<
" when searching for " 87 << keyword.substr(begVar, keyword.size()-begVar)
90 dictPtr = &dictPtr->parent_;
93 return dictPtr->lookupScopedSubEntryPtr
95 keyword.substr(endVar),
103 word firstWord = keyword.substr(0, dotPos);
105 const entry* entPtr = lookupScopedSubEntryPtr
126 const entry* subEntPtr = lookupEntryPtr
128 keyword.substr(0, nextDotPos),
132 if (nextDotPos == string::npos)
138 if (subEntPtr && subEntPtr->isDict())
140 return subEntPtr->dict().lookupScopedSubEntryPtr
145 keyword.size()-nextDotPos
152 nextDotPos = keyword.find(
'.', nextDotPos+1);
156 if (entPtr->isDict())
158 return entPtr->dict().lookupScopedSubEntryPtr
160 keyword.substr(dotPos, keyword.size()-dotPos),
174 bool Foam::dictionary::findInPatterns
176 const bool patternMatch,
179 DLList<autoPtr<regExp>>::const_iterator& reLink
182 if (patternEntries_.size())
184 while (wcLink != patternEntries_.end())
189 ? reLink()->match(Keyword)
190 : wcLink()->keyword() == Keyword
205 bool Foam::dictionary::findInPatterns
207 const bool patternMatch,
210 DLList<autoPtr<regExp>>::iterator& reLink
213 if (patternEntries_.size())
215 while (wcLink != patternEntries_.end())
220 ? reLink()->match(Keyword)
221 : wcLink()->keyword() == Keyword
263 hashedEntries_.insert(iter().keyword(), &iter());
265 if (iter().keyword().isPattern())
267 patternEntries_.insert(&iter());
268 patternRegexps_.insert
284 parent_(dictionary::null)
288 hashedEntries_.insert(iter().keyword(), &iter());
290 if (iter().keyword().isPattern())
292 patternEntries_.insert(&iter());
293 patternRegexps_.insert
309 hashedEntries_(move(dict.hashedEntries_)),
310 parent_(dict.parent_),
311 patternEntries_(move(dict.patternEntries_)),
312 patternRegexps_(move(dict.patternRegexps_))
321 parent_(dictionary::null)
338 hashedEntries_(move(dict.hashedEntries_)),
340 patternEntries_(move(dict.patternEntries_)),
341 patternRegexps_(move(dict.patternRegexps_))
367 if (&p !=
this && !p.
name().empty())
382 return first()->startLineNumber();
395 return last()->endLineNumber();
444 if (hashedEntries_.found(keyword))
450 if (patternMatch && patternEntries_.size())
453 patternEntries_.begin();
455 patternRegexps_.begin();
458 if (findInPatterns(patternMatch, keyword, wcLink, reLink))
464 if (recursive && &parent_ != &dictionary::null)
466 return parent_.
found(keyword, recursive, patternMatch);
485 if (iter == hashedEntries_.end())
487 if (patternMatch && patternEntries_.size())
490 patternEntries_.begin();
492 patternRegexps_.begin();
495 if (findInPatterns(patternMatch, keyword, wcLink, reLink))
501 if (recursive && &parent_ != &dictionary::null)
524 if (iter == hashedEntries_.end())
526 if (patternMatch && patternEntries_.size())
529 patternEntries_.begin();
531 patternRegexps_.begin();
534 if (findInPatterns(patternMatch, keyword, wcLink, reLink))
540 if (recursive && &parent_ != &dictionary::null)
568 if (entryPtr ==
nullptr)
573 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 600 if (keyword[0] ==
':')
604 while (&dictPtr->parent_ != &dictionary::null)
606 dictPtr = &dictPtr->parent_;
610 return dictPtr->lookupScopedSubEntryPtr
612 keyword.substr(1, keyword.size()-1),
619 return lookupScopedSubEntryPtr
631 word varName = keyword(1, keyword.size()-1);
660 return entryPtr->
isDict();
675 return &entryPtr->
dict();
690 return &entryPtr->
dict();
703 if (entryPtr ==
nullptr)
708 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 712 return entryPtr->
dict();
720 if (entryPtr ==
nullptr)
725 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 729 return entryPtr->
dict();
741 if (entryPtr ==
nullptr)
748 ) <<
"keyword " << keyword <<
" is undefined in dictionary " 751 return entryPtr->
dict();
760 return entryPtr->
dict();
774 return entryPtr->
dict();
790 keys[nKeys++] = iter().keyword();
799 return hashedEntries_.sortedToc();
810 if (iter().keyword().isPattern() ? patterns : !patterns)
812 keys[nKeys++] = iter().keyword();
828 if (mergeEntry && iter != hashedEntries_.end())
831 if (iter()->isDict() && entryPtr->
isDict())
833 iter()->dict().merge(entryPtr->
dict());
843 hashedEntries_.erase(iter);
845 if (hashedEntries_.insert(entryPtr->
keyword(), entryPtr))
851 patternEntries_.insert(entryPtr);
852 patternRegexps_.insert
863 <<
"problem replacing entry "<< entryPtr->
keyword()
864 <<
" in dictionary " <<
name() <<
endl;
873 if (hashedEntries_.insert(entryPtr->
keyword(), entryPtr))
880 patternEntries_.insert(entryPtr);
881 patternRegexps_.insert
892 <<
"attempt to add entry "<< entryPtr->
keyword()
893 <<
" which already exists in dictionary " <<
name()
904 add(e.
clone(*this).ptr(), mergeEntry);
953 if (existingPtr && existingPtr->
isDict())
963 set(e.
clone(*this).ptr());
977 if (iter != hashedEntries_.end())
981 patternEntries_.begin();
983 patternRegexps_.begin();
986 if (findInPatterns(
false, Keyword, wcLink, reLink))
988 patternEntries_.remove(wcLink);
989 patternRegexps_.remove(reLink);
994 hashedEntries_.erase(iter);
1013 if (oldKeyword == newKeyword)
1021 if (iter == hashedEntries_.end())
1026 if (iter()->keyword().isPattern())
1031 ) <<
"Old keyword "<< oldKeyword
1033 <<
"Pattern replacement not yet implemented." 1041 if (iter2 != hashedEntries_.end())
1045 if (iter2()->keyword().isPattern())
1049 patternEntries_.begin();
1051 patternRegexps_.begin();
1054 if (findInPatterns(
false, iter2()->keyword(), wcLink, reLink))
1056 patternEntries_.remove(wcLink);
1057 patternRegexps_.remove(reLink);
1063 hashedEntries_.erase(iter2);
1071 ) <<
"cannot rename keyword "<< oldKeyword
1072 <<
" to existing keyword " << newKeyword
1073 <<
" in dictionary " <<
name() <<
endl;
1079 iter()->keyword() = newKeyword;
1080 iter()->name() =
name() +
'.' + newKeyword;
1081 hashedEntries_.erase(oldKeyword);
1082 hashedEntries_.insert(newKeyword, iter());
1086 patternEntries_.insert(iter());
1087 patternRegexps_.insert
1103 <<
"attempted merge to self for dictionary " <<
name()
1107 bool changed =
false;
1113 if (fnd != hashedEntries_.end())
1117 if (fnd()->isDict() && iter().isDict())
1119 if (fnd()->dict().merge(iter().
dict()))
1126 add(iter().
clone(*this).ptr(),
true);
1145 hashedEntries_.clear();
1146 patternEntries_.clear();
1147 patternRegexps_.clear();
1158 hashedEntries_.transfer(dict.hashedEntries_);
1159 patternEntries_.transfer(dict.patternEntries_);
1160 patternRegexps_.transfer(dict.patternRegexps_);
1178 <<
"attempted assignment to self for dictionary " <<
name()
1201 <<
"attempted assignment to self for dictionary " <<
name()
1207 hashedEntries_ = move(rhs.hashedEntries_);
1208 patternEntries_ = move(rhs.patternEntries_);
1209 patternRegexps_ = move(rhs.patternRegexps_);
1219 <<
"attempted addition assignment to self for dictionary " <<
name()
1236 <<
"attempted assignment to self for dictionary " <<
name()
1242 if (!
found(iter().keyword()))
1256 <<
"attempted assignment to self for dictionary " <<
name()
1262 set(iter().clone(*this).ptr());
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.
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.
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.
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)
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
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)
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.