Index: code/branches/core2/src/orxonox/core/CMakeLists.txt
===================================================================
--- code/branches/core2/src/orxonox/core/CMakeLists.txt	(revision 879)
+++ code/branches/core2/src/orxonox/core/CMakeLists.txt	(revision 895)
@@ -18,4 +18,5 @@
   XMLPort.cc
   Namespace.cc
+  NamespaceNode.cc
 )
 
Index: code/branches/core2/src/orxonox/core/CorePrereqs.h
===================================================================
--- code/branches/core2/src/orxonox/core/CorePrereqs.h	(revision 879)
+++ code/branches/core2/src/orxonox/core/CorePrereqs.h	(revision 895)
@@ -96,4 +96,5 @@
   class MetaObjectListElement;
   class Namespace;
+  class NamespaceNode;
   template <class T>
   class ObjectList;
Index: code/branches/core2/src/orxonox/core/Namespace.cc
===================================================================
--- code/branches/core2/src/orxonox/core/Namespace.cc	(revision 879)
+++ code/branches/core2/src/orxonox/core/Namespace.cc	(revision 895)
@@ -29,4 +29,6 @@
 #include "CoreIncludes.h"
 #include "XMLPort.h"
+#include "util/SubString.h"
+#include "NamespaceNode.h"
 
 namespace orxonox
@@ -38,5 +40,6 @@
         RegisterObject(Namespace);
 
-        this->representingNamespace_ = this;
+        this->bAutogeneratedFileRootNamespace_ = false;
+        this->operator_ = "or";
     }
 
@@ -55,4 +58,36 @@
         BaseObject::XMLPort(xmlelement, loading);
 
+        std::string name = this->getName();
+        unsigned int pos = 0;
+        while ((pos = name.find(',')) != std::string::npos)
+            name.replace(pos, 1, " ");
+        while ((pos = name.find(';')) != std::string::npos)
+            name.replace(pos, 1, " ");
+        while ((pos = name.find('\n')) != std::string::npos)
+            name.replace(pos, 1, " ");
+        while ((pos = name.find('\t')) != std::string::npos)
+            name.replace(pos, 1, " ");
+        SubString tokens(name, " ", '\0', false, '\\', '"', '\0', '\0', '\0');
+        for (unsigned int i = 0; i < tokens.size(); i++)
+        {
+            for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
+            {
+                std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
+                this->representingNamespaces_.insert(temp.begin(), temp.end());
+            }
+        }
+
+        XMLPortParam(Namespace, "operator", setOperator, getOperator, xmlelement, loading);
+        XMLPortParam(Namespace, "bAutogenerated", setAutogenerated, isAutogenerated, xmlelement, loading);
+
+        if (this->bAutogeneratedFileRootNamespace_)
+        {
+            for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
+            {
+                (*it)->setRoot(true);
+                (*it)->setHidden(true);
+            }
+        }
+
         XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false);
     }
@@ -60,23 +95,5 @@
     void Namespace::loadObjects(BaseObject* object)
     {
-        object->setNamespace(this->representingNamespace_);
-
-        if (object->isA(Class(Namespace)))
-            this->addSubnamespace((Namespace*)object);
-    }
-
-    void Namespace::addSubnamespace(Namespace* ns)
-    {
-        std::string name = ns->getName().substr(ns->getName().find("::"
-
-        if (!this->hasSubnamespace(ns->getName()))
-            this->namespaces_[ns->getName()] = ns;
-        else
-            ns->representingNamespace_ = object;
-    }
-
-    bool Namespace::hasSubnamespace(const std::string& name) const
-    {
-        return (this->namespaces_.find(name) != this->namespaces_.end());
+        object->setNamespace(this);
     }
 
@@ -85,3 +102,35 @@
         return 0; // todo
     }
+
+    bool Namespace::includes(const Namespace* ns) const
+    {
+        for (std::set<NamespaceNode*>::const_iterator it1 = this->representingNamespaces_.begin(); it1 != this->representingNamespaces_.end(); ++it1)
+        {
+            for (std::set<NamespaceNode*>::const_iterator it2 = ns->representingNamespaces_.begin(); it2 != ns->representingNamespaces_.end(); ++it2)
+            {
+                if ((*it1)->includes(*it2))
+                {
+                    if (this->operator_ == "or")
+                        return true;
+
+                    if (this->operator_ == "not")
+                        return false;
+                }
+                else
+                {
+                    if (this->operator_ == "and")
+                        return false;
+                }
+            }
+        }
+
+        if (this->operator_ == "or")
+            return false;
+        else if (this->operator_ == "and")
+            return true;
+        else if (this->operator_ == "not")
+            return true;
+
+        return false;
+    }
 }
Index: code/branches/core2/src/orxonox/core/Namespace.h
===================================================================
--- code/branches/core2/src/orxonox/core/Namespace.h	(revision 879)
+++ code/branches/core2/src/orxonox/core/Namespace.h	(revision 895)
@@ -49,10 +49,21 @@
             const BaseObject* saveObjects(unsigned int index) const;
 
-            void addSubnamespace(Namespace* ns);
-            bool hasSubnamespace(const std::string& name) const;
+            void setAutogenerated(bool bAutogenerated)
+                { this->bAutogeneratedFileRootNamespace_ = bAutogenerated; }
+            bool isAutogenerated() const
+                { return this->bAutogeneratedFileRootNamespace_; }
+
+            void setOperator(const std::string& op)
+                { this->operator_ = op; }
+            const std::string& getOperator() const
+                { return this->operator_; }
+
+            bool includes(const Namespace* ns) const;
+            bool isIncludedIn(const Namespace* ns) const { return ns->includes(this); }
 
         private:
-            std::map<std::string, Namespace*> namespaces_;
-            Namespace* representingNamespace_;
+            std::set<NamespaceNode*> representingNamespaces_;
+            bool bAutogeneratedFileRootNamespace_;
+            std::string operator_;
     };
 }
Index: code/branches/core2/src/orxonox/core/NamespaceNode.cc
===================================================================
--- code/branches/core2/src/orxonox/core/NamespaceNode.cc	(revision 895)
+++ code/branches/core2/src/orxonox/core/NamespaceNode.cc	(revision 895)
@@ -0,0 +1,115 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "NamespaceNode.h"
+#include "Debug.h"
+
+namespace orxonox
+{
+    NamespaceNode::NamespaceNode(const std::string& name, NamespaceNode* parent)
+    {
+        this->name_ = name;
+        this->parent_ = parent;
+        this->bRoot_ = false;
+        this->bHidden_ = false;
+    }
+
+    NamespaceNode::~NamespaceNode()
+    {
+        for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); )
+            delete ((*(it++)).second);
+    }
+
+    std::set<NamespaceNode*> NamespaceNode::getNodeRelative(const std::string& name)
+    {
+        std::set<NamespaceNode*> nodes;
+
+        if (name == "")
+        {
+            nodes.insert(this);
+        }
+        else
+        {
+            unsigned int pos = name.find("::");
+            std::string firstPart = name.substr(0, pos);
+            std::string secondPart = name.substr(pos + 2, std::string::npos);
+
+            if (firstPart == "..")
+            {
+                if (this->bRoot_)
+                {
+                    COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", namespace is root." << std::endl;
+                    nodes = this->getNodeRelative(secondPart);
+                }
+                else
+                {
+                    nodes = this->parent_->getNodeRelative(secondPart);
+                }
+            }
+            else if (name.find('@') != 0)
+            {
+                std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.find(firstPart);
+                if (it == this->subnodes_.end())
+                    it = this->subnodes_.insert(this->subnodes_.begin(), std::pair<std::string, NamespaceNode*>(firstPart, new NamespaceNode(firstPart, this)));
+
+                if ((*it).second->isHidden())
+                    COUT(2) << "Warning: Subnamespace '" << firstPart << "' in namespace '" << this->name_ << "' is hidden and can't be accessed." << std::endl;
+                else
+                    nodes = (*it).second->getNodeRelative(secondPart);
+            }
+            else
+            {
+                for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
+                {
+                    if ((*it).first.find(firstPart) == ((*it).first.size() - firstPart.size()))
+                    {
+                        std::set<NamespaceNode*> temp2 = (*it).second->getNodeRelative(secondPart);
+                        nodes.insert(temp2.begin(), temp2.end());
+                    }
+                }
+            }
+        }
+
+        return nodes;
+    }
+
+    bool NamespaceNode::includes(const NamespaceNode* ns) const
+    {
+        if (ns == this)
+        {
+            return true;
+        }
+        else
+        {
+            for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
+                if ((*it).second->includes(ns))
+                    return true;
+        }
+
+        return false;
+    }
+}
Index: code/branches/core2/src/orxonox/core/NamespaceNode.h
===================================================================
--- code/branches/core2/src/orxonox/core/NamespaceNode.h	(revision 895)
+++ code/branches/core2/src/orxonox/core/NamespaceNode.h	(revision 895)
@@ -0,0 +1,64 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _NamespaceNode_H__
+#define _NamespaceNode_H__
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "CorePrereqs.h"
+
+namespace orxonox
+{
+    class NamespaceNode
+    {
+        public:
+            NamespaceNode(const std::string& name, NamespaceNode* parent = 0);
+            ~NamespaceNode();
+
+            std::set<NamespaceNode*> getNodeRelative(const std::string& name);
+
+            void setRoot(bool bRoot) { this->bRoot_ = bRoot; }
+            void setHidden(bool bHidden) { this->bHidden_ = bHidden; }
+
+            bool isRoot() const { return this->bRoot_; }
+            bool isHidden() const { return this->bHidden_; }
+
+            bool includes(const NamespaceNode*) const;
+
+        private:
+            std::string name_;
+            NamespaceNode* parent_;
+            std::map<std::string, NamespaceNode*> subnodes_;
+            bool bHidden_;
+            bool bRoot_;
+    };
+}
+
+#endif /* _NamespaceNode_H__ */
Index: code/branches/core2/src/orxonox/core/XMLPort.h
===================================================================
--- code/branches/core2/src/orxonox/core/XMLPort.h	(revision 879)
+++ code/branches/core2/src/orxonox/core/XMLPort.h	(revision 895)
@@ -42,20 +42,24 @@
 
 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, loading) \
