ENH: consistent access to IOobjectList names.

- Previously matched name against the object->name() method
  but saved with iter.key().  Now use iter.key() more consistently.

STYLE: consistent parameter names (doxygen)
This commit is contained in:
Mark Olesen
2017-05-15 08:47:35 +02:00
parent 6933bc3021
commit d4041e7d36
6 changed files with 109 additions and 98 deletions

View File

@ -91,9 +91,9 @@ Foam::IOobjectList::IOobjectList
} }
Foam::IOobjectList::IOobjectList(const IOobjectList& ioOL) Foam::IOobjectList::IOobjectList(const IOobjectList& iolist)
: :
HashPtrTable<IOobject>(ioOL) HashPtrTable<IOobject>(iolist)
{} {}
@ -113,17 +113,7 @@ bool Foam::IOobjectList::add(IOobject& io)
bool Foam::IOobjectList::remove(IOobject& io) bool Foam::IOobjectList::remove(IOobject& io)
{ {
HashPtrTable<IOobject>::iterator iter = return erase(io.name());
HashPtrTable<IOobject>::find(io.name());
if (iter != end())
{
return erase(iter);
}
else
{
return false;
}
} }
@ -131,7 +121,7 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
{ {
HashPtrTable<IOobject>::const_iterator iter = find(name); HashPtrTable<IOobject>::const_iterator iter = find(name);
if (iter != end()) if (iter.found())
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
@ -152,68 +142,80 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
} }
Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& name) const Foam::IOobjectList Foam::IOobjectList::lookup(const wordRe& matcher) const
{ {
IOobjectList objectsOfName(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (name.match(iter()->name())) if (matcher.match(iter.key()))
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfName.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfName; return results;
} }
Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& patterns) const Foam::IOobjectList Foam::IOobjectList::lookup(const wordReList& matcher) const
{ {
wordReListMatcher names(patterns); wordReListMatcher mat(matcher);
IOobjectList objectsOfName(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (names.match(iter()->name())) if (mat.match(iter.key()))
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfName.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfName; return results;
} }
Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const
{ {
IOobjectList objectsOfClass(size()); IOobjectList results(size());
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (iter()->headerClassName() == ClassName) if (iter()->headerClassName() == clsName)
{ {
if (IOobject::debug) if (IOobject::debug)
{ {
InfoInFunction << "Found " << iter.key() << endl; InfoInFunction << "Found " << iter.key() << endl;
} }
objectsOfClass.insert(iter.key(), new IOobject(*iter())); results.insert
(
iter.key(),
new IOobject(*(iter.object()))
);
} }
} }
return objectsOfClass; return results;
} }
@ -231,33 +233,33 @@ Foam::wordList Foam::IOobjectList::sortedNames() const
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName const word& clsName
) const ) const
{ {
wordList objectNames(size()); wordList objNames(size());
label count = 0; label count = 0;
forAllConstIter(HashPtrTable<IOobject>, *this, iter) forAllConstIters(*this, iter)
{ {
if (iter()->headerClassName() == ClassName) if (iter()->headerClassName() == clsName)
{ {
objectNames[count++] = iter.key(); objNames[count++] = iter.key();
} }
} }
objectNames.setSize(count); objNames.setSize(count);
return objectNames; return objNames;
} }
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName, const word& clsName,
const wordRe& matcher const wordRe& matcher
) const ) const
{ {
wordList objNames = names(ClassName); wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames)); return wordList(objNames, findStrings(matcher, objNames));
} }
@ -265,11 +267,11 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::names
( (
const word& ClassName, const word& clsName,
const wordReList& matcher const wordReList& matcher
) const ) const
{ {
wordList objNames = names(ClassName); wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames)); return wordList(objNames, findStrings(matcher, objNames));
} }
@ -277,10 +279,10 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName const word& clsName
) const ) const
{ {
wordList sortedLst = names(ClassName); wordList sortedLst = names(clsName);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;
@ -289,11 +291,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName, const word& clsName,
const wordRe& matcher const wordRe& matcher
) const ) const
{ {
wordList sortedLst = names(ClassName, matcher); wordList sortedLst = names(clsName, matcher);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;
@ -302,11 +304,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames Foam::wordList Foam::IOobjectList::sortedNames
( (
const word& ClassName, const word& clsName,
const wordReList& matcher const wordReList& matcher
) const ) const
{ {
wordList sortedLst = names(ClassName, matcher); wordList sortedLst = names(clsName, matcher);
sort(sortedLst); sort(sortedLst);
return sortedLst; return sortedLst;

View File

@ -77,7 +77,7 @@ public:
); );
//- Construct as copy //- Construct as copy
IOobjectList(const IOobjectList&); IOobjectList(const IOobjectList& iolist);
//- Destructor //- Destructor
@ -87,52 +87,56 @@ public:
// Member functions // Member functions
//- Add an IOobject to the list //- Add an IOobject to the list
bool add(IOobject&); bool add(IOobject& io);
//- Remove an IOobject from the list //- Remove an IOobject from the list
bool remove(IOobject&); bool remove(IOobject& io);
//- Lookup a given name and return IOobject ptr if found else nullptr //- Lookup a given name and return IOobject ptr if found else nullptr
IOobject* lookup(const word& name) const; IOobject* lookup(const word& name) const;
//- Return the list for all IOobects whose name matches name //- The list of all IOobects with matching names
IOobjectList lookup(const wordRe& name) const; IOobjectList lookup(const wordRe& matcher) const;
//- Return the list for all IOobects whose name matches name //- The list of all IOobjects with matching names
IOobjectList lookup(const wordReList& patterns) const; IOobjectList lookup(const wordReList& matcher) const;
//- Return the list for all IOobjects of a given class //- The list of all IOobjects with the given class name
IOobjectList lookupClass(const word& className) const; IOobjectList lookupClass(const word& clsName) const;
//- A list of names of the IOobjects //- A list of names of the IOobjects
wordList names() const; wordList names() const;
//- A list of names of IOobjects of the given class //- The names of IOobjects with the given class name
wordList names(const word& className) const; wordList names(const word& clsName) const;
//- A list of names of IOobjects of the given class, //- The names of IOobjects with the given class name that also
// and that also satisfy the input matcher // have a name satisfying the input matcher
wordList names(const word& className, const wordRe&) const; wordList names(const word& clsName, const wordRe& matcher) const;
//- A list of names of IOobjects of the given class, //- The names of IOobjects with the given class name that also
// and that also satisfy the input matchers // have a name satisfying the input matcher
wordList names(const word& className, const wordReList&) const; wordList names(const word& clsName, const wordReList& matcher) const;
//- A sorted list of names of the IOobjects //- A sorted list of names of the IOobjects
wordList sortedNames() const; wordList sortedNames() const;
//- A sorted list of names of IOobjects of given class //- The sorted names of IOobjects with the given class name
wordList sortedNames(const word& className) const; wordList sortedNames(const word& clsName) const;
//- A sorted list of names of IOobjects of the given class, //- The sorted names of IOobjects with the given class name that also
// and that also satisfy the input matcher // have a name satisfying the input matcher
wordList sortedNames(const word& className, const wordRe&) const; wordList sortedNames(const word& clsName, const wordRe& matcher) const;
//- A sorted list of names of IOobjects of the given class, //- The sorted names of IOobjects with the given class name that also
// and that also satisfy the input matchers // have a name satisfying the input matcher
wordList sortedNames(const word& className, const wordReList&) const; wordList sortedNames
(
const word& clsName,
const wordReList& matcher
) const;
}; };

