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)
{
HashPtrTable<IOobject>::iterator iter =
HashPtrTable<IOobject>::find(io.name());
if (iter != end())
{
return erase(iter);
}
else
{
return false;
}
return erase(io.name());
}
@ -131,7 +121,7 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
{
HashPtrTable<IOobject>::const_iterator iter = find(name);
if (iter != end())
if (iter.found())
{
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)
{
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)
{
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)
{
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
(
const word& ClassName
const word& clsName
) const
{
wordList objectNames(size());
wordList objNames(size());
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
(
const word& ClassName,
const word& clsName,
const wordRe& matcher
) const
{
wordList objNames = names(ClassName);
wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames));
}
@ -265,11 +267,11 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::names
(
const word& ClassName,
const word& clsName,
const wordReList& matcher
) const
{
wordList objNames = names(ClassName);
wordList objNames = names(clsName);
return wordList(objNames, findStrings(matcher, objNames));
}
@ -277,10 +279,10 @@ Foam::wordList Foam::IOobjectList::names
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& ClassName
const word& clsName
) const
{
wordList sortedLst = names(ClassName);
wordList sortedLst = names(clsName);
sort(sortedLst);
return sortedLst;
@ -289,11 +291,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& ClassName,
const word& clsName,
const wordRe& matcher
) const
{
wordList sortedLst = names(ClassName, matcher);
wordList sortedLst = names(clsName, matcher);
sort(sortedLst);
return sortedLst;
@ -302,11 +304,11 @@ Foam::wordList Foam::IOobjectList::sortedNames
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& ClassName,
const word& clsName,
const wordReList& matcher
) const
{
wordList sortedLst = names(ClassName, matcher);
wordList sortedLst = names(clsName, matcher);
sort(sortedLst);
return sortedLst;

View File

@ -77,7 +77,7 @@ public:
);
//- Construct as copy
IOobjectList(const IOobjectList&);
IOobjectList(const IOobjectList& iolist);
//- Destructor
@ -87,52 +87,56 @@ public:
// Member functions
//- Add an IOobject to the list
bool add(IOobject&);
bool add(IOobject& io);
//- 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
IOobject* lookup(const word& name) const;
//- Return the list for all IOobects whose name matches name
IOobjectList lookup(const wordRe& name) const;
//- The list of all IOobects with matching names
IOobjectList lookup(const wordRe& matcher) const;
//- Return the list for all IOobects whose name matches name
IOobjectList lookup(const wordReList& patterns) const;
//- The list of all IOobjects with matching names
IOobjectList lookup(const wordReList& matcher) const;
//- Return the list for all IOobjects of a given class
IOobjectList lookupClass(const word& className) const;
//- The list of all IOobjects with the given class name
IOobjectList lookupClass(const word& clsName) const;
//- A list of names of the IOobjects
wordList names() const;
//- A list of names of IOobjects of the given class
wordList names(const word& className) const;
//- The names of IOobjects with the given class name
wordList names(const word& clsName) const;
//- A list of names of IOobjects of the given class,
// and that also satisfy the input matcher
wordList names(const word& className, const wordRe&) const;
//- The names of IOobjects with the given class name that also
// have a name satisfying the input matcher
wordList names(const word& clsName, const wordRe& matcher) const;
//- A list of names of IOobjects of the given class,
// and that also satisfy the input matchers
wordList names(const word& className, const wordReList&) const;
//- The names of IOobjects with the given class name that also
// have a name satisfying the input matcher
wordList names(const word& clsName, const wordReList& matcher) const;
//- A sorted list of names of the IOobjects
wordList sortedNames() const;
//- A sorted list of names of IOobjects of given class
wordList sortedNames(const word& className) const;
//- The sorted names of IOobjects with the given class name
wordList sortedNames(const word& clsName) const;
//- A sorted list of names of IOobjects of the given class,
// and that also satisfy the input matcher
wordList sortedNames(const word& className, const wordRe&) const;
//- The sorted names of IOobjects with the given class name that also
// have a name satisfying the input matcher
wordList sortedNames(const word& clsName, const wordRe& matcher) const;
//- A sorted list of names of IOobjects of the given class,
// and that also satisfy the input matchers
wordList sortedNames(const word& className, const wordReList&) const;
//- The sorted names of IOobjects with the given class name that also
// have a name satisfying the input matcher
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
(
const bool patternMatch,
const word& Keyword,
const word& keyword,
DLList<entry*>::const_iterator& wcLink,
DLList<autoPtr<regExp>>::const_iterator& reLink
) const
@ -173,8 +173,8 @@ bool Foam::dictionary::findInPatterns
if
(
patternMatch
? reLink()->match(Keyword)
: wcLink()->keyword() == Keyword
? reLink()->match(keyword)
: wcLink()->keyword() == keyword
)
{
return true;
@ -192,7 +192,7 @@ bool Foam::dictionary::findInPatterns
bool Foam::dictionary::findInPatterns
(
const bool patternMatch,
const word& Keyword,
const word& keyword,
DLList<entry*>::iterator& wcLink,
DLList<autoPtr<regExp>>::iterator& reLink
)
@ -204,8 +204,8 @@ bool Foam::dictionary::findInPatterns
if
(
patternMatch
? reLink()->match(Keyword)
: wcLink()->keyword() == Keyword
? reLink()->match(keyword)
: wcLink()->keyword() == keyword
)
{
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
DLList<entry*>::iterator wcLink =
@ -964,7 +964,7 @@ bool Foam::dictionary::remove(const word& Keyword)
patternRegexps_.begin();
// Find in pattern using exact match only
if (findInPatterns(false, Keyword, wcLink, reLink))
if (findInPatterns(false, keyword, wcLink, reLink))
{
patternEntries_.remove(wcLink);
patternRegexps_.remove(reLink);

View File

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

View File

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