Index: code/trunk/src/orxonox/core/Identifier.h
===================================================================
--- code/trunk/src/orxonox/core/Identifier.h	(revision 790)
+++ code/trunk/src/orxonox/core/Identifier.h	(revision 871)
@@ -26,5 +26,5 @@
  */
 
-/*!
+/**
     @file Identifier.h
     @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
@@ -39,5 +39,5 @@
 
     Every object has a pointer to the Identifier of its class. This allows the use isA(...),
-    isDirectlyA(...), isChildOf(...) and isParentOf(...).
+    isExactlyA(...), isChildOf(...) and isParentOf(...).
 
     To create the class-hierarchy, the Identifier has some intern functions and variables.
@@ -52,4 +52,5 @@
 #define _Identifier_H__
 
+#include <list>
 #include <map>
 #include <string>
@@ -59,5 +60,4 @@
 
 #include "ObjectList.h"
-#include "IdentifierList.h"
 #include "Debug.h"
 #include "Iterator.h"
@@ -82,5 +82,5 @@
 
         Every object has a pointer to the Identifier of its class. This allows the use isA(...),
-        isDirectlyA(...), isChildOf(...) and isParentOf(...).
+        isExactlyA(...), isChildOf(...) and isParentOf(...).
 
         You can't directly create an Identifier, it's just the base-class for ClassIdentifier.
@@ -89,10 +89,10 @@
     {
         template <class T>
-        friend class ClassIdentifier; // Forward declaration
+        friend class ClassIdentifier;
 
         template <class T>
-        friend class SubclassIdentifier; // Forward declaration
-
-        friend class Factory; // Forward declaration
+        friend class SubclassIdentifier;
+
+        friend class Factory;
 
         public:
@@ -102,26 +102,48 @@
             BaseObject* fabricate();
             bool isA(const Identifier* identifier) const;
-            bool isDirectlyA(const Identifier* identifier) const;
+            bool isExactlyA(const Identifier* identifier) const;
             bool isChildOf(const Identifier* identifier) const;
+            bool isDirectChildOf(const Identifier* identifier) const;
             bool isParentOf(const Identifier* identifier) const;
-
-            static std::map<std::string, Identifier*>& getIdentifierMap();
+            bool isDirectParentOf(const Identifier* identifier) const;
 
             /** @brief Removes all objects of the corresponding class. */
             virtual void removeObjects() const = 0;
 
-            /** @returns the name of the class the Identifier belongs to. */
+            /** @brief Returns the name of the class the Identifier belongs to. @return The name */
             inline const std::string& getName() const { return this->name_; }
 
-            /** @returns the parents of the class the Identifier belongs to. */
-            inline const IdentifierList& getParents() const { return this->parents_; }
-
-            /** @returns the children of the class the Identifier belongs to. */
-            inline IdentifierList& getChildren() const { return *this->children_; }
-
-            /** @returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. */
+            /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */
+            inline const std::list<const Identifier*>& getParents() const { return this->parents_; }
+            /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */
+            inline std::list<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }
+            /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */
+            inline std::list<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }
+
+            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
+            inline const std::list<const Identifier*>& getChildren() const { return (*this->children_); }
+            /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */
+            inline std::list<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }
+            /** @brief Returns the end-iterator of the children-list. @return The end-iterator */
+            inline std::list<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }
+
+            /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */
+            inline const std::list<const Identifier*>& getDirectParents() const { return this->directParents_; }
+            /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */
+            inline std::list<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }
+            /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */
+            inline std::list<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }
+
+            /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */
+            inline const std::list<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }
+            /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */
+            inline std::list<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }
+            /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */
+            inline std::list<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); }
+
+            /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */
             inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }
 
-            /** @returns the network ID to identify a class through the network. */
+            /** @brief Returns the network ID to identify a class through the network. @return the network ID */
             inline const unsigned int getNetworkID() const { return this->classID_; }
 
@@ -129,11 +151,14 @@
             void setNetworkID(unsigned int id);
 
-            /** @returns the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variable */
-            inline ConfigValueContainer* getConfigValueContainer(const std::string& varname)
-                { return this->configValues_[varname]; }
-
-            /** @brief Sets the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variablee @param container The container */
-            inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container)
-                { this->configValues_[varname] = container; }
+            ConfigValueContainer* getConfigValueContainer(const std::string& varname);
+            void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
+
+            virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0;
+            virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0;
+
+            virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0;
+            virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0;
+
+            static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list);
 
         private:
@@ -141,5 +166,10 @@
             Identifier(const Identifier& identifier) {} // don't copy
             virtual ~Identifier();
