diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index a55f68a425..41eb798407 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -58,7 +58,7 @@ Foam::IOobjectList::IOobjectList } } - // Create list file names in directory + // Create a list of file names in this directory fileNameList ObjectNames = readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE); @@ -130,8 +130,8 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const { if (IOobject::debug) { - Info<< "IOobjectList::lookup : found " << name - << endl; + Info<< "IOobjectList::lookup : found " + << name << endl; } return const_cast(*iter); @@ -140,8 +140,8 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const { if (IOobject::debug) { - Info<< "IOobjectList::lookup : could not find " << name - << endl; + Info<< "IOobjectList::lookup : could not find " + << name << endl; } return NULL; @@ -151,7 +151,7 @@ Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const { - IOobjectList IOobjectsOfClass(size()); + IOobjectList objectsOfClass(size()); for ( @@ -165,34 +165,26 @@ Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& ClassName) const if (IOobject::debug) { Info<< "IOobjectList::lookupClass : found " - << iter()->name() - << endl; + << iter.key() << endl; } - IOobjectsOfClass.insert(iter()->name(), new IOobject(*iter())); + objectsOfClass.insert(iter.key(), new IOobject(*iter())); } } - return IOobjectsOfClass; + return objectsOfClass; } Foam::wordList Foam::IOobjectList::names() const { - wordList objectNames(size()); + return HashPtrTable::toc(); +} - label count = 0; - for - ( - HashPtrTable::const_iterator iter = begin(); - iter != end(); - ++iter - ) - { - objectNames[count++] = iter()->name(); - } - return objectNames; +Foam::wordList Foam::IOobjectList::sortedNames() const +{ + return HashPtrTable::sortedToc(); } @@ -210,7 +202,7 @@ Foam::wordList Foam::IOobjectList::names(const word& ClassName) const { if (iter()->headerClassName() == ClassName) { - objectNames[count++] = iter()->name(); + objectNames[count++] = iter.key(); } } @@ -220,4 +212,13 @@ Foam::wordList Foam::IOobjectList::names(const word& ClassName) const } +Foam::wordList Foam::IOobjectList::sortedNames(const word& ClassName) const +{ + wordList sortedLst = names(ClassName); + sort(sortedLst); + + return sortedLst; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index 71c63f9d38..fc6034115f 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.H +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.H @@ -84,23 +84,29 @@ public: // Member functions - //- Add an IOobject to list + //- Add an IOobject to the list bool add(IOobject&); - //- Remove an IOobject from list + //- Remove an IOobject from the list bool remove(IOobject&); //- Lookup a given name and return IOobject ptr if found else NULL IOobject* lookup(const word& name) const; - //- Return the list for all IOobjects of given class + //- Return the list for all IOobjects of a given class IOobjectList lookupClass(const word& className) const; //- Return the list of names of the IOobjects wordList names() const; + //- Return the sorted list of names of the IOobjects + wordList sortedNames() const; + //- Return the list of names of the IOobjects of given class wordList names(const word& className) const; + + //- Return the sorted list of names of the IOobjects of given class + wordList sortedNames(const word& className) const; };