Index: code/branches/objecthierarchie/src/ClassHierarchy.cc
===================================================================
--- code/branches/objecthierarchie/src/ClassHierarchy.cc	(revision 132)
+++ code/branches/objecthierarchie/src/ClassHierarchy.cc	(revision 149)
@@ -1,259 +1,266 @@
 #include "ClassHierarchy.h"
-#include "BaseObject.h"
-
-//namespace orxonox
-//{
-    // ##### ClassName #####
-    ClassName::ClassName(const std::string& name, ClassNameSingleton<class T>* factory)
-    {
-        this->parentClass = NULL;
-        this->childClasses = new ClassList();
-        this->objects = new ObjectList();
-        this->name = name;
-        this->factory = factory;
-    }
-
-    ClassName::~ClassName()
-    {
-        delete this->childClasses;
-        delete this->objects;
-    }
-
-
-    // ##### ClassListItem #####
-    ClassListItem::ClassListItem(ClassName* className)
-    {
-        this->next = NULL;
-        this->className = className;
-    }
-
-    ClassListItem::~ClassListItem()
-    {
-        delete this->className;
-        delete this->next;
-    }
-
-
-    // ##### ClassList #####
-    ClassList::ClassList()
-    {
-        this->first = NULL;
-    }
-
-    ClassList::~ClassList()
-    {
-        delete this->first;
-    }
-
-    void ClassList::add(ClassName* className)
-    {
-        if (!this->first)
-        {
-            this->first = new ClassListItem(className);
-            return;
-        }
-
-        ClassListItem* iterator = this->first;
-        while (iterator != NULL)
-        {
-            if (iterator->next == NULL)
-            {
-                iterator->next = new ClassListItem(className);
+
+namespace orxonox
+{
+    // ###############################
+    // ###       Identifier        ###
+    // ###############################
+    Identifier* Identifier::pointer_ = NULL;
+/*
+    Identifier* Identifier::registerClass(IdentifierList* parents)
+    {
+        if (!pointer_)
+        {
+            pointer_ = new Identifier();
+            pointer_->initialize(parents);
+        }
+
+        return pointer_;
+    }
+*/
+    Identifier::Identifier()
+    {
+        this->bCreatedOneObject_ = false;
+        this->directParents_ = new IdentifierList();
+        this->allParents_ = new IdentifierList();
+        this->directChildren_ = new IdentifierList();
+        this->allChildren_ = new IdentifierList();
+        this->objects_ = new ObjectList();
+    }
+
+    void Identifier::initialize(IdentifierList* parents)
+    {
+        if (parents)
+        {
+            this->bCreatedOneObject_ = true;
+
+            IdentifierListElement* temp1;
+            IdentifierListElement* temp2;
+            IdentifierListElement* temp3;
+
+            temp1 = parents->first_;
+            while (temp1)
+            {
+                temp2 = temp1->identifier_->directParents_->first_;
+                while (temp2)
+                {
+                    temp3 = parents->first_;
+                    while(temp3)
+                    {
+                        if (temp3->identifier_ == temp2->identifier_)
+                            temp3->bDirect_ = false;
+
+                        temp3 = temp3->next_;
+                    }
+
+                    temp2 = temp2->next_;
+                }
+                temp1 = temp1->next_;
+            }
+
+            temp1 = parents->first_;
+            while (temp1)
+            {
+                if (temp1->bDirect_)
+                {
+                    this->directParents_->add(temp1->identifier_);
+                    temp1->identifier_->directChildren_->add(this->pointer_);
+                }
+
+                this->allParents_->add(temp1->identifier_);
+                temp1->identifier_->allChildren_->add(this->pointer_);
+
+                temp1 = temp1->next_;
+            }
+        }
+    }
+
+    void Identifier::addObject(BaseObject* object)
+    {
+        this->objects_->add(object);
+    }
+
+    void Identifier::removeObject(BaseObject* object)
+    {
+        this->objects_->remove(object);
+    }
+
+    bool Identifier::isA(Identifier* identifier)
+    {
+        return (identifier == this->pointer_ || this->allParents_->isInList(identifier));
+    }
+
+    bool Identifier::isDirectA(Identifier* identifier)
+    {
+        return (identifier == this->pointer_);
+    }
+
+    bool Identifier::isChildOf(Identifier* identifier)
+    {
+        return this->allParents_->isInList(identifier);
+    }
+
+    bool Identifier::isDirectChildOf(Identifier* identifier)
+    {
+        return this->directParents_->isInList(identifier);
+    }
+
+    bool Identifier::isParentOf(Identifier* identifier)
+    {
+        return this->allChildren_->isInList(identifier);
+    }
+
+    bool Identifier::isDirectParentOf(Identifier* identifier)
+    {
+        return this->directChildren_->isInList(identifier);
+    }
+
+
+    // ###############################
+    // ###     IdentifierList      ###
+    // ###############################
+    IdentifierList::IdentifierList()
+    {
+        this->first_ = NULL;
+    }
+
+    IdentifierList::~IdentifierList()
+    {
+        IdentifierListElement* temp;
+        while (this->first_)
+        {
+            temp = this->first_->next_;
+            delete this->first_;
+            this->first_ = temp;
+        }
+    }
+
+    void IdentifierList::add(Identifier* identifier)
+    {
+        IdentifierListElement* temp = this->first_;
+        this->first_ = new IdentifierListElement(identifier);
+        this->first_->next_ = temp;
+    }
+
+    void IdentifierList::remove(Identifier* identifier)
+    {
+        if (!identifier)
+            return;
+
+        if (this->first_->identifier_ == identifier)
+        {
+            IdentifierListElement* temp = this->first_->next_;
+            delete this->first_;
+            this->first_ = temp;
+
+            return;
+        }
+
+        IdentifierListElement* temp = this->first_;
+        while (temp->next_)
+        {
+            if (temp->next_->identifier_ == identifier)
+            {
+                IdentifierListElement* temp2 = temp->next_->next_;
+                delete temp->next_;
+                temp->next_ = temp2;
+
                 return;
             }
 
-            iterator = iterator->next;
-        }
-    }
-
-    // ##### ObjectListItem #####
-    ObjectListItem::ObjectListItem(BaseObject* object)
-    {
-        this->next = NULL;
-        this->object = object;
-    }
-
-    ObjectListItem::~ObjectListItem()
-    {
-        delete this->object;
-        delete this->next;
-    }
-
-
-    // ##### ObjectList #####
+            temp = temp->next_;
+        }
+    }
+
+    bool IdentifierList::isInList(Identifier* identifier)
+    {
+        IdentifierListElement* temp = this->first_;
+        while (temp)
+        {
+            if (temp->identifier_ == identifier)
+                return true;
+
+            temp = temp->next_;
+        }
+
+        return false;
+    }
+
+
+    // ###############################
+    // ###  IdentifierListElement  ###
+    // ###############################
+    IdentifierListElement::IdentifierListElement(Identifier* identifier)
+    {
+        this->identifier_ = identifier;
+        this->next_ = NULL;
+        this->bDirect_ = true;
+    }
+
+
+    // ###############################
+    // ###       ObjectList        ###
+    // ###############################
     ObjectList::ObjectList()
     {
-        this->first = NULL;
+        this->first_ = NULL;
     }
 
     ObjectList::~ObjectList()
     {
-        delete this->first;
+        ObjectListElement* temp;
+        while (this->first_)
+        {
+            temp = this->first_->next_;
+            delete this->first_;
+            this->first_ = temp;
+        }
     }
 
     void ObjectList::add(BaseObject* object)
     {
-        if (!this->first)
-        {
-            this->first = new ObjectListItem(object);
-            return;
-        }
-
-        ObjectListItem* iterator = this->first;
-        while (iterator != NULL)
-        {
-            if (iterator->next == NULL)
-            {
-                iterator->next = new ObjectListItem(object);
+        ObjectListElement* temp = this->first_;
+        this->first_ = new ObjectListElement(object);
+        this->first_->next_ = temp;
+    }
+
+    void ObjectList::remove(BaseObject* object)
+    {
+        if (!object)
+            return;
+
+        if (this->first_->object_ == object)
+        {
+            ObjectListElement* temp = this->first_->next_;
+            delete this->first_;
+            this->first_ = temp;
+
+            return;
+        }
+
+        ObjectListElement* temp = this->first_;
+        while (temp->next_)
+        {
+            if (temp->next_->object_ == object)
+            {
+                ObjectListElement* temp2 = temp->next_->next_;
+                delete temp->next_;
+                temp->next_ = temp2;
+
                 return;
             }
 
-            iterator = iterator->next;
-        }
-    }
-
-    void ObjectList::remove(BaseObject* object)
-    {
-        if (!this->first || !object)
-            return;
-
-        if (this->first->object == object)
-        {
-            ObjectListItem* temp = this->first->next;
-            delete this->first;
-            this->first = temp;
-
-            return;
-        }
-
-        ObjectListItem* iterator = this->first;
-        while (iterator->next != NULL)
-        {
-            if (iterator->next->object == object)
-            {
-                ObjectListItem* temp = iterator->next->next;
-                delete iterator->next;
-                iterator->next = temp;
-
-                return;
-            }
-
-            iterator = iterator->next;
-        }
-    }
-
-    // ##### ClassNameTree #####
-    ClassNameTree* ClassNameTree::pointer = NULL;
-
-    ClassNameTree::ClassNameTree()
-    {
-    }
-
-    ClassNameTree::~ClassNameTree()
-    {
-        this->pointer = NULL;
-    }
-
-    ClassNameTree* ClassNameTree::getSingleton()
-    {
-        if (!pointer)
-        {
-            pointer = new ClassNameTree();
-        }
-
-        return pointer;
-    }
-/*
-    BaseObject* ClassNameTree::create(ClassName* className)
-    {
-        return className->factory->create();
-    }
-
-    BaseObject* ClassNameTree::create(std::string& name)
-    {
-        return this->getClassName(name)->factory->create();
-    }
-*/
-    ClassName* ClassNameTree::getClassName(std::string& name)
-    {
-        return getClassName(name, this->rootClass);
-    }
-
-    ClassName* ClassNameTree::getClassName(std::string& name, ClassName* root)
-    {
-        if (root->name == name)
-            return root;
-
-        ClassListItem* temp = root->childClasses->first;
-        while (temp != NULL)
-        {
-            ClassName* temp2 = this->getClassName(name, temp->className);
-            if (temp2)
-                return temp2;
-
-            temp = temp->next;
-        }
-
-        return NULL;
-    }
-
-
-    // ##### ClassNameSingleton #####
-    #define getClassNameString(ClassName) \
-        #ClassName
-
-    template <class T>
-    ClassNameSingleton<T>* ClassNameSingleton<T>::pointer = NULL;
-
-    template <class T>
-    ClassName* ClassNameSingleton<T>::className = NULL;
-
-    template <class T>
-    ClassName* ClassNameSingleton<T>::getClassName(BaseObject* object, bool bIsRootClass)
-    {
-        if (!pointer || !className)
-        {
-            pointer = new ClassNameSingleton<T>();
-            className = new ClassName(getClassNameString(T), pointer);
-
-            if (bIsRootClass)
-            {
-                className->parentClass = NULL;
-                ClassNameTree::getSingleton()->setRootClass(className);
-            }
-            else
-            {
-                className->parentClass = object->className;
-                object->className->childClasses->add(className);
-            }
-        }
-
-        return className;
-    }
-
-    template <class T>
-    ClassName* ClassNameSingleton<T>::getNewClassName()
-    {
-        if (!pointer || !className)
-        {
-            T* temp = new T();
-            delete temp;
-        }
-
-        return className;
-    }
-
-    template <class T>
-    BaseObject* ClassNameSingleton<T>::create()
-    {
-        return new T();
-    }
-
-    template <class T>
-    ClassNameSingleton<T>::~ClassNameSingleton()
-    {
-        this->pointer = NULL;
-        delete this->className;
-        this->className = NULL;
-    }
-//}
+            temp = temp->next_;
+        }
+    }
+
+
+    // ###############################
+    // ###    ObjectListElement    ###
+    // ###############################
+    ObjectListElement::ObjectListElement(BaseObject* object)
+    {
+        this->object_ = object;
+        this->next_ = NULL;
+    }
+}