-            void initialize(const IdentifierList* parents);
+            void initialize(std::list<const Identifier*>* parents);
+
+            /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */
+            inline std::list<const Identifier*>& getChildrenIntern() const { return (*this->children_); }
+            /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */
+            inline std::list<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }
 
             /**
@@ -149,5 +179,5 @@
             {
                 hierarchyCreatingCounter_s++;
-                COUT(4) << "*** Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
+                COUT(4) << "*** Identifier: Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
             }
 
@@ -158,9 +188,12 @@
             {
                 hierarchyCreatingCounter_s--;
-                COUT(4) << "*** Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
-            }
-
-            IdentifierList parents_;                                    //!< The Parents of the class the Identifier belongs to
-            IdentifierList* children_;                                  //!< The Children of the class the Identifier belongs to
+                COUT(4) << "*** Identifier: Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl;
+            }
+
+            std::list<const Identifier*> parents_;                      //!< The parents of the class the Identifier belongs to
+            std::list<const Identifier*>* children_;                    //!< The children of the class the Identifier belongs to
+
+            std::list<const Identifier*> directParents_;                //!< The direct parents of the class the Identifier belongs to
+            std::list<const Identifier*>* directChildren_;              //!< The direct children of the class the Identifier belongs to
 
             std::string name_;                                          //!< The name of the class the Identifier belongs to
@@ -173,4 +206,6 @@
     };
 
+    std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list);
+
 
     // ###############################
@@ -182,14 +217,29 @@
         This makes it possible to store informations about a class, sharing them with all
         objects of that class without defining static variables in every class.
+
+        To be really sure that not more than exactly one object exists (even with libraries),
+        ClassIdentifiers are only created by IdentifierDistributor.
+
+        You can access the ClassIdentifiers created by IdentifierDistributor through the
+        ClassManager singletons.
     */
     template <class T>
     class ClassIdentifier : public Identifier
     {
+        template <class TT>
+        friend class ClassManager;
+
         public:
-            static ClassIdentifier<T>* registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass);
-            static void addObject(T* object);
-            static ClassIdentifier<T>* getIdentifier();
+            ClassIdentifier<T>* registerClass(std::list<const Identifier*>* parents, const std::string& name, bool bRootClass);
+            void addObject(T* object);
             void removeObjects() const;
             void setName(const std::string& name);
+            inline const ObjectList<T>* getObjects() const { return this->objects_; }
+
+            XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);
+            void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);
+
+            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
+            void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
 
         private:
@@ -200,4 +250,6 @@
             ObjectList<T>* objects_;    //!< The ObjectList, containing all objects of type T
             bool bSetName_;             //!< True if the name is set
+            std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_;
+            std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_;
     };
 
@@ -208,5 +260,6 @@
     ClassIdentifier<T>::ClassIdentifier()
     {
-        this->objects_ = ObjectList<T>::getList();
+//        this->objects_ = ObjectList<T>::getList();
+        this->objects_ = new ObjectList<T>();
         this->bSetName_ = false;
     }
@@ -214,5 +267,5 @@
     /**
         @brief Registers a class, which means that the name and the parents get stored.
-        @param parents An IdentifierList, containing the Identifiers of all parents of the class
+        @param parents A list, containing the Identifiers of all parents of the class
         @param name A string, containing exactly the name of the class
         @param bRootClass True if the class is either an Interface or the BaseObject itself
@@ -220,41 +273,22 @@
     */
     template <class T>
-    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass)
-    {
-        COUT(4) << "*** Register Class in " << name << "-Singleton." << std::endl;
+    ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::list<const Identifier*>* parents, const std::string& name, bool bRootClass)
+    {
+        COUT(5) << "*** ClassIdentifier: Register Class in " << name << "-Singleton." << std::endl;
 
         // Check if at least one object of the given type was created
-        if (!getIdentifier()->bCreatedOneObject_)
+        if (!this->bCreatedOneObject_)
         {
             // If no: We have to store the informations and initialize the Identifier
-            getIdentifier()->setName(name);
-
-            COUT(4) << "*** Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
+            this->setName(name);
+
+            COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl;
             if (bRootClass)
-                getIdentifier()->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.
+                this->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case.
             else
-                getIdentifier()->initialize(parents);
+                this->initialize(parents);
         }
 
-        return getIdentifier();
-    }
-
-    /**
-        @brief Creates the only instance of this class for the template class T.
-        @return The Identifier itself
-    */
-    template <class T>
-    ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()
-    {
-        static ClassIdentifier<T> theOneAndOnlyInstance = ClassIdentifier<T>();
-        static bool bIdentifierCreated = false;
-
-        if (!bIdentifierCreated)
-        {
-            COUT(4) << "*** Create Identifier Singleton." << std::endl;
-            bIdentifierCreated = true;
-        }
-
-        return &theOneAndOnlyInstance;
+        return this;
     }
 
@@ -266,9 +300,7 @@
     void ClassIdentifier<T>::setName(const std::string& name)
     {
-        // Make sure we didn't already set the name, to avoid duplicate entries in the Identifier map
         if (!this->bSetName_)
         {
             this->name_ = name;
-            this->getIdentifierMap().insert(std::pair<std::string, Identifier*>(name, this));
             this->bSetName_ = true;
         }
@@ -282,6 +314,6 @@
     void ClassIdentifier<T>::addObject(T* object)
     {
-        COUT(4) << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;
-        object->getMetaList().add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object));
+        COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;
+        object->getMetaList().add(this->objects_, this->objects_->add(object));
     }
 