View File

@ -161,7 +161,7 @@ const Foam::entry* Foam::dictionary::lookupScopedSubEntryPtr
bool Foam::dictionary::findInPatterns bool Foam::dictionary::findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::const_iterator& wcLink, DLList<entry*>::const_iterator& wcLink,
DLList<autoPtr<regExp>>::const_iterator& reLink DLList<autoPtr<regExp>>::const_iterator& reLink
) const ) const
@ -173,8 +173,8 @@ bool Foam::dictionary::findInPatterns
if if
( (
patternMatch patternMatch
? reLink()->match(Keyword) ? reLink()->match(keyword)
: wcLink()->keyword() == Keyword : wcLink()->keyword() == keyword
) )
{ {
return true; return true;
@ -192,7 +192,7 @@ bool Foam::dictionary::findInPatterns
bool Foam::dictionary::findInPatterns bool Foam::dictionary::findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::iterator& wcLink, DLList<entry*>::iterator& wcLink,
DLList<autoPtr<regExp>>::iterator& reLink DLList<autoPtr<regExp>>::iterator& reLink
) )
@ -204,8 +204,8 @@ bool Foam::dictionary::findInPatterns
if if
( (
patternMatch patternMatch
? reLink()->match(Keyword) ? reLink()->match(keyword)
: wcLink()->keyword() == Keyword : wcLink()->keyword() == keyword
) )
{ {
return true; return true;
@ -951,11 +951,11 @@ void Foam::dictionary::set(const keyType& k, const dictionary& d)
} }
bool Foam::dictionary::remove(const word& Keyword) bool Foam::dictionary::remove(const word& keyword)
{ {
HashTable<entry*>::iterator iter = hashedEntries_.find(Keyword); HashTable<entry*>::iterator iter = hashedEntries_.find(keyword);
if (iter != hashedEntries_.end()) if (iter.found())
{ {
// Delete from patterns first // Delete from patterns first
DLList<entry*>::iterator wcLink = DLList<entry*>::iterator wcLink =
@ -964,7 +964,7 @@ bool Foam::dictionary::remove(const word& Keyword)
patternRegexps_.begin(); patternRegexps_.begin();
// Find in pattern using exact match only // Find in pattern using exact match only
if (findInPatterns(false, Keyword, wcLink, reLink)) if (findInPatterns(false, keyword, wcLink, reLink))
{ {
patternEntries_.remove(wcLink); patternEntries_.remove(wcLink);
patternRegexps_.remove(reLink); patternRegexps_.remove(reLink);

View File

@ -204,7 +204,7 @@ class dictionary
bool findInPatterns bool findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::const_iterator& wcLink, DLList<entry*>::const_iterator& wcLink,
DLList<autoPtr<regExp>>::const_iterator& reLink DLList<autoPtr<regExp>>::const_iterator& reLink
) const; ) const;
@ -213,7 +213,7 @@ class dictionary
bool findInPatterns bool findInPatterns
( (
const bool patternMatch, const bool patternMatch,
const word& Keyword, const word& keyword,
DLList<entry*>::iterator& wcLink, DLList<entry*>::iterator& wcLink,
DLList<autoPtr<regExp>>::iterator& reLink DLList<autoPtr<regExp>>::iterator& reLink
); );
@ -518,7 +518,7 @@ public:
void set(const keyType& k, const T& t); void set(const keyType& k, const T& t);
//- Remove an entry specified by keyword //- Remove an entry specified by keyword
bool remove(const word& Keyword); bool remove(const word& keyword);
//- Change the keyword for an entry, //- Change the keyword for an entry,
// optionally forcing overwrite of an existing entry // optionally forcing overwrite of an existing entry

View File

@ -57,7 +57,7 @@ class dictionary;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class entry; class entry;
Ostream& operator<<(Ostream&, const entry&); Ostream& operator<<(Ostream& os, const entry& e);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class entry Declaration Class entry Declaration
@ -75,11 +75,16 @@ class entry
// Private Member Functions // Private Member Functions
//- Get the next valid keyword. Return true if is valid keyType. //- Get the next valid keyword. Return true if a valid keyType.
static bool getKeyword(keyType&, token&, Istream&); static bool getKeyword
(
keyType& keyword,
token& keywordToken,
Istream& is
);
//- Get the next valid keyword otherwise return false //- Get the next valid keyword otherwise return false
static bool getKeyword(keyType&, Istream&); static bool getKeyword(keyType& keyword, Istream& is);
public: public:
@ -90,10 +95,10 @@ public:
// Constructors // Constructors
//- Construct from keyword //- Construct from keyword
entry(const keyType&); entry(const keyType& keyword);
//- Construct as copy //- Construct as copy
entry(const entry&); entry(const entry& e);
//- Construct on freestore as copy with reference to the //- Construct on freestore as copy with reference to the
// dictionary the copy belongs to // dictionary the copy belongs to
@ -107,7 +112,7 @@ public:
virtual autoPtr<entry> clone() const; virtual autoPtr<entry> clone() const;
//- Construct from Istream and insert into dictionary //- Construct from Istream and insert into dictionary
static bool New(dictionary& parentDict, Istream&); static bool New(dictionary& parentDict, Istream& is);
//- Construct on freestore from Istream and return //- Construct on freestore from Istream and return
static autoPtr<entry> New(Istream& is); static autoPtr<entry> New(Istream& is);
@ -179,7 +184,7 @@ public:
// Ostream operator // Ostream operator
friend Ostream& operator<<(Ostream&, const entry&); friend Ostream& operator<<(Ostream& os, const entry& e);
}; };

View File

@ -106,7 +106,7 @@ bool Foam::entry::getKeyword(keyType& keyword, Istream& is)
bool Foam::entry::New(dictionary& parentDict, Istream& is) bool Foam::entry::New(dictionary& parentDict, Istream& is)
{ {
is.fatalCheck("entry::New(const dictionary& parentDict, Istream&)"); is.fatalCheck(FUNCTION_NAME);
keyType keyword; keyType keyword;
token keyToken; token keyToken;
@ -324,7 +324,7 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is) Foam::autoPtr<Foam::entry> Foam::entry::New(Istream& is)
{ {
is.fatalCheck("entry::New(Istream&)"); is.fatalCheck(FUNCTION_NAME);
keyType keyword; keyType keyword;