-    orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \
-    if (!xmlcontainer##loadfunction##savefunction) \
+    XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##savefunction, createFunctor(&classname::loadfunction), createFunctor(&classname::savefunction), xmlelement, loading)
+#define XMLPortParam_Template(classname, paramname, loadtemplate, loadfunction, savetemplate, savefunction, xmlelement, loading) \
+    XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##savefunction, createFunctor loadtemplate (&classname::loadfunction), createFunctor savetemplate (&classname::savefunction), xmlelement, loading)
+
+
+#define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, loading) \
+    XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##0, createFunctor(&classname::loadfunction), 0, xmlelement, loading)
+#define XMLPortParamLoadOnly_Template(classname, paramname, loadtemplate, loadfunction, xmlelement, loading) \
+    XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##0, createFunctor loadtemplate (&classname::loadfunction), 0, xmlelement, loading)
+
+
+#define XMLPortParamGeneric(classname, paramname, containername, loadfunctor, savefunctor, xmlelement, loading) \
+    orxonox::XMLPortClassParamContainer<classname>* containername = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \
+    if (!containername) \
     { \
-        xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), createFunctor(&classname::savefunction)); \
-        this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \
+        containername = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), loadfunctor, savefunctor); \
+        this->getIdentifier()->addXMLPortParamContainer(paramname, containername); \
     } \
-    xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading)
-
-#define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, loading) \
-    orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \
-    if (!xmlcontainer##loadfunction##savefunction) \
-    { \
-        xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), 0); \
-        this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \
-    } \
-    xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading)
+    containername->port(this, xmlelement, loading)
+
 
 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading, bApplyLoaderMask, bLoadBefore) \
