From 5bc6204c6617eeea077ec26dff02e269cdca61ed Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 8 Dec 2009 14:31:02 +0000 Subject: [PATCH] Retrofitted functionality from our development line to improve error and warning messages from "dictionary". --- src/OpenFOAM/db/dictionary/dictionary.C | 40 +++- src/OpenFOAM/db/dictionary/dictionary.H | 95 +++++--- .../dictionary/dictionaryEntry/dictionaryEntryIO.C | 6 +- src/OpenFOAM/db/dictionary/dictionaryIO.C | 6 +- src/OpenFOAM/db/dictionary/entry/entry.C | 1 - src/OpenFOAM/db/dictionary/entry/entry.H | 13 +- .../functionEntries/functionEntry/functionEntry.C | 6 +- .../functionEntries/removeEntry/removeEntry.C | 19 +- .../functionEntries/removeEntry/removeEntry.H | 9 +- src/OpenFOAM/primitives/Lists/stringListOps.H | 240 +++++++++++++++++++-- .../Lists/stringListOpsTemplates.C} | 93 ++++---- .../Lists/wordReListMatcher.H} | 69 +++--- .../Lists/wordReListMatcherI.H} | 70 +++--- 13 files changed, 467 insertions(+), 200 deletions(-) copy src/OpenFOAM/{db/dictionary/functionEntries/removeEntry/removeEntry.C => primitives/Lists/stringListOpsTemplates.C} (52%) copy src/OpenFOAM/{db/dictionary/functionEntries/removeEntry/removeEntry.H => primitives/Lists/wordReListMatcher.H} (61%) copy src/OpenFOAM/{db/dictionary/entry/entry.C => primitives/Lists/wordReListMatcherI.H} (58%) diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index fb6f28af..9d022d51 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -109,14 +109,21 @@ Foam::dictionary::dictionary() {} +Foam::dictionary::dictionary(const fileName& name) +: + dictionaryName(name), + parent_(dictionary::null) +{} + + Foam::dictionary::dictionary ( const dictionary& parentDict, const dictionary& dict ) : + dictionaryName(parentDict.name() + "::" + dict.name()), IDLList(dict, *this), - name_(dict.name()), parent_(parentDict) { forAllIter(IDLList, *this, iter) @@ -140,8 +147,8 @@ Foam::dictionary::dictionary const dictionary& dict ) : + dictionaryName(dict.name()), IDLList(dict, *this), - name_(dict.name()), parent_(dictionary::null) { forAllIter(IDLList, *this, iter) @@ -183,6 +190,7 @@ Foam::dictionary::dictionary parent_(parentDict) { transfer(dict()); + name() = parentDict.name() + "::" + name(); } @@ -472,6 +480,24 @@ Foam::dictionary& Foam::dictionary::subDict(const word& keyword) } +Foam::dictionary Foam::dictionary::subOrEmptyDict +( + const word& keyword +) const +{ + const entry* entryPtr = lookupEntryPtr(keyword, false, true); + + if (entryPtr == NULL) + { + return dictionary(*this, dictionary(keyword)); + } + else + { + return entryPtr->dict(); + } +} + + Foam::wordList Foam::dictionary::toc() const { wordList keys(size()); @@ -530,7 +556,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) if (hashedEntries_.insert(entryPtr->keyword(), entryPtr)) { - entryPtr->name() = name_ + "::" + entryPtr->keyword(); + entryPtr->name() = name() + "::" + entryPtr->keyword(); if (entryPtr->keyword().isPattern()) { @@ -558,7 +584,7 @@ bool Foam::dictionary::add(entry* entryPtr, bool mergeEntry) if (hashedEntries_.insert(entryPtr->keyword(), entryPtr)) { - entryPtr->name() = name_ + "::" + entryPtr->keyword(); + entryPtr->name() = name() + "::" + entryPtr->keyword(); IDLList::append(entryPtr); if (entryPtr->keyword().isPattern()) @@ -763,7 +789,7 @@ bool Foam::dictionary::changeKeyword // change name and HashTable, but leave DL-List untouched iter()->keyword() = newKeyword; - iter()->name() = name_ + "::" + newKeyword; + iter()->name() = name() + "::" + newKeyword; hashedEntries_.erase(oldKeyword); hashedEntries_.insert(newKeyword, iter()); @@ -838,7 +864,7 @@ void Foam::dictionary::transfer(dictionary& dict) { // changing parents probably doesn't make much sense, // but what about the names? - name_ = dict.name_; + name() = dict.name(); IDLList::transfer(dict); hashedEntries_.transfer(dict.hashedEntries_); @@ -871,7 +897,7 @@ void Foam::dictionary::operator=(const dictionary& rhs) << abort(FatalError); } - name_ = rhs.name(); + name() = rhs.name(); clear(); // Create clones of the entries in the given dictionary diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H index 31ac3142..8645dfad 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.H +++ b/src/OpenFOAM/db/dictionary/dictionary.H @@ -41,7 +41,7 @@ Description ToDo A merge() member function with a non-const dictionary parameter. - This would avoid unnecessary cloning in the add(entry*,bool) method + This would avoid unnecessary cloning in the add(entry*, bool) method. SourceFiles dictionary.C @@ -74,6 +74,47 @@ class SHA1Digest; Istream& operator>>(Istream&, dictionary&); Ostream& operator<<(Ostream&, const dictionary&); +/*---------------------------------------------------------------------------*\ + Class dictionaryName Declaration +\*---------------------------------------------------------------------------*/ + +class dictionaryName +{ + // Private data + + fileName name_; + + +public: + + // Constructors + + //- Construct dictionaryName null + dictionaryName() + {} + + //- Construct dictionaryName as copy of the given fileName + dictionaryName(const fileName& name) + : + name_(name) + {} + + + // Member functions + + //- Return the dictionary name + const fileName& name() const + { + return name_; + } + + //- Return the dictionary name + fileName& name() + { + return name_; + } +}; + /*---------------------------------------------------------------------------*\ Class dictionary Declaration @@ -81,13 +122,11 @@ Ostream& operator<<(Ostream&, const dictionary&); class dictionary : + public dictionaryName, public IDLList { // Private data - //- Dictionary name - fileName name_; - //- HashTable of the entries held on the DL-list for quick lookup HashTable hashedEntries_; @@ -100,6 +139,7 @@ class dictionary //- Patterns as precompiled regular expressions DLList > patternRegexps_; + // Private Member Functions //- Search patterns table for exact match or regular expression match @@ -123,16 +163,6 @@ class dictionary public: - //- Read dictionary from Istream - bool read(Istream&); - - //- Substitute the given keyword prepended by '$' with the - // corresponding sub-dictionary entries - bool substituteKeyword(const word& keyword); - - -public: - //- Declare friendship with the entry class for IO friend class entry; @@ -150,10 +180,14 @@ public: //- Construct top-level dictionary null dictionary(); - //- Construct from the parent dictionary and Istream, reading entries - // until lastEntry or EOF + //- Construct top-level empty dictionary with given name + dictionary(const fileName& name); + + //- Construct given the entry name, parent dictionary and Istream, + // reading entries until lastEntry or EOF dictionary ( + const fileName& name, const dictionary& parentDict, Istream& ); @@ -192,18 +226,6 @@ public: // Member functions - //- Return the dictionary name - const fileName& name() const - { - return name_; - } - - //- Return the dictionary name - fileName& name() - { - return name_; - } - //- Return the parent dictionary const dictionary& parent() const { @@ -320,14 +342,23 @@ public: //- Find and return a sub-dictionary for manipulation dictionary& subDict(const word&); + //- Find and return a sub-dictionary as a copy, or + // return an empty dictionary if the sub-dictionary does not exist + dictionary subOrEmptyDict(const word&) const; + //- Return the table of contents wordList toc() const; //- Return the list of available keys or patterns List keys(bool patterns=false) const; + // Editing + //- Substitute the given keyword prepended by '$' with the + // corresponding sub-dictionary entries + bool substituteKeyword(const word& keyword); + //- Add a new entry // With the merge option, dictionaries are interwoven and // primitive entries are overwritten @@ -400,13 +431,19 @@ public: //- Clear the dictionary void clear(); - //- Transfer the contents of the argument and annull the argument. + //- Transfer the contents of the argument and annul the argument. void transfer(dictionary&); //- Transfer contents to the Xfer container Xfer xfer(); + // Read + + //- Read dictionary from Istream + bool read(Istream&); + + // Write void write(Ostream&, bool subDict=true) const; diff --git a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C index 4ed38340..489395e4 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryEntry/dictionaryEntryIO.C @@ -39,7 +39,7 @@ Foam::dictionaryEntry::dictionaryEntry Istream& is ) : - entry(is), + entry(keyType(is)), dictionary(parentDict, is) { is.fatalCheck @@ -58,10 +58,8 @@ Foam::dictionaryEntry::dictionaryEntry ) : entry(key), - dictionary(parentDict, is) + dictionary(key, parentDict, is) { - name() += "::" + key; - is.fatalCheck ( "dictionaryEntry::dictionaryEntry" diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C index 96196e3a..446aba82 100644 --- a/src/OpenFOAM/db/dictionary/dictionaryIO.C +++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C @@ -95,11 +95,12 @@ bool Foam::dictionary::substituteKeyword(const word& keyword) Foam::dictionary::dictionary ( + const fileName& name, const dictionary& parentDict, Istream& is ) : - name_(is.name()), + dictionaryName(parentDict.name() + "::" + name), parent_(parentDict) { read(is); @@ -108,7 +109,7 @@ Foam::dictionary::dictionary Foam::dictionary::dictionary(Istream& is) : - name_(is.name()), + dictionaryName(is.name()), parent_(dictionary::null) { // Reset input mode as this is a "top-level" dictionary @@ -132,6 +133,7 @@ Foam::Istream& Foam::operator>>(Istream& is, dictionary& dict) functionEntries::inputModeEntry::clear(); dict.clear(); + dict.name() = is.name(); dict.read(is); return is; diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C index a3049a31..d153bb04 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/db/dictionary/entry/entry.C @@ -38,7 +38,6 @@ Foam::entry::entry(const keyType& keyword) Foam::entry::entry(const entry& e) : - IDLList::link(), keyword_(e.keyword_) {} diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H index ddaefe74..972576e5 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.H +++ b/src/OpenFOAM/db/dictionary/entry/entry.H @@ -77,7 +77,7 @@ class entry // Private Member Functions //- Get the next valid keyword otherwise return false - static bool getKeyword(keyType& keyword, Istream& is); + static bool getKeyword(keyType&, Istream&); public: @@ -85,7 +85,7 @@ public: // Constructors //- Construct from keyword - entry(const keyType& keyword); + entry(const keyType&); //- Construct as copy entry(const entry&); @@ -102,16 +102,15 @@ public: virtual autoPtr clone() const; //- Construct from Istream and insert into dictionary - static bool New(dictionary& parentDict, Istream& is); + static bool New(dictionary& parentDict, Istream&); //- Construct on freestore from Istream and return static autoPtr New(Istream& is); - // Destructor - - virtual ~entry() - {} + //- Destructor + virtual ~entry() + {} // Member functions diff --git a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C index e386a30f..b1164941 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/functionEntry/functionEntry.C @@ -81,7 +81,8 @@ bool Foam::functionEntry::execute ( "functionEntry::execute" "(const word& functionName, dictionary& parentDict, Istream&)" - ) << "Unknown functionEntry " << functionName + ) << "Unknown functionEntry '" << functionName + << "' in " << is.name() << " near line " << is.lineNumber() << endl << endl << "Valid functionEntries are :" << endl << executedictionaryIstreamMemberFunctionTablePtr_->toc() @@ -126,7 +127,8 @@ bool Foam::functionEntry::execute ( "functionEntry::execute" "(const word&, const dictionary&, primitiveEntry&, Istream&)" - ) << "Unknown functionEntry " << functionName + ) << "Unknown functionEntry '" << functionName + << "' in " << is.name() << " near line " << is.lineNumber() << endl << endl << "Valid functionEntries are :" << endl << executeprimitiveEntryIstreamMemberFunctionTablePtr_->toc() diff --git a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C index 32f66604..78facd8e 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C @@ -26,6 +26,7 @@ License #include "removeEntry.H" #include "dictionary.H" +#include "stringListOps.H" #include "IStringStream.H" #include "OStringStream.H" #include "addToMemberFunctionSelectionTable.H" @@ -64,22 +65,14 @@ bool Foam::functionEntries::removeEntry::execute Istream& is ) { - token currToken(is); - is.putBack(currToken); + wordList dictKeys = parentDict.toc(); + wordReList patterns = readList(is); - if (currToken == token::BEGIN_LIST) - { - wordList keys(is); + labelList indices = findStrings(patterns, dictKeys); - forAll(keys, keyI) - { - parentDict.remove(keys[keyI]); - } - } - else + forAll(indices, indexI) { - word key(is); - parentDict.remove(key); + parentDict.remove(dictKeys[indices[indexI]]); } return true; diff --git a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H index b98da86e..148f8e26 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H @@ -28,13 +28,16 @@ Class Description Remove a dictionary entry. - The @c \#remove directive takes a word or a list of words. For example, + The @c \#remove directive takes a list or a single wordRe. + For example, @verbatim #remove entry0 - #remove ( entry1 entry2 entry3 ) + #remove ( entry1 entry2 entry3 otherEntry ) + #remove "entry[1-3]" + #remove ( "entry[1-3]" otherEntry ) @endverbatim - The removable only occurs in the current context. + The removal only occurs in the current context. Removing sub-entries or parent entries is not supported. SourceFiles diff --git a/src/OpenFOAM/primitives/Lists/stringListOps.H b/src/OpenFOAM/primitives/Lists/stringListOps.H index 253a249c..493a0cb3 100644 --- a/src/OpenFOAM/primitives/Lists/stringListOps.H +++ b/src/OpenFOAM/primitives/Lists/stringListOps.H @@ -36,54 +36,262 @@ SourceFiles #ifndef stringListOps_H #define stringListOps_H +#include "regExp.H" #include "labelList.H" #include "stringList.H" #include "wordReList.H" +#include "wordReListMatcher.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { + // single-string matches: + + //- Return true if string matches one of the regular expressions + inline bool findStrings + ( + const wordReListMatcher& matcher, + const std::string& str + ) + { + return matcher.match(str); + } + + // multi-string matches: + + //- Return list indices for matching strings + template + labelList findMatchingStrings + ( + const Matcher&, + const UList&, + const bool invert=false + ); + //- Return list indices for strings matching the regular expression + // Template partial specialization of findMatchingStrings template labelList findStrings ( - const char* regexpPattern, - const UList& - ); + const regExp& re, + const UList& lst, + const bool invert=false + ) + { + return findMatchingStrings(re, lst, invert); + } //- Return list indices for strings matching the regular expression + // Template partial specialization of findMatchingStrings template labelList findStrings ( - const std::string& regexpPattern, - const UList& - ); + const char* rePattern, + const UList& lst, + const bool invert=false + ) + { + return findStrings(regExp(rePattern), lst, invert); + } //- Return list indices for strings matching the regular expression + // Template partial specialization of findMatchingStrings template labelList findStrings ( - const wordRe&, - const UList& - ); + const std::string& rePattern, + const UList& lst, + const bool invert=false + ) + { + return findMatchingStrings(regExp(rePattern), lst, invert); + } + + //- Return list indices for strings matching the regular expression + // Template partial specialization of findMatchingStrings + template + labelList findStrings + ( + const wordRe& wre, + const UList& lst, + const bool invert=false + ) + { + return findMatchingStrings(wre, lst, invert); + } + //- Return list indices for strings matching one of the regular expression + // Template partial specialization of findMatchingStrings template labelList findStrings ( - const UList&, - const UList& + const wordReListMatcher& matcher, + const UList& lst, + const bool invert=false + ) + { + return findMatchingStrings(matcher, lst, invert); + } + + // subsetting multi-string matches (similar to ListOp): + + //- Extract elements of StringList when regular expression matches + // optionally invert the match + // eg, to extract all selected elements: + // subsetMatchingStrings(myRegExp, lst); + template + StringListType subsetMatchingStrings + ( + const Matcher&, + const StringListType&, + const bool invert=false ); - //- Return true if string matches one of the regular expressions - template - bool findStrings + //- Extract elements of StringList when regular expression matches + // Template partial specialization of subsetMatchingStrings + template + StringListType subsetStrings ( - const UList&, - const StringType& str + const regExp& re, + const StringListType& lst, + const bool invert=false + ) + { + return subsetMatchingStrings(re, lst, invert); + } + + //- Extract elements of StringList when regular expression matches + // Template partial specialization of subsetMatchingStrings + template + StringListType subsetStrings + ( + const char* rePattern, + const StringListType& lst, + const bool invert=false + ) + { + return subsetMatchingStrings(regExp(rePattern), lst, invert); + } + + //- Extract elements of StringList when regular expression matches + // Template partial specialization of subsetMatchingStrings + template + StringListType subsetStrings + ( + const std::string& rePattern, + const StringListType& lst, + const bool invert=false + ) + { + return subsetMatchingStrings(regExp(rePattern), lst, invert); + } + + //- Extract elements of StringList when regular expression matches + // Template partial specialization of subsetMatchingStrings + template + StringListType subsetStrings + ( + const wordRe& wre, + const StringListType& lst, + const bool invert=false + ) + { + return subsetMatchingStrings(wre, lst, invert); + } + + //- Extract elements of StringList when regular expression matches + // Template partial specialization of subsetMatchingStrings + template + StringListType subsetStrings + ( + const wordReListMatcher& matcher, + const StringListType& lst, + const bool invert=false + ) + { + return subsetMatchingStrings(matcher, lst, invert); + } + + + //- Inplace extract elements of StringList when regular expression matches + // optionally invert the match + // eg, to extract all selected elements: + // inplaceSubsetMatchingStrings(myRegExp, lst); + template + void inplaceSubsetMatchingStrings + ( + const Matcher&, + StringListType&, + const bool invert=false ); + //- Inplace extract elements of StringList when regular expression matches + // Template partial specialization of inplaceSubsetMatchingStrings + template + void inplaceSubsetStrings + ( + const regExp& re, + StringListType& lst, + const bool invert=false + ) + { + inplaceSubsetMatchingStrings(re, lst, invert); + } + + //- Inplace extract elements of StringList when regular expression matches + // Template partial specialization of inplaceSubsetMatchingStrings + template + void inplaceSubsetStrings + ( + const char* rePattern, + StringListType& lst, + const bool invert=false + ) + { + inplaceSubsetMatchingStrings(regExp(rePattern), lst, invert); + } + + //- Inplace extract elements of StringList when regular expression matches + // Template partial specialization of inplaceSubsetMatchingStrings + template + void inplaceSubsetStrings + ( + const std::string& rePattern, + StringListType& lst, + const bool invert=false + ) + { + inplaceSubsetMatchingStrings(regExp(rePattern), lst, invert); + } + + //- Inplace extract elements of StringList when regular expression matches + // Template partial specialization of inplaceSubsetMatchingStrings + template + void inplaceSubsetStrings + ( + const wordRe& wre, + StringListType& lst, + const bool invert=false + ) + { + inplaceSubsetMatchingStrings(wre, lst, invert); + } + + //- Inplace extract elements of StringList when regular expression matches + // Template partial specialization of inplaceSubsetMatchingStrings + template + void inplaceSubsetStrings + ( + const wordReListMatcher& matcher, + StringListType& lst, + const bool invert=false + ) + { + inplaceSubsetMatchingStrings(matcher, lst, invert); + } + } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C b/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C similarity index 52% copy from src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C copy to src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C index 32f66604..6489658d 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.C +++ b/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C @@ -24,65 +24,74 @@ License \*---------------------------------------------------------------------------*/ -#include "removeEntry.H" -#include "dictionary.H" -#include "IStringStream.H" -#include "OStringStream.H" -#include "addToMemberFunctionSelectionTable.H" +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const Foam::word Foam::functionEntries::removeEntry::typeName +template +Foam::labelList Foam::findMatchingStrings ( - Foam::functionEntries::removeEntry::typeName_() -); + const Matcher& matcher, + const UList& lst, + const bool invert +) +{ + labelList indices(lst.size()); -// Don't lookup the debug switch here as the debug switch dictionary -// might include removeEntry -int Foam::functionEntries::removeEntry::debug(0); + label nElem = 0; + forAll(lst, elemI) + { + if (matcher.match(lst[elemI]) ? !invert : invert) + { + indices[nElem++] = elemI; + } + } + indices.setSize(nElem); -namespace Foam -{ -namespace functionEntries -{ - addToMemberFunctionSelectionTable - ( - functionEntry, - removeEntry, - execute, - dictionaryIstream - ); + return indices; } -} - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::functionEntries::removeEntry::execute +template +StringListType Foam::subsetMatchingStrings ( - dictionary& parentDict, - Istream& is + const Matcher& matcher, + const StringListType& lst, + const bool invert ) { - token currToken(is); - is.putBack(currToken); + StringListType newLst(lst.size()); - if (currToken == token::BEGIN_LIST) + label nElem = 0; + forAll(lst, elemI) { - wordList keys(is); - - forAll(keys, keyI) + if (matcher.match(lst[elemI]) ? !invert : invert) { - parentDict.remove(keys[keyI]); + newLst[nElem++] = lst[elemI]; } } - else + newLst.setSize(nElem); + + return newLst; +} + + +template +void Foam::inplaceSubsetMatchingStrings +( + const Matcher& matcher, + StringListType& lst, + const bool invert +) +{ + label nElem = 0; + forAll(lst, elemI) { - word key(is); - parentDict.remove(key); + if (matcher.match(lst[elemI]) ? !invert : invert) + { + lst[nElem++] = lst[elemI]; + } } - - return true; + lst.setSize(nElem); } + // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H b/src/OpenFOAM/primitives/Lists/wordReListMatcher.H similarity index 61% copy from src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H copy to src/OpenFOAM/primitives/Lists/wordReListMatcher.H index b98da86e..fa125048 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/removeEntry/removeEntry.H +++ b/src/OpenFOAM/primitives/Lists/wordReListMatcher.H @@ -23,74 +23,79 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Class - Foam::functionEntries::removeEntry + Foam::wordReListMatcher Description - Remove a dictionary entry. + A wrapper for matching a List of wordRe. - The @c \#remove directive takes a word or a list of words. For example, - @verbatim - #remove entry0 - #remove ( entry1 entry2 entry3 ) - @endverbatim - - The removable only occurs in the current context. - Removing sub-entries or parent entries is not supported. +Note + The constructor should remain non-explicit. This allows automatic + conversion from UList\ to wordReListMatcher in search + functions. SourceFiles - removeEntry.C + wordReListMatcherI.H \*---------------------------------------------------------------------------*/ -#ifndef removeEntry_H -#define removeEntry_H +#ifndef wordReListMatcher_H +#define wordReListMatcher_H -#include "functionEntry.H" +#include "wordReList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -namespace functionEntries -{ /*---------------------------------------------------------------------------*\ - Class removeEntry Declaration + Class wordReListMatcher Declaration \*---------------------------------------------------------------------------*/ -class removeEntry -: - public functionEntry +class wordReListMatcher { - // Private Member Functions - - //- Disallow default bitwise copy construct - removeEntry(const removeEntry&); - - //- Disallow default bitwise assignment - void operator=(const removeEntry&); + // Private data + //- Reference to underlying list + const UList& reList_; public: - //- Runtime type information - ClassName("remove"); + // Constructors + + //- Construct from a List of wordRe + inline wordReListMatcher(const UList&); // Member Functions - //- Execute the functionEntry in a sub-dict context - static bool execute(dictionary& parentDict, Istream&); + // Access + + inline label size() const; + inline bool empty() const; + + //- Return underlying list of wordRe + inline const UList& operator()() const; + + + // Searching + + //- Return true if string matches any of the regular expressions + // Smart match as regular expression or as a string. + // Optionally specify a literal match only. + inline bool match(const string&, bool literalMatch=false) const; + }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace functionEntries } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "wordReListMatcherI.H" + #endif // ************************************************************************* // diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/primitives/Lists/wordReListMatcherI.H similarity index 58% copy from src/OpenFOAM/db/dictionary/entry/entry.C copy to src/OpenFOAM/primitives/Lists/wordReListMatcherI.H index a3049a31..4b3774d2 100644 --- a/src/OpenFOAM/db/dictionary/entry/entry.C +++ b/src/OpenFOAM/primitives/Lists/wordReListMatcherI.H @@ -24,69 +24,55 @@ License \*---------------------------------------------------------------------------*/ -#include "entry.H" -#include "dictionary.H" -#include "OStringStream.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::entry::entry(const keyType& keyword) +inline Foam::wordReListMatcher::wordReListMatcher +( + const UList& lst +) : - keyword_(keyword) + reList_(lst) {} -Foam::entry::entry(const entry& e) -: - IDLList::link(), - keyword_(e.keyword_) -{} +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -Foam::autoPtr Foam::entry::clone() const +inline Foam::label Foam::wordReListMatcher::size() const { - return clone(dictionary::null); + return reList_.size(); } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -void Foam::entry::operator=(const entry& e) +inline bool Foam::wordReListMatcher::empty() const { - // check for assignment to self - if (this == &e) - { - FatalErrorIn("entry::operator=(const entry&)") - << "attempted assignment to self" - << abort(FatalError); - } - - keyword_ = e.keyword_; + return reList_.empty(); } -bool Foam::entry::operator==(const entry& e) const +inline const Foam::UList& +Foam::wordReListMatcher::operator()() const { - if (keyword_ != e.keyword_) - { - return false; - } - else - { - OStringStream oss1; - oss1 << *this; - - OStringStream oss2; - oss2 << e; - - return oss1.str() == oss2.str(); - } + return reList_; } -bool Foam::entry::operator!=(const entry& e) const +inline bool Foam::wordReListMatcher::match +( + const string& str, + bool literalMatch +) const { - return !operator==(e); + const label nElem = reList_.size(); + for (label elemI = 0; elemI < nElem; ++elemI) + { + if (reList_[elemI].match(str, literalMatch)) + { + return true; + } + } + + return false; } -- 2.11.4.GIT