From d80ce7fc33ce7ef4bfc7c17d309c21c20649b5ea Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Tue, 1 Dec 2009 11:54:06 +0100
Subject: [PATCH] objectRegistry - gets sortedNames() methods

- reduce duplicate code by using some HashTable methods directly
---
 .../db/objectRegistry/objectRegistry.C        | 39 +++++++++++--------
 .../db/objectRegistry/objectRegistry.H        | 12 ++++--
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C
index 452ad35ac60..a8a7390015a 100644
--- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C
+++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C
@@ -93,7 +93,7 @@ Foam::objectRegistry::~objectRegistry()
         }
     }
 
-    for (label i=0; i<nMyObjects; i++)
+    for (label i=0; i < nMyObjects; i++)
     {
         checkOut(*myObjects[i]);
     }
@@ -104,15 +104,13 @@ Foam::objectRegistry::~objectRegistry()
 
 Foam::wordList Foam::objectRegistry::names() const
 {
-    wordList objectNames(size());
+    return HashTable<regIOobject*>::toc();
+}
 
-    label count=0;
-    for (const_iterator iter = cbegin(); iter != cend(); ++iter)
-    {
-        objectNames[count++] = iter()->name();
-    }
 
-    return objectNames;
+Foam::wordList Foam::objectRegistry::sortedNames() const
+{
+    return HashTable<regIOobject*>::sortedToc();
 }
 
 
@@ -125,7 +123,7 @@ Foam::wordList Foam::objectRegistry::names(const word& ClassName) const
     {
         if (iter()->type() == ClassName)
         {
-            objectNames[count++] = iter()->name();
+            objectNames[count++] = iter.key();
         }
     }
 
@@ -135,6 +133,15 @@ Foam::wordList Foam::objectRegistry::names(const word& ClassName) const
 }
 
 
+Foam::wordList Foam::objectRegistry::sortedNames(const word& ClassName) const
+{
+    wordList sortedLst = names(ClassName);
+    sort(sortedLst);
+
+    return sortedLst;
+}
+
+
 const Foam::objectRegistry& Foam::objectRegistry::subRegistry
 (
     const word& name
@@ -151,8 +158,8 @@ Foam::label Foam::objectRegistry::getEvent() const
     if (event_ == labelMax)
     {
         WarningIn("objectRegistry::getEvent() const")
-            << "Event counter has overflowed. Resetting counter on all"
-            << " dependent objects." << endl
+            << "Event counter has overflowed. "
+            << "Resetting counter on all dependent objects." << nl
             << "This might cause extra evaluations." << endl;
 
         // Reset event counter
@@ -202,7 +209,7 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const
         if (objectRegistry::debug)
         {
             Pout<< "objectRegistry::checkOut(regIOobject&) : "
-                << name() << " : checking out " << io.name()
+                << name() << " : checking out " << iter.key()
                 << endl;
         }
 
@@ -211,7 +218,8 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const
             if (objectRegistry::debug)
             {
                 WarningIn("objectRegistry::checkOut(regIOobject&)")
-                    << name() << " : attempt to checkOut copy of " << io.name()
+                    << name() << " : attempt to checkOut copy of "
+                    << iter.key()
                     << endl;
             }
 
@@ -286,8 +294,7 @@ void Foam::objectRegistry::readModifiedObjects()
         {
             Pout<< "objectRegistry::readModifiedObjects() : "
                 << name() << " : Considering reading object "
-                << iter()->name()
-                << endl;
+                << iter.key() << endl;
         }
 
         iter()->readIfModified();
@@ -317,7 +324,7 @@ bool Foam::objectRegistry::writeObject
         {
             Pout<< "objectRegistry::write() : "
                 << name() << " : Considering writing object "
-                << iter()->name()
+                << iter.key()
                 << " with writeOpt " << iter()->writeOpt()
                 << " to file " << iter()->objectPath()
                 << endl;
diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H
index 1f2d30d93e7..6e7c5c04f6e 100644
--- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H
+++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H
@@ -132,9 +132,15 @@ public:
             //- Return the list of names of the IOobjects
             wordList names() const;
 
-            //- Return the list of names of the IOobjects of given class name
+            //- Return the sorted list of names of the IOobjects
+            wordList sortedNames() const;
+
+            //- Return the list of names of IOobjects of given class name
             wordList names(const word& className) const;
 
+            //- Return the sorted list of names of IOobjects of given class name
+            wordList sortedNames(const word& className) const;
+
             //- Return the list of names of the IOobjects of given type
             template<class Type>
             wordList names() const;
@@ -142,11 +148,11 @@ public:
             //- Lookup and return a const sub-objectRegistry
             const objectRegistry& subRegistry(const word& name) const;
 
-            //- Lookup and return all the object of the given Type
+            //- Lookup and return all objects of the given Type
             template<class Type>
             HashTable<const Type*> lookupClass() const;
 
-            //- Is the named Type
+            //- Is the named Type found?
             template<class Type>
             bool foundObject(const word& name) const;
 
-- 
GitLab