Index: branches/new_class_id/src/lib/util/loading/factory.cc
===================================================================
--- branches/new_class_id/src/lib/util/loading/factory.cc	(revision 9725)
+++ branches/new_class_id/src/lib/util/loading/factory.cc	(revision 9762)
@@ -35,12 +35,13 @@
   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;
 
 /**
@@ -49,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);
 }
 
@@ -99,16 +87,15 @@
 BaseObject* Factory::fabricate(const TiXmlElement* root)
 {
-  assert (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;
+  }
 }
 
@@ -121,16 +108,15 @@
 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;
+  }
 }
 
@@ -142,16 +128,34 @@
 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 '%d'\n", classID.id());
-  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();
+}
