Index: /code/branches/core/src/orxonox/core/ClassTreeMask.cc
===================================================================
--- /code/branches/core/src/orxonox/core/ClassTreeMask.cc	(revision 802)
+++ /code/branches/core/src/orxonox/core/ClassTreeMask.cc	(revision 803)
@@ -80,4 +80,72 @@
     {
         return this->subclass_;
+    }
+
+
+    // ###############################
+    // ###  ClassTreeMaskIterator  ###
+    // ###############################
+    ClassTreeMaskIterator::ClassTreeMaskIterator(ClassTreeMaskNode* node)
+    {
+        std::list<ClassTreeMaskNode*> templist;
+        std::list<ClassTreeMaskNode*>::iterator tempiterator = templist.insert(templist.end(), node);
+        this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(tempiterator, templist.end()));
+    }
+
+    ClassTreeMaskIterator::~ClassTreeMaskIterator()
+    {
+    }
+
+    ClassTreeMaskIterator& ClassTreeMaskIterator::operator++()
+    {
+        if ((*this->nodes_.top().first)->subnodes_.begin() != (*this->nodes_.top().first)->subnodes_.end())
+            this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>((*this->nodes_.top().first)->subnodes_.begin(), (*this->nodes_.top().first)->subnodes_.end()));
+        else
+        {
+            do
+            {
+                ++this->nodes_.top().first;
+                if (this->nodes_.top().first == this->nodes_.top().second)
+                {
+                    this->nodes_.pop();
+                    continue;
+                }
+
+                break;
+            } while (!this->nodes_.empty());
+        }
+
+        return *this;
+    }
+
+    ClassTreeMaskNode* ClassTreeMaskIterator::operator*() const
+    {
+        return (*this->nodes_.top().first);
+    }
+
+    ClassTreeMaskNode* ClassTreeMaskIterator::operator->() const
+    {
+        return (*this->nodes_.top().first);
+    }
+
+    ClassTreeMaskIterator::operator bool()
+    {
+        return (!this->nodes_.empty());
+    }
+
+    bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare)
+    {
+        if (!this->nodes_.empty())
+            return ((*this->nodes_.top().first) == compare);
+        else
+            return (compare == 0);
+    }
+
+    bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare)
+    {
+        if (!this->nodes_.empty())
+            return ((*this->nodes_.top().first) != compare);
+        else
+            return (compare != 0);
     }
 
@@ -162,10 +230,10 @@
     }
 
-    bool ClassTreeMask::isIncluded(const Identifier* subclass)
+    bool ClassTreeMask::isIncluded(const Identifier* subclass) const
     {
         return this->isIncluded(this->root_, subclass);
     }
 
-    bool ClassTreeMask::isIncluded(ClassTreeMaskNode* node, const Identifier* subclass)
+    bool ClassTreeMask::isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const
     {
         // Check if the searched subclass is of the same type as the class in the current node or a derivative
@@ -191,7 +259,115 @@
     }
 
-    bool ClassTreeMask::isExcluded(const Identifier* subclass)
+    bool ClassTreeMask::isExcluded(const Identifier* subclass) const
     {
         return (!this->isIncluded(subclass));
     }
+
+    void ClassTreeMask::clean()
+    {
+        this->clean(this->root_);
+    }
+
+    void ClassTreeMask::clean(ClassTreeMaskNode* node)
+    {
+        for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); )
+        {
+            if ((*it)->isIncluded() == node->isIncluded())
+            {
+                node->subnodes_.insert(node->subnodes_.end(), (*it)->subnodes_.begin(), (*it)->subnodes_.end());
+                (*it)->subnodes_.clear();
+                node->subnodes_.erase(it++);
+            }
+            else
+            {
+                ++it;
+            }
+        }
+    }
+
+    ClassTreeMask ClassTreeMask::operator+(const ClassTreeMask& other) const
+    {
+        ClassTreeMask newmask;
+        for (ClassTreeMaskIterator it = this->root_; it; ++it)
+        {
+            const Identifier* subclass = it->getClass();
+            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
+        }
+        for (ClassTreeMaskIterator it = other.root_; it; ++it)
+        {
+            const Identifier* subclass = it->getClass();
+            newmask.add(subclass, this->isIncluded(subclass) or other.isIncluded(subclass));
+        }
+        newmask.clean();
+
+        return newmask;
+    }
+
+    ClassTreeMask ClassTreeMask::operator*(const ClassTreeMask& other) const
+    {
+        ClassTreeMask newmask;
+        for (ClassTreeMaskIterator it = this->root_; it; ++it)
+        {
+            const Identifier* subclass = it->getClass();
+            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
+        }
+        for (ClassTreeMaskIterator it = other.root_; it; ++it)
+        {
+            const Identifier* subclass = it->getClass();
+            newmask.add(subclass, this->isIncluded(subclass) and other.isIncluded(subclass));
+        }
+        newmask.clean();
+
+        return newmask;
+    }
+
+    ClassTreeMask ClassTreeMask::operator!() const
+    {
+        ClassTreeMask newmask;
+        for (ClassTreeMaskIterator it = this->root_; it; ++it)
+        {
+            const Identifier* subclass = it->getClass();
+            newmask.add(subclass, !this->isIncluded(subclass));
+        }
+
+        return newmask;
+    }
+
+    ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const
+    {
+        return ((*this) * (!other));
+    }
+
+    ClassTreeMask ClassTreeMask::operator&(const ClassTreeMask& other) const
+    {
+        return ((*this) * other);
+    }
+
+    ClassTreeMask ClassTreeMask::operator|(const ClassTreeMask& other) const
+    {
+        return ((*this) + other);
+    }
+
+    ClassTreeMask ClassTreeMask::operator^(const ClassTreeMask& other) const
+    {
+        ClassTreeMask newmask;
+        for (ClassTreeMaskIterator it = this->root_; it; ++it)
+        {
+            const Identifier* subclass = it->getClass();
+            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
+        }
+        for (ClassTreeMaskIterator it = other.root_; it; ++it)
+        {
+            const Identifier* subclass = it->getClass();
+            newmask.add(subclass, this->isIncluded(subclass) xor other.isIncluded(subclass));
+        }
+        newmask.clean();
+
+        return newmask;
+    }
+
+    ClassTreeMask ClassTreeMask::operator~() const
+    {
+        return (!(*this));
+    }
 }
Index: /code/branches/core/src/orxonox/core/ClassTreeMask.h
===================================================================
--- /code/branches/core/src/orxonox/core/ClassTreeMask.h	(revision 802)
+++ /code/branches/core/src/orxonox/core/ClassTreeMask.h	(revision 803)
@@ -30,4 +30,5 @@
 
 #include <list>
+#include <stack>
 
 #include "CorePrereqs.h"
@@ -38,4 +39,5 @@
     {
         friend class ClassTreeMask;
+        friend class ClassTreeMaskIterator;
 
         public:
@@ -60,4 +62,21 @@
     };
 
+    class ClassTreeMaskIterator
+    {
+        public:
+            ClassTreeMaskIterator(ClassTreeMaskNode* node);
+            ~ClassTreeMaskIterator();
+
+            ClassTreeMaskIterator& operator++();
+            ClassTreeMaskNode* operator*() const;
+            ClassTreeMaskNode* operator->() const;
+            operator bool();
+            bool operator==(ClassTreeMaskNode* compare);
+            bool operator!=(ClassTreeMaskNode* compare);
+
+        private:
+            std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_;
+    };
+
     class ClassTreeMask
     {
@@ -70,11 +89,23 @@
             void add(const Identifier* subclass, bool bInclude);
             void reset();
+            void clean();
 
-            bool isIncluded(const Identifier* subclass);
-            bool isExcluded(const Identifier* subclass);
+            bool isIncluded(const Identifier* subclass) const;
+            bool isExcluded(const Identifier* subclass) const;
+
+            ClassTreeMask operator+(const ClassTreeMask& other) const;
+            ClassTreeMask operator*(const ClassTreeMask& other) const;
+            ClassTreeMask operator!() const;
+            ClassTreeMask operator-(const ClassTreeMask& other) const;
+
+            ClassTreeMask operator&(const ClassTreeMask& other) const;
+            ClassTreeMask operator|(const ClassTreeMask& other) const;
+            ClassTreeMask operator^(const ClassTreeMask& other) const;
+            ClassTreeMask operator~() const;
 
         private:
             void add(ClassTreeMaskNode* node, const Identifier* subclass, bool bInclude);
-            bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass);
+            bool isIncluded(ClassTreeMaskNode* node, const Identifier* subclass) const;
+            void clean(ClassTreeMaskNode* node);
 
             ClassTreeMaskNode* root_;
