Index: trunk/src/lib/util/loading/factory.cc
===================================================================
--- trunk/src/lib/util/loading/factory.cc	(revision 9675)
+++ trunk/src/lib/util/loading/factory.cc	(revision 9869)
@@ -15,9 +15,9 @@
 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
 
-#include "util/loading/factory.h"
+#include "factory.h"
 #include "debug.h"
 //#include "shell_command.h"
 
-
+ObjectListDefinition(Factory);
 
 //SHELL_COMMAND(create, Factory, fabricate);
@@ -28,18 +28,20 @@
  * set everything to zero and define factoryName
  */
-Factory::Factory (const std::string& factoryName, ClassID classID)
-    : classID(classID), className(factoryName)
+Factory::Factory (const ClassID& classID)
+    : _classID(classID)
 {
-  this->setClassID(CL_FACTORY, "Factory");
-  this->setName(factoryName);
+  PRINTF(4)("Factory::create(%s::%d)\n", classID.name().c_str(), classID.id());
+  //this->registerObject(this, Factory::_objectList);
+  this->setName(classID.name());
 
-  if( Factory::factoryList == NULL)
-    Factory::factoryList = new std::list<Factory*>;
-
-  Factory::factoryList->push_back(this);
+  Factory::_factoryIDMap[classID] = this;
+  Factory::_factoryStringMap[classID.name()] = this;
 }
 
-/** @brief a reference to the First Factory */
-std::list<Factory*>* Factory::factoryList = NULL;
+/** @brief A Map of all Factories ordered by ID. */
+Factory::FactoryIDMap Factory::_factoryIDMap;
+
+/** @brief A Map of all Factories ordered by Name. */
+Factory::FactoryStringMap Factory::_factoryStringMap;
 
 /**
@@ -48,24 +50,11 @@
 Factory::~Factory ()
 {
-  //  printf("%s\n", this->factoryName);
-  //  Factory* tmpDel = this->next;
-  //  this->next = NULL;
-}
+  FactoryIDMap::iterator it = Factory::_factoryIDMap.find(this->_classID);
+  if (it != Factory::_factoryIDMap.end() && (*it).second == this)
+    Factory::_factoryIDMap.erase(it);
 
-/**
- * @brief deletes all the Factories. (cleanup)
- */
-void Factory::deleteFactories()
-{
-  if (Factory::factoryList != NULL)
-  {
-    while(!Factory::factoryList->empty())
-    {
-      delete Factory::factoryList->front();
-      Factory::factoryList->pop_front();
-    }
-    delete Factory::factoryList;
-    Factory::factoryList = NULL;
-  }
+  FactoryStringMap::iterator stringIt = Factory::_factoryStringMap.find(this->_classID.name());
+  if (stringIt != Factory::_factoryStringMap.end() && (*stringIt).second == this)
+    Factory::_factoryStringMap.erase(stringIt);
 }
 
@@ -74,18 +63,9 @@
  * @returns true on match, false otherwise
  */
-bool Factory::operator==(ClassID classID) const
+bool Factory::operator==(int classID) const
 {
-  return (this->classID == classID);
+  return (this->_classID == classID);
 }
 
-/**
- * @brief Compares the Factories Name against a given ClassName
- * @param className the Name of the Class to Query
- * @returns true on match, false otherwise.
- */
-bool Factory::operator==(const char* className) const
-{
-  return (className != NULL && this->className == className);
-}
 
 /**
@@ -96,5 +76,5 @@
 bool Factory::operator==(const std::string& className) const
 {
-  return (this->className == className);
+  return (this->_classID.name() == className);
 }
 
@@ -107,16 +87,15 @@
 BaseObject* Factory::fabricate(const TiXmlElement* root)
 {
-  assert (root != NULL && Factory::factoryList != NULL);
-
-  std::list<Factory*>::const_iterator factory;
-  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
-    if (*(*factory) == root->Value())
-    {
-      PRINTF(2)("Create a new Object of type %s\n", (*factory)->getCName());
-      return (*factory)->fabricateObject(root);
-    }
-
-  PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value());
-  return NULL;
+  FactoryStringMap::const_iterator it = Factory::_factoryStringMap.find(root->Value());
+  if (it != Factory::_factoryStringMap.end())
+  {
+    PRINTF(2)("Create a new Object of type %s\n", (*it).second->getCName());
+    return (*it).second->fabricateObject(root);
+  }
+  else
+  {
+    PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value());
+    return NULL;
+  }
 }
 
@@ -129,18 +108,16 @@
 BaseObject* Factory::fabricate(const std::string& className)
 {
-  if (Factory::factoryList == NULL)
+  FactoryStringMap::const_iterator it = Factory::_factoryStringMap.find(className);
+  if (it != Factory::_factoryStringMap.end())
+  {
+    PRINTF(2)("Create a new Object of type %s\n", (*it).second->getCName());
+    return (*it).second->fabricateObject(NULL);
+  }
+  else
+  {
+    PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str());
     return NULL;
-
-  std::list<Factory*>::const_iterator factory;
-  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
-    if (*(*factory) == className)
-    {
-      PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
-      return (*factory)->fabricateObject(NULL);
-    }
-  PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str());
-  return NULL;
+  }
 }
-
 
 /**
@@ -149,18 +126,36 @@
  * @returns a new Object of Type classID on match, NULL otherwise
  */
-BaseObject* Factory::fabricate(ClassID classID)
+BaseObject* Factory::fabricate(const ClassID& classID)
 {
-  if (Factory::factoryList == NULL)
+  FactoryIDMap::const_iterator it = Factory::_factoryIDMap.find(classID);
+  if (it != Factory::_factoryIDMap.end())
+  {
+    PRINTF(4)("Create a new Object of type %s\n", (*it).second->getCName());
+    return (*it).second->fabricateObject(NULL);
+  }
+  else
+  {
+    PRINTF(2)("Could not Fabricate an Object of ClassID '%d'\n", classID.id());
     return NULL;
+  }
+}
 
-  std::list<Factory*>::const_iterator factory;
-  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
-    if (*(*factory) == classID)
-    {
-      PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());
-      return (*factory)->fabricateObject(NULL);
 
-    }
-  PRINTF(2)("Could not Fabricate an Object of ClassID '0x%h'\n", classID);
-  return NULL;
+/**
+ * @brief print out some nice litte debug information about the Factory.
+ */
+void Factory::debug() const
+{
+  PRINTF(0)("Factory of class '%s' with ClassID: %d\n", this->_classID.name().c_str(), this->_classID.id());
 }
+
+/**
+ * @brief Prints out some nice Debug information about all factories
+ */
+void Factory::debugAll()
+{
+  PRINTF(0)("Debugging all %d Factories\n", Factory::_factoryStringMap.size());
+  Factory::FactoryStringMap::const_iterator it;
+  for (it = Factory::_factoryStringMap.begin(); it != Factory::_factoryStringMap.end(); ++it)
+    (*it).second->debug();
+}