@@ -292,7 +324,40 @@
     void ClassIdentifier<T>::removeObjects() const
     {
-        for (Iterator<T> it = ObjectList<T>::start(); it;)
+        for (Iterator<T> it = this->objects_->start(); it;)
             delete *(it++);
     }
+
+    template <class T>
+    XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname)
+    {
+        typename std::map<std::string, XMLPortClassParamContainer<T>*>::const_iterator it = xmlportParamContainers_.find(paramname);
+        if (it != xmlportParamContainers_.end())
+            return (XMLPortParamContainer*)((*it).second);
+        else
+            return 0;
+    }
+
+    template <class T>
+    void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
+    {
+        this->xmlportParamContainers_[paramname] = (XMLPortClassParamContainer<T>*)container;
+    }
+
+    template <class T>
+    XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname)
+    {
+        typename std::map<std::string, XMLPortClassObjectContainer<T, class O>*>::const_iterator it = xmlportObjectContainers_.find(sectionname);
+        if (it != xmlportObjectContainers_.end())
+            return (XMLPortObjectContainer*)((*it).second);
+        else
+            return 0;
+    }
+
+    template <class T>
+    void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
+    {
+        this->xmlportObjectContainers_[sectionname] = (XMLPortClassObjectContainer<T, class O>*)container;
+    }
+
 
     // ###############################
@@ -314,5 +379,14 @@
             SubclassIdentifier()
             {
-                this->identifier_ = ClassIdentifier<T>::getIdentifier();
+                this->identifier_ = ClassManager<T>::getIdentifier();
+            }
+
+            /**
+                @brief Copyconstructor: Assigns the given Identifier.
+                @param identifier The Identifier
+            */
+            SubclassIdentifier(Identifier* identifier)
+            {
+                this->identifier_ = identifier;
             }
 
@@ -324,8 +398,9 @@
             SubclassIdentifier<T>& operator=(Identifier* identifier)
             {
-                if (!identifier->isA(ClassIdentifier<T>::getIdentifier()))
+                if (!identifier->isA(ClassManager<T>::getIdentifier()))
                 {
-                    COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
-                    COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
+                    COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
+                    COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassManager<T>::getIdentifier()->getName() << "!" << std::endl;
+                    COUT(1) << "Error: SubclassIdentifier<" << ClassManager<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;
                     COUT(1) << "Aborting..." << std::endl;
                     abort();
@@ -372,5 +447,6 @@
                     if (this->identifier_)
                     {
-                        COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;
+                        COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
+                        COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassManager<T>::getIdentifier()->getName() << "!" << std::endl;
                         COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;
                         COUT(1) << "Aborting..." << std::endl;
@@ -378,4 +454,5 @@
                     else
                     {
+                        COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;
                         COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;
                         COUT(1) << "Aborting..." << std::endl;
@@ -386,26 +463,34 @@
             }
 
-            /** @returns the assigned identifier. */
+            /** @brief Returns the assigned identifier. @return The identifier */
             inline const Identifier* getIdentifier() const
                 { return this->identifier_; }
 
-            /** @returns true, if the assigned identifier is at least of the given type. @param identifier The identifier to compare with */
+            /** @brief Returns true, if the assigned identifier is at least of the given type. @param identifier The identifier to compare with */
             inline bool isA(const Identifier* identifier) const
                 { return this->identifier_->isA(identifier); }
 
-            /** @returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */
-            inline bool isDirectlyA(const Identifier* identifier) const
-                { return this->identifier_->isDirectlyA(identifier); }
-
-            /** @returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */
+            /** @brief Returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */
+            inline bool isExactlyA(const Identifier* identifier) const
+                { return this->identifier_->isExactlyA(identifier); }
+
+            /** @brief Returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */
             inline bool isChildOf(const Identifier* identifier) const
                 { return this->identifier_->isChildOf(identifier); }
 
-            /** @returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */
+            /** @brief Returns true, if the assigned identifier is a direct child of the given identifier. @param identifier The identifier to compare with */
+            inline bool isDirectChildOf(const Identifier* identifier) const
+                { return this->identifier_->isDirectChildOf(identifier); }
+
+            /** @brief Returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */
             inline bool isParentOf(const Identifier* identifier) const
                 { return this->identifier_->isParentOf(identifier); }
 
+            /** @brief Returns true, if the assigned identifier is a direct parent of the given identifier. @param identifier The identifier to compare with */
+            inline bool isDirectParentOf(const Identifier* identifier) const
+                { return this->identifier_->isDirectParentOf(identifier); }
+
         private:
-            Identifier* identifier_;        //!< The assigned identifier
+            Identifier* identifier_;            //!< The assigned identifier
     };
 }
