diff --git a/applications/utilities/miscellaneous/foamInfoExec/foamInfoExec.C b/applications/utilities/miscellaneous/foamInfoExec/foamInfoExec.C index 50bf81035f..7bff5f4c23 100644 --- a/applications/utilities/miscellaneous/foamInfoExec/foamInfoExec.C +++ b/applications/utilities/miscellaneous/foamInfoExec/foamInfoExec.C @@ -100,13 +100,23 @@ int main(int argc, char *argv[]) if (dict.found(entryNames[0])) { - const entry* entPtr = &dict.lookupEntry(entryNames[0]); + const entry* entPtr = &dict.lookupEntry + ( + entryNames[0], + false, + true // wildcards + ); for (int i=1; idict().found(entryNames[i])) { - entPtr = &entPtr->dict().lookupEntry(entryNames[i]); + entPtr = &entPtr->dict().lookupEntry + ( + entryNames[i], + false, + true // wildcards + ); } else { diff --git a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamI.H b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamI.H index 8f9f682cdc..427c0a6fde 100644 --- a/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamI.H +++ b/applications/utilities/postProcessing/graphics/PV3FoamReader/vtkPV3Foam/vtkPV3FoamI.H @@ -37,7 +37,7 @@ inline Foam::word Foam::vtkPV3Foam::getFirstWord(const char* str) { ++n; } - return word(str, n); + return word(str, n, true); } else { diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C index f24729da97..ec5d019310 100644 --- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C +++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C @@ -164,7 +164,16 @@ int main(int argc, char *argv[]) forAll(dictList, i) { doneKeys[i] = dictList[i].keyword(); - dictList.set(i, fieldDict.lookupEntry(doneKeys[i]).clone()); + dictList.set + ( + i, + fieldDict.lookupEntry + ( + doneKeys[i], + false, + true + ).clone() + ); fieldDict.remove(doneKeys[i]); } // Add remaining entries diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index cf4e331e25..e24fd6b5ec 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -39,6 +39,7 @@ $(strings)/word/word.C $(strings)/word/wordIO.C $(strings)/fileName/fileName.C $(strings)/fileName/fileNameIO.C +$(strings)/keyType/keyTypeIO.C primitives/random/Random.C diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C index f0d3f8fd1a..577494aa1c 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.C @@ -22,15 +22,31 @@ License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -Description - \*---------------------------------------------------------------------------*/ +#include "word.H" #include "Ostream.H" #include "token.H" +#include "keyType.H" +#include "IOstreams.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +//- Write keyType +Foam::Ostream& Foam::Ostream::write(const keyType& s) +{ + // Write as word? + if (s.isWildCard()) + { + return write(static_cast(s)); + } + else + { + return write(static_cast(s)); + } +} + + //- Decrememt the indent level void Foam::Ostream::decrIndent() { @@ -47,7 +63,7 @@ void Foam::Ostream::decrIndent() // Write the keyword to the Ostream followed by appropriate indentation -Foam::Ostream& Foam::Ostream::writeKeyword(const Foam::word& keyword) +Foam::Ostream& Foam::Ostream::writeKeyword(const Foam::keyType& keyword) { indent(); write(keyword); diff --git a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H index bcd081df56..6dc7df259a 100644 --- a/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H +++ b/src/OpenFOAM/db/IOstreams/IOstreams/Ostream.H @@ -35,6 +35,7 @@ Description #define Ostream_H #include "IOstream.H" +#include "keyType.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -105,6 +106,9 @@ public: //- Write word virtual Ostream& write(const word&) = 0; + //- Write keyType + virtual Ostream& write(const keyType&); + //- Write string virtual Ostream& write(const string&) = 0; @@ -146,7 +150,7 @@ public: //- Write the keyword to the Ostream followed by // appropriate indentation - Ostream& writeKeyword(const word& keyword); + Ostream& writeKeyword(const keyType& keyword); // Stream state functions diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 8a38ff9ba2..ad960e7405 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -34,6 +34,72 @@ defineTypeNameAndDebug(Foam::dictionary, 0); const Foam::dictionary Foam::dictionary::null; + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +bool Foam::dictionary::findInWildcards +( + const bool wildCardMatch, + const word& Keyword, + DLList::const_iterator& wcLink, + DLList >::const_iterator& reLink +) const +{ + if (wildCardEntries_.size() > 0) + { + //wcLink = wildCardEntries_.begin(); + //reLink = wildCardRegexps_.end(); + + while (wcLink != wildCardEntries_.end()) + { + if (!wildCardMatch && wcLink()->keyword() == Keyword) + { + return true; + } + else if (wildCardMatch && reLink()->matches(Keyword)) + { + return true; + } + + ++reLink; + ++wcLink; + } + } + + return false; +} + + +bool Foam::dictionary::findInWildcards +( + const bool wildCardMatch, + const word& Keyword, + DLList::iterator& wcLink, + DLList >::iterator& reLink +) +{ + if (wildCardEntries_.size() > 0) + { + while (wcLink != wildCardEntries_.end()) + { + if (!wildCardMatch && wcLink()->keyword() == Keyword) + { + return true; + } + else if (wildCardMatch && reLink()->matches(Keyword)) + { + return true; + } + + ++reLink; + ++wcLink; + } + } + + return false; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::dictionary::dictionary() @@ -60,6 +126,18 @@ Foam::dictionary::dictionary ) { hashedEntries_.insert(iter().keyword(), &iter()); + + if (iter().keyword().isWildCard()) + { + wildCardEntries_.insert(&iter()); + wildCardRegexps_.insert + ( + autoPtr + ( + new regularExpression(iter().keyword()) + ) + ); + } } } @@ -81,6 +159,18 @@ Foam::dictionary::dictionary ) { hashedEntries_.insert(iter().keyword(), &iter()); + + if (iter().keyword().isWildCard()) + { + wildCardEntries_.insert(&iter()); + wildCardRegexps_.insert + ( + autoPtr + ( + new regularExpression(iter().keyword()) + ) + ); + } } } @@ -133,13 +223,29 @@ bool Foam::dictionary::found(const word& keyword, bool recursive) const { return true; } - else if (recursive && &parent_ != &dictionary::null) - { - return parent_.found(keyword, recursive); - } else { - return false; + if (wildCardEntries_.size() > 0) + { + DLList::const_iterator wcLink = wildCardEntries_.begin(); + DLList >::const_iterator reLink = + wildCardRegexps_.begin(); + + // Find in wildcards using regular expressions only + if (findInWildcards(true, keyword, wcLink, reLink)) + { + return true; + } + } + + if (recursive && &parent_ != &dictionary::null) + { + return parent_.found(keyword, recursive); + } + else + { + return false; + } } } @@ -147,16 +253,31 @@ bool Foam::dictionary::found(const word& keyword, bool recursive) const const Foam::entry* Foam::dictionary::lookupEntryPtr ( const word& keyword, - bool recursive + bool recursive, + bool wildCardMatch ) const { HashTable::const_iterator iter = hashedEntries_.find(keyword); if (iter == hashedEntries_.end()) { + if (wildCardMatch && wildCardEntries_.size() > 0) + { + DLList::const_iterator wcLink = + wildCardEntries_.begin(); + DLList >::const_iterator reLink = + wildCardRegexps_.begin(); + + // Find in wildcards using regular expressions only + if (findInWildcards(wildCardMatch, keyword, wcLink, reLink)) + { + return wcLink(); + } + } + if (recursive && &parent_ != &dictionary::null) { - return parent_.lookupEntryPtr(keyword, recursive); + return parent_.lookupEntryPtr(keyword, recursive, wildCardMatch); } else { @@ -171,19 +292,34 @@ const Foam::entry* Foam::dictionary::lookupEntryPtr Foam::entry* Foam::dictionary::lookupEntryPtr ( const word& keyword, - bool recursive + bool recursive, + bool wildCardMatch ) { HashTable::iterator iter = hashedEntries_.find(keyword); if (iter == hashedEntries_.end()) { + if (wildCardMatch && wildCardEntries_.size() > 0) + { + DLList::iterator wcLink = + wildCardEntries_.begin(); + DLList >::iterator reLink = + wildCardRegexps_.begin(); + // Find in wildcards using regular expressions only + if (findInWildcards(wildCardMatch, keyword, wcLink, reLink)) + { + return wcLink(); + } + } + if (recursive && &parent_ != &dictionary::null) { return const_cast(parent_).lookupEntryPtr ( keyword, - recursive + recursive, + wildCardMatch ); } else @@ -199,16 +335,17 @@ Foam::entry* Foam::dictionary::lookupEntryPtr const Foam::entry& Foam::dictionary::lookupEntry ( const word& keyword, - bool recursive + bool recursive, + bool wildCardMatch ) const { - const entry* entryPtr = lookupEntryPtr(keyword, recursive); + const entry* entryPtr = lookupEntryPtr(keyword, recursive, wildCardMatch); if (entryPtr == NULL) { FatalIOErrorIn ( - "dictionary::lookupEntry(const word& keyword) const", + "dictionary::lookupEntry(const word&, bool, bool) const", *this ) << "keyword " << keyword << " is undefined in dictionary " << name() @@ -222,16 +359,18 @@ const Foam::entry& Foam::dictionary::lookupEntry Foam::ITstream& Foam::dictionary::lookup ( const word& keyword, - bool recursive + bool recursive, + bool wildCardMatch ) const { - return lookupEntry(keyword, recursive).stream(); + return lookupEntry(keyword, recursive, wildCardMatch).stream(); } bool Foam::dictionary::isDict(const word& keyword) const { - const entry* entryPtr = lookupEntryPtr(keyword); + // Find non-recursive with wildcards + const entry* entryPtr = lookupEntryPtr(keyword, false, true); if (entryPtr) { @@ -246,7 +385,7 @@ bool Foam::dictionary::isDict(const word& keyword) const const Foam::dictionary* Foam::dictionary::subDictPtr(const word& keyword) const { - const entry* entryPtr = lookupEntryPtr(keyword); + const entry* entryPtr = lookupEntryPtr(keyword, false, true); if (entryPtr) { @@ -261,7 +400,8 @@ const Foam::dictionary* Foam::dictionary::subDictPtr(const word& keyword) const const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const { - const entry* entryPtr = lookupEntryPtr(keyword); + const entry* entryPtr = lookupEntryPtr(keyword, false, true); + if (entryPtr == NULL) { FatalIOErrorIn @@ -278,7 +418,8 @@ const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) const Foam::dictionary& Foam::dictionary::subDict(const word& keyword) { - entry* entryPtr = lookupEntryPtr(keyword); + entry* entryPtr = lookupEntryPtr(keyword, false, true); + if (entryPtr == NULL) { FatalIOErrorIn @@ -314,7 +455,10 @@ Foam::wordList Foam::dictionary::toc() const bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) { - HashTable::iterator iter = hashedEntries_.find(entryPtr->keyword()); + HashTable::iterator iter = hashedEntries_.find + ( + entryPtr->keyword() + ); if (mergeEntry && iter != hashedEntries_.end()) { @@ -336,6 +480,19 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) if (hashedEntries_.insert(entryPtr->keyword(), entryPtr)) { entryPtr->name() = name_ + "::" + entryPtr->keyword(); + + if (entryPtr->keyword().isWildCard()) + { + wildCardEntries_.insert(entryPtr); + wildCardRegexps_.insert + ( + autoPtr + ( + new regularExpression(entryPtr->keyword()) + ) + ); + } + return true; } else @@ -356,6 +513,18 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) entryPtr->name() = name_ + "::" + entryPtr->keyword(); IDLList::append(entryPtr); + if (entryPtr->keyword().isWildCard()) + { + wildCardEntries_.insert(entryPtr); + wildCardRegexps_.insert + ( + autoPtr + ( + new regularExpression(entryPtr->keyword()) + ) + ); + } + return true; } else @@ -376,27 +545,37 @@ void Foam::dictionary::add(const entry& e, bool mergeEntry) add(e.clone(*this).ptr(), mergeEntry); } -void Foam::dictionary::add(const word& k, const word& w, bool overwrite) +void Foam::dictionary::add(const keyType& k, const word& w, bool overwrite) { add(new primitiveEntry(k, token(w)), overwrite); } -void Foam::dictionary::add(const word& k, const Foam::string& s, bool overwrite) +void Foam::dictionary::add +( + const keyType& k, + const Foam::string& s, + bool overwrite +) { add(new primitiveEntry(k, token(s)), overwrite); } -void Foam::dictionary::add(const word& k, const label l, bool overwrite) +void Foam::dictionary::add(const keyType& k, const label l, bool overwrite) { add(new primitiveEntry(k, token(l)), overwrite); } -void Foam::dictionary::add(const word& k, const scalar s, bool overwrite) +void Foam::dictionary::add(const keyType& k, const scalar s, bool overwrite) { add(new primitiveEntry(k, token(s)), overwrite); } -void Foam::dictionary::add(const word& k, const dictionary& d, bool mergeEntry) +void Foam::dictionary::add +( + const keyType& k, + const dictionary& d, + bool mergeEntry +) { add(new dictionaryEntry(k, *this, d), mergeEntry); } @@ -404,7 +583,7 @@ void Foam::dictionary::add(const word& k, const dictionary& d, bool mergeEntry) void Foam::dictionary::set(entry* entryPtr) { - entry* existingPtr = lookupEntryPtr(entryPtr->keyword()); + entry* existingPtr = lookupEntryPtr(entryPtr->keyword(), false, true); // clear dictionary so merge acts like overwrite if (existingPtr && existingPtr->isDict()) @@ -420,7 +599,7 @@ void Foam::dictionary::set(const entry& e) set(e.clone(*this).ptr()); } -void Foam::dictionary::set(const word& k, const dictionary& d) +void Foam::dictionary::set(const keyType& k, const dictionary& d) { set(new dictionaryEntry(k, *this, d)); } @@ -432,6 +611,19 @@ bool Foam::dictionary::remove(const word& Keyword) if (iter != hashedEntries_.end()) { + // Delete from wildcards first + DLList::iterator wcLink = + wildCardEntries_.begin(); + DLList >::iterator reLink = + wildCardRegexps_.begin(); + + // Find in wildcards using exact match only + if (findInWildcards(false, Keyword, wcLink, reLink)) + { + wildCardEntries_.remove(wcLink); + wildCardRegexps_.remove(reLink); + } + IDLList::remove(iter()); delete iter(); hashedEntries_.erase(iter); @@ -447,8 +639,8 @@ bool Foam::dictionary::remove(const word& Keyword) bool Foam::dictionary::changeKeyword ( - const word& oldKeyword, - const word& newKeyword, + const keyType& oldKeyword, + const keyType& newKeyword, bool forceOverwrite ) { @@ -466,6 +658,18 @@ bool Foam::dictionary::changeKeyword return false; } + if (iter()->keyword().isWildCard()) + { + FatalErrorIn + ( + "dictionary::changeKeyword(const word&, const word&, bool)" + ) << "Old keyword "<< oldKeyword + << " is a wildcard." + << "Wildcard replacement not yet implemented." + << exit(FatalError); + } + + HashTable::iterator iter2 = hashedEntries_.find(newKeyword); // newKeyword already exists @@ -473,14 +677,33 @@ bool Foam::dictionary::changeKeyword { if (forceOverwrite) { + if (iter2()->keyword().isWildCard()) + { + // Delete from wildcards first + DLList::iterator wcLink = + wildCardEntries_.begin(); + DLList >::iterator reLink = + wildCardRegexps_.begin(); + + // Find in wildcards using exact match only + if (findInWildcards(false, iter2()->keyword(), wcLink, reLink)) + { + wildCardEntries_.remove(wcLink); + wildCardRegexps_.remove(reLink); + } + } + IDLList::replace(iter2(), iter()); delete iter2(); hashedEntries_.erase(iter2); + } else { - WarningIn("dictionary::changeKeyword(const word&, const word&)") - << "cannot rename keyword "<< oldKeyword + WarningIn + ( + "dictionary::changeKeyword(const word&, const word&, bool)" + ) << "cannot rename keyword "<< oldKeyword << " to existing keyword " << newKeyword << " in dictionary " << name() << endl; return false; @@ -493,6 +716,18 @@ bool Foam::dictionary::changeKeyword hashedEntries_.erase(oldKeyword); hashedEntries_.insert(newKeyword, iter()); + if (newKeyword.isWildCard()) + { + wildCardEntries_.insert(iter()); + wildCardRegexps_.insert + ( + autoPtr + ( + new regularExpression(newKeyword) + ) + ); + } + return true; } @@ -579,6 +814,7 @@ void Foam::dictionary::operator=(const dictionary& dict) // Create clones of the entries in the given dictionary // resetting the parentDict to this dictionary + for ( IDLList::const_iterator iter = dict.begin(); @@ -586,17 +822,7 @@ void Foam::dictionary::operator=(const dictionary& dict) ++iter ) { - IDLList::append(iter().clone(*this).ptr()); - } - - for - ( - IDLList::iterator iter = begin(); - iter != end(); - ++iter - ) - { - hashedEntries_.insert(iter().keyword(), &iter()); + add(iter().clone(*this).ptr()); } } diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 05872cce61..00198b7b82 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -27,7 +27,12 @@ Class Description A list of keyword definitions, which are a keyword followed by any number - of values (e.g. words and numbers). + of values (e.g. words and numbers). The keywords can represent wildcards + which are matched using Posix regular expressions. The general order for + searching is + - exact match + - wildcard match + - optional recursion into subdictionaries The dictionary class is the base class for IOdictionary. It also serves as a bootstrap dictionary for the objectRegistry data @@ -49,11 +54,13 @@ SourceFiles #include "entry.H" #include "IDLList.H" +#include "DLList.H" #include "fileName.H" #include "ITstream.H" #include "HashTable.H" #include "wordList.H" #include "className.H" +#include "regularExpression.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -80,12 +87,40 @@ class dictionary //- Dictionary name fileName name_; - //- HashTable of the enries held on the DL-list for quick lookup + //- HashTable of the entries held on the DL-list for quick lookup HashTable hashedEntries_; //- Parent dictionary const dictionary& parent_; + //- Wildcard entries + DLList wildCardEntries_; + + //- Wildcard precompiled regex + DLList > wildCardRegexps_; + + // Private Member Functions + + //- Search wildcard table either for exact match or for regular + // expression match. + bool findInWildcards + ( + const bool wildCardMatch, + const word& Keyword, + DLList::const_iterator& wcLink, + DLList >::const_iterator& reLink + ) const; + + //- Search wildcard table either for exact match or for regular + // expression match. + bool findInWildcards + ( + const bool wildCardMatch, + const word& Keyword, + DLList::iterator& wcLink, + DLList >::iterator& reLink + ); + public: @@ -181,24 +216,44 @@ public: //- Find and return an entry data stream pointer if present // otherwise return NULL. - // If recursive search parent dictionaries + // If recursive search parent dictionaries. If wildCardMatch + // use wildcards. const entry* lookupEntryPtr ( - const word&, bool recursive=false + const word&, + bool recursive, + bool wildCardMatch ) const; //- Find and return an entry data stream pointer for manipulation // if present otherwise return NULL. - // If recursive search parent dictionaries - entry* lookupEntryPtr(const word&, bool recursive=false); + // If recursive search parent dictionaries. If wildCardMatch + // use wildcards. + entry* lookupEntryPtr + ( + const word&, + bool recursive, + bool wildCardMatch + ); //- Find and return an entry data stream if present otherwise error. - // If recursive search parent dictionaries - const entry& lookupEntry(const word&, bool recursive=false) const; + // If recursive search parent dictionaries. If wildCardMatch + // use wildcards. + const entry& lookupEntry + ( + const word&, + bool recursive, + bool wildCardMatch + ) const; //- Find and return an entry data stream // If recursive search parent dictionaries - ITstream& lookup(const word&, bool recursive=false) const; + ITstream& lookup + ( + const word&, + bool recursive=false, + bool wildCardMatch=true + ) const; //- Find and return a T, // if not found return the given default value @@ -208,7 +263,8 @@ public: ( const word&, const T&, - bool recursive=false + bool recursive=false, + bool wildCardMatch=true ) const; //- Find and return a T, if not found return the given @@ -219,7 +275,8 @@ public: ( const word&, const T&, - bool recursive=false + bool recursive=false, + bool wildCardMatch=true ); //- Find an entry if present, and assign to T @@ -229,7 +286,8 @@ public: ( const word&, T&, - bool recursive=false + bool recursive=false, + bool wildCardMatch=true ) const; //- Check if entry is a sub-dictionary @@ -248,7 +306,6 @@ public: //- Return the table of contents wordList toc() const; - // Editing //- Add a new entry @@ -263,25 +320,25 @@ public: //- Add a word entry // optionally overwrite an existing entry - void add(const word& keyword, const word&, bool overwrite=false); + void add(const keyType&, const word&, bool overwrite=false); //- Add a string entry // optionally overwrite an existing entry - void add(const word& keyword, const string&, bool overwrite=false); + void add(const keyType&, const string&, bool overwrite=false); //- Add a label entry // optionally overwrite an existing entry - void add(const word& keyword, const label, bool overwrite=false); + void add(const keyType&, const label, bool overwrite=false); //- Add a scalar entry // optionally overwrite an existing entry - void add (const word& keyword, const scalar, bool overwrite=false); + void add (const keyType&, const scalar, bool overwrite=false); //- Add a dictionary entry // optionally merge with an existing sub-dictionary void add ( - const word& keyword, + const keyType& keyword, const dictionary&, bool mergeEntry=false ); @@ -289,7 +346,7 @@ public: //- Add a T entry // optionally overwrite an existing entry template - void add(const word& keyword, const T&, bool overwrite=false); + void add(const keyType& keyword, const T&, bool overwrite=false); //- Assign a new entry, overwrite any existing entry void set(entry*); @@ -298,11 +355,11 @@ public: void set(const entry&); //- Assign a dictionary entry, overwrite any existing entry - void set(const word& keyword, const dictionary&); + void set(const keyType& keyword, const dictionary&); //- Assign a T entry, overwrite any existing entry template - void set(const word& keyword, const T&); + void set(const keyType& keyword, const T&); //- Remove an entry specified by keyword bool remove(const word& keyword); @@ -311,8 +368,8 @@ public: // optionally forcing overwrite of an existing entry bool changeKeyword ( - const word& oldKeyword, - const word& newKeyword, + const keyType& oldKeyword, + const keyType& newKeyword, bool forceOverwrite = false ); @@ -361,11 +418,13 @@ public: // Global Operators -//- Combine dictionaries starting from the entries in dict1 and then including those from dict2. +//- Combine dictionaries starting from the entries in dict1 and then including +// those from dict2. // Warn, but do not overwrite the entries from dict1. dictionary operator+(const dictionary& dict1, const dictionary& dict2); -//- Combine dictionaries starting from the entries in dict1 and then including those from dict2. +//- Combine dictionaries starting from the entries in dict1 and then including +// those from dict2. // Do not overwrite the entries from dict1. dictionary operator|(const dictionary& dict1, const dictionary& dict2); diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C index 9beb835bcb..6dea212507 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.C @@ -30,7 +30,7 @@ License Foam::dictionaryEntry::dictionaryEntry ( - const word& key, + const keyType& key, const dictionary& parentDict, const dictionary& dict ) diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H index 2812c1b0bb..3e86e969b2 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntry.H @@ -43,6 +43,7 @@ SourceFiles #ifndef dictionaryEntry_H #define dictionaryEntry_H +#include "keyType.H" #include "entry.H" #include "dictionary.H" #include "InfoProxy.H" @@ -79,7 +80,7 @@ public: //- Construct from the keyword, parent dictionary and a Istream dictionaryEntry ( - const word& keyword, + const keyType& keyword, const dictionary& parentDict, Istream& is ); @@ -87,7 +88,7 @@ public: //- Construct from the keyword, parent dictionary and a dictionary dictionaryEntry ( - const word& keyword, + const keyType& keyword, const dictionary& parentDict, const dictionary& dict ); diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index b6c2c2ebce..9cce3eb7de 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -27,7 +27,9 @@ Description \*---------------------------------------------------------------------------*/ +#include "keyType.H" #include "dictionaryEntry.H" +#include "IOstreams.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -43,14 +45,14 @@ Foam::dictionaryEntry::dictionaryEntry is.fatalCheck ( "dictionaryEntry::dictionaryEntry" - "(Istream& is, const dictionary& parentDict)" + "(const dictionary& parentDict, Istream& is)" ); } Foam::dictionaryEntry::dictionaryEntry ( - const word& key, + const keyType& key, const dictionary& parentDict, Istream& is ) @@ -63,7 +65,7 @@ Foam::dictionaryEntry::dictionaryEntry is.fatalCheck ( "dictionaryEntry::dictionaryEntry" - "(const word& keyword, const dictionary& parentDict, Istream& is)" + "(const keyType& keyword, const dictionary& parentDict, Istream& is)" ); } diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index 53069af0b0..b1d5fbcbc4 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -71,7 +71,7 @@ bool Foam::dictionary::substituteKeyword(const word& keyword) word varName = keyword(1, keyword.size()-1); // lookup the variable name in the given dictionary.... - const entry* ePtr = lookupEntryPtr(varName, true); + const entry* ePtr = lookupEntryPtr(varName, true, true); // ...if defined insert its entries into this dictionary... if (ePtr != NULL) @@ -137,6 +137,8 @@ Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict) dict.clear(); dict.hashedEntries_.clear(); + dict.wildCardEntries_.clear(); + dict.wildCardRegexps_.clear(); dict.read(is); return is; diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C index 3dc32a7b51..a47a976814 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C +++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C @@ -34,10 +34,11 @@ T Foam::dictionary::lookupOrDefault ( const word& keyword, const T& deflt, - bool recursive + bool recursive, + bool wildCardMatch ) const { - const entry* entryPtr = lookupEntryPtr(keyword, recursive); + const entry* entryPtr = lookupEntryPtr(keyword, recursive, wildCardMatch); if (entryPtr == NULL) { @@ -55,10 +56,11 @@ T Foam::dictionary::lookupOrAddDefault ( const word& keyword, const T& deflt, - bool recursive + bool recursive, + bool wildCardMatch ) { - const entry* entryPtr = lookupEntryPtr(keyword, recursive); + const entry* entryPtr = lookupEntryPtr(keyword, recursive, wildCardMatch); if (entryPtr == NULL) { @@ -77,10 +79,11 @@ bool Foam::dictionary::readIfPresent ( const word& k, T& val, - bool recursive + bool recursive, + bool wildCardMatch ) const { - const entry* entryPtr = lookupEntryPtr(k, recursive); + const entry* entryPtr = lookupEntryPtr(k, recursive, wildCardMatch); if (entryPtr == NULL) { @@ -95,16 +98,17 @@ bool Foam::dictionary::readIfPresent template -void Foam::dictionary::add(const word& k, const T& t, bool overwrite) +void Foam::dictionary::add(const keyType& k, const T& t, bool overwrite) { add(new primitiveEntry(k, t), overwrite); } template -void Foam::dictionary::set(const word& k, const T& t) +void Foam::dictionary::set(const keyType& k, const T& t) { set(new primitiveEntry(k, t)); } + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C index 93cf677b0b..54581d869b 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/db/dictionary/entry/entry.C @@ -30,7 +30,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::entry::entry(const word& keyword) +Foam::entry::entry(const keyType& keyword) : keyword_(keyword) {} diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H index 5afab95b5a..974074862b 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.H +++ b/src/OpenFOAM/db/dictionary/entry/entry.H @@ -42,6 +42,7 @@ SourceFiles #ifndef entry_H #define entry_H +#include "keyType.H" #include "IDLList.H" #include "fileName.H" #include "autoPtr.H" @@ -70,21 +71,18 @@ class entry // Private data //- Keyword of entry - word keyword_; + keyType keyword_; // Private Member Functions - //- Get the next valid keyword otherwise return false - static bool getKeyword(word& keyword, Istream& is); - public: // Constructors //- Construct from keyword - entry(const word& keyword); + entry(const keyType& keyword); //- Construct as copy entry(const entry&); @@ -115,14 +113,17 @@ public: // Member functions + //- Get the next valid keyword otherwise return false + static bool getKeyword(keyType& keyword, Istream& is); + //- Return keyword - const word& keyword() const + const keyType& keyword() const { return keyword_; } //- Return non-const access to keyword - word& keyword() + keyType& keyword() { return keyword_; } diff --git a/src/OpenFOAM/db/dictionary/entry/entryIO.C b/src/OpenFOAM/db/dictionary/entry/entryIO.C index 830c21cf8a..d131acb8e6 100644 --- a/src/OpenFOAM/db/dictionary/entry/entryIO.C +++ b/src/OpenFOAM/db/dictionary/entry/entryIO.C @@ -32,7 +32,7 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -bool Foam::entry::getKeyword(word& keyword, Istream& is) +bool Foam::entry::getKeyword(keyType& keyword, Istream& is) { token keywordToken; @@ -57,6 +57,12 @@ bool Foam::entry::getKeyword(word& keyword, Istream& is) keyword = keywordToken.wordToken(); return true; } + else if (keywordToken.isString()) + { + // Enable wildcards + keyword = keywordToken.stringToken(); + return true; + } // If it is the end of the dictionary or file return false... else if (keywordToken == token::END_BLOCK || is.eof()) { @@ -67,7 +73,7 @@ bool Foam::entry::getKeyword(word& keyword, Istream& is) { cerr<< "--> FOAM Warning : " << std::endl << " From function " - << "entry::getKeyword(word& keyword, Istream& is)" << std::endl + << "entry::getKeyword(keyType& keyword, Istream& is)" << std::endl << " in file " << __FILE__ << " at line " << __LINE__ << std::endl << " Reading " << is.name().c_str() << std::endl @@ -84,7 +90,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is) { is.fatalCheck("entry::New(const dictionary& parentDict, Istream& is)"); - word keyword; + keyType keyword; // Get the next keyword and if invalid return false if (!getKeyword(keyword, is)) @@ -115,7 +121,13 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is) // Deal with duplicate entries bool mergeEntry = false; - entry* existingPtr = parentDict.lookupEntryPtr(keyword); + // See (using exact match) if entry already present + entry* existingPtr = parentDict.lookupEntryPtr + ( + keyword, + false, + true + ); if (existingPtr) { if (functionEntries::inputModeEntry::overwrite()) @@ -158,7 +170,7 @@ Foam::autoPtr Foam::entry::New(Istream& is) { is.fatalCheck("entry::New(Istream& is)"); - word keyword; + keyType keyword; // Get the next keyword and if invalid return false if (!getKeyword(keyword, is)) diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C index df888cd064..71bc50189d 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.C @@ -24,12 +24,13 @@ License \*---------------------------------------------------------------------------*/ +#include "word.H" #include "primitiveEntry.H" #include "dictionary.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::primitiveEntry::primitiveEntry(const word& key, const ITstream& tokens) +Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens) : entry(key), ITstream(tokens) @@ -38,7 +39,7 @@ Foam::primitiveEntry::primitiveEntry(const word& key, const ITstream& tokens) } -Foam::primitiveEntry::primitiveEntry(const word& keyword, const token& t) +Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t) : entry(keyword), ITstream(keyword, tokenList(1, t)) @@ -47,7 +48,7 @@ Foam::primitiveEntry::primitiveEntry(const word& keyword, const token& t) Foam::primitiveEntry::primitiveEntry ( - const word& keyword, + const keyType& keyword, const tokenList& tokens ) : diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H index b97452818a..86d8afd61d 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntry.H @@ -108,23 +108,23 @@ public: // Constructors //- Construct from keyword and a Istream - primitiveEntry(const word& keyword, Istream&); + primitiveEntry(const keyType& keyword, Istream&); //- Construct from keyword, parent dictionary and a Istream - primitiveEntry(const word& keyword, const dictionary&, Istream&); + primitiveEntry(const keyType& keyword, const dictionary&, Istream&); //- Construct from keyword and a ITstream - primitiveEntry(const word& keyword, const ITstream&); + primitiveEntry(const keyType& keyword, const ITstream&); //- Construct from keyword and a token - primitiveEntry(const word&, const token&); + primitiveEntry(const keyType&, const token&); //- Construct from keyword and a tokenList - primitiveEntry(const word&, const tokenList&); + primitiveEntry(const keyType&, const tokenList&); //- Construct from keyword and a T template - primitiveEntry(const word&, const T&); + primitiveEntry(const keyType&, const T&); autoPtr clone(const dictionary&) const { diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C index 10bc3c78c8..58cf475303 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryIO.C @@ -81,7 +81,7 @@ bool Foam::primitiveEntry::expandVariable word varName = w(1, w.size()-1); // lookup the variable name in the given dictionary.... - const entry* ePtr = dict.lookupEntryPtr(varName, true); + const entry* ePtr = dict.lookupEntryPtr(varName, true, true); // ...if defined insert its tokens into this if (ePtr != NULL) @@ -218,7 +218,7 @@ void Foam::primitiveEntry::readEntry(const dictionary& dict, Istream& is) Foam::primitiveEntry::primitiveEntry ( - const word& key, + const keyType& key, const dictionary& dict, Istream& is ) @@ -236,7 +236,7 @@ Foam::primitiveEntry::primitiveEntry } -Foam::primitiveEntry::primitiveEntry(const word& key, Istream& is) +Foam::primitiveEntry::primitiveEntry(const keyType& key, Istream& is) : entry(key), ITstream diff --git a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C index fce303173b..38e35b054a 100644 --- a/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C +++ b/src/OpenFOAM/db/dictionary/primitiveEntry/primitiveEntryTemplates.C @@ -30,7 +30,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::primitiveEntry::primitiveEntry(const word& keyword, const T& t) +Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const T& t) : entry(keyword), ITstream(keyword, tokenList(10)) diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index 3e61275164..6565c28b4f 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -87,16 +87,21 @@ public: inline word(const word&); //- Construct as copy of character array - inline word(const char*); + inline word(const char*, const bool doStripInvalid = true); //- Construct as copy with a maximum number of characters - inline word(const char*, const size_type); + inline word + ( + const char*, + const size_type, + const bool doStripInvalid + ); //- Construct as copy of string - inline word(const string&); + inline word(const string&, const bool doStripInvalid = true); //- Construct as copy of std::string - inline word(const std::string&); + inline word(const std::string&, const bool doStripInvalid = true); //- Construct from Istream word(Istream&); diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H index c31208fd7b..d71eff2f9a 100644 --- a/src/OpenFOAM/primitives/strings/word/wordI.H +++ b/src/OpenFOAM/primitives/strings/word/wordI.H @@ -65,34 +65,51 @@ inline Foam::word::word() {} -inline Foam::word::word(const string& s) +inline Foam::word::word(const string& s, const bool doStripInvalid) : string(s) { - stripInvalid(); + if (doStripInvalid) + { + stripInvalid(); + } } -inline Foam::word::word(const std::string& s) +inline Foam::word::word(const std::string& s, const bool doStripInvalid) : string(s) { - stripInvalid(); + if (doStripInvalid) + { + stripInvalid(); + } } -inline Foam::word::word(const char* s) +inline Foam::word::word(const char* s, const bool doStripInvalid) : string(s) { - stripInvalid(); + if (doStripInvalid) + { + stripInvalid(); + } } -inline Foam::word::word(const char* s, const size_type n) +inline Foam::word::word +( + const char* s, + const size_type n, + const bool doStripInvalid +) : string(s, n) { - stripInvalid(); + if (doStripInvalid) + { + stripInvalid(); + } }