Index: code/trunk/src/core/ClassTreeMask.cc
===================================================================
--- code/trunk/src/core/ClassTreeMask.cc	(revision 1756)
+++ code/trunk/src/core/ClassTreeMask.cc	(revision 1757)
@@ -102,31 +102,4 @@
 
     /**
-        @brief Tells if the rule is "included" or not.
-        @return The rule: true = included, false = excluded
-    */
-    bool ClassTreeMaskNode::isIncluded() const
-    {
-        return this->bIncluded_;
-    }
-
-    /**
-        @brief Tells if the rule is "excluded" or not.
-        @return The inverted rule: true = excluded, false = included
-    */
-    bool ClassTreeMaskNode::isExcluded() const
-    {
-        return (!this->bIncluded_);
-    }
-
-    /**
-        @brief Returns the Identifier of the class the rule refers to.
-        @return The Identifier representing the class
-    */
-    const Identifier* ClassTreeMaskNode::getClass() const
-    {
-        return this->subclass_;
-    }
-
-    /**
         @brief Deletes all subnodes of this node.
     */
@@ -169,5 +142,5 @@
         @return A reference to the iterator itself
     */
-    ClassTreeMaskIterator& ClassTreeMaskIterator::operator++()
+    const ClassTreeMaskIterator& ClassTreeMaskIterator::operator++()
     {
         // Check if the actual node has subnodes
@@ -226,5 +199,5 @@
         @return True if we've reached the end of the tree
     */
-    ClassTreeMaskIterator::operator bool()
+    ClassTreeMaskIterator::operator bool() const
     {
         return (!this->nodes_.empty());
@@ -236,5 +209,5 @@
         @return The result of the comparison (true if they match)
     */
-    bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare)
+    bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare) const
     {
         if (!this->nodes_.empty())
@@ -249,5 +222,5 @@
         @return The result of the comparison (true if they don't match)
     */
-    bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare)
+    bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare) const
     {
         if (!this->nodes_.empty())
@@ -545,5 +518,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other)
+    const ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other)
     {
         // Make a copy to avoid troubles with self-assignments (like A = A).
@@ -598,5 +571,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator+()
+    const ClassTreeMask& ClassTreeMask::operator+() const
     {
         return (*this);
@@ -709,5 +682,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other)
+    const ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other)
     {
         (*this) = (*this) + other;
@@ -720,5 +693,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other)
+    const ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other)
     {
         (*this) = (*this) * other;
@@ -731,5 +704,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other)
+    const ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other)
     {
         (*this) = (*this) - other;
@@ -802,5 +775,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other)
+    const ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other)
     {
         (*this) = (*this) & other;
@@ -813,5 +786,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other)
+    const ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other)
     {
         (*this) = (*this) | other;
@@ -824,5 +797,5 @@
         @return A reference to the mask itself
     */
-    ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other)
+    const ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other)
     {
         (*this) = (*this) ^ other;
@@ -853,3 +826,139 @@
         return out;
     }
+
+
+    // ###################################
+    // ### ClassTreeMaskObjectIterator ###
+    // ###################################
+    /**
+        @brief Initializes the iterator from a given ClassTreeMask.
+        @param mask The mask
+    */
+    const ClassTreeMaskObjectIterator& ClassTreeMaskObjectIterator::operator=(const ClassTreeMask& mask)
+    {
+        // Clear everything, use a cleaned copy of the mask
+        this->subclasses_.clear();
+        ClassTreeMask temp = mask;
+        temp.clean();
+
+        // Create the subclass-list by going through the mask-tree, starting with the root-node
+        this->create(temp.root_);
+
+        // Move the subclass-iterator to the beginning of the subclass-list
+        this->subclassIterator_ = this->subclasses_.begin();
+
+        // If there is a first subclass, move the object-iterator to the first object of this class. Else go to the end
+        if (this->subclassIterator_ != this->subclasses_.end())
+            this->objectIterator_ = (*this->subclassIterator_).first->getObjects()->begin();
+        else
+            this->objectIterator_ = ObjectList<BaseObject>::end();
+
+        // Check if the iterator points on a valid object. If not, go to the next object by calling ++
+        if (!this->objectIterator_ || ((*this->subclassIterator_).second && !this->objectIterator_->isExactlyA((*this->subclassIterator_).first)))
+            this->operator++();
+
+        return (*this);
+    }
+
+    /**
+        @brief Iterate to the next object (if any).
+        @return The iterator itself
+    */
+    const ClassTreeMaskObjectIterator& ClassTreeMaskObjectIterator::operator++()
+    {
+        if (this->objectIterator_)
+        {
+            // The iterator points on a valid object, therefore we also have a valid subclass-iterator at the moment
+            do
+            {
+                // Go to the next object
+                ++this->objectIterator_;
+
+                while (!this->objectIterator_)
+                {
+                    // We reached the end of the current objectlist - go to the next class
+                    ++this->subclassIterator_;
+
+                    // Check if there really is a next class. If yes, move the object-iterator to the first object
+                    if (this->subclassIterator_ != this->subclasses_.end())
+                        this->objectIterator_ = (*this->subclassIterator_).first->getObjects()->begin();
+                    else
+                        return (*this);
+                }
+
+            // Repeat this until we reach a valid object or the end
+            } while ((*this->subclassIterator_).second && !this->objectIterator_->isExactlyA((*this->subclassIterator_).first));
+        }
+        return (*this);
+    }
+
+    /**
+        @brief Recursive function to create the Iterators subclass-list by going through the node-tree of the mask.
+        @param node The current node
+    */
+    void ClassTreeMaskObjectIterator::create(ClassTreeMaskNode* node)
+    {
+        // Add the class of this node to the list, if the class is included
+        if (node->isIncluded())
+        {
+            // If there are some subnodes, the bool is "true", meaning we have to check for the exact clss when iterating
+            if (node->hasSubnodes())
+                this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(node->getClass(), true));
+            else
+                this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(node->getClass(), false));
+        }
+
+        // Now check if the node has subnodes
+        if (node->hasSubnodes())
+        {
+            // Get all _direct_ children of the nodes class
+            std::set<const Identifier*> directChildren = node->getClass()->getDirectChildren();
+
+            // Iterate through all subnodes
+            for (std::list<ClassTreeMaskNode*>::iterator it1 = node->subnodes_.begin(); it1 != node->subnodes_.end(); ++it1)
+            {
+                // Recursive call to this function with the subnode
+                this->create(*it1);
+
+                // Only execute the following code if the current node is included, meaning some of the subnodes might be included too
+                if (node->isIncluded())
+                {
+                    scanChildren: // This is a label for goto
+
+                    // Iterate through all direct children
+                    for (std::set<const Identifier*>::iterator it2 = directChildren.begin(); it2 != directChildren.end(); ++it2)
+                    {
+                        // Check if the subnode (it1) is a child of the directChild (it2)
+                        if ((*it1)->getClass()->isA(*it2))
+                        {
+                            // Yes it is - remove the directChild (it2) from the list, because it will already be handled by a recursive call to the create() function
+                            directChildren.erase(it2);
+
+                            // Check if the removed directChild was exactly the subnode
+                            if (!(*it1)->getClass()->isExactlyA(*it2))
+                            {
+                                // No, it wasn't exactly the subnode - therefore there are some classes between
+
+                                // Add the previously removed directChild (it2) to the subclass-list
+                                this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(*it2, true));
+
+                                // Insert all directChildren of the directChild
+                                directChildren.insert((*it2)->getDirectChildrenBegin(), (*it2)->getDirectChildrenEnd());
+
+                                // Restart the scan with the expanded set of directChildren
+                                goto scanChildren;
+                            }
+                            break;
+                        }
+                    }
+                }
+            }
+
+            // Now add all directChildren which don't have subnodes on their own to the subclass-list
+            // The bool is "false", meaning they have no subnodes and therefore need no further checks
+            if (node->isIncluded())
+                for (std::set<const Identifier*>::iterator it = directChildren.begin(); it != directChildren.end(); ++it)
+                    this->subclasses_.insert(this->subclasses_.end(), std::pair<const Identifier*, bool>(*it, false));
+        }
+    }
 }
Index: code/trunk/src/core/ClassTreeMask.h
===================================================================
--- code/trunk/src/core/ClassTreeMask.h	(revision 1756)
+++ code/trunk/src/core/ClassTreeMask.h	(revision 1757)
@@ -76,4 +76,6 @@
 #include <stack>
 
+#include "Iterator.h"
+
 namespace orxonox
 {
@@ -91,4 +93,5 @@
         friend class ClassTreeMask;
         friend class ClassTreeMaskIterator;
+        friend class ClassTreeMaskObjectIterator;
 
         public:
@@ -102,8 +105,14 @@
             void addSubnode(ClassTreeMaskNode* subnode);
 
-            bool isIncluded() const;
-            bool isExcluded() const;
-
-            const Identifier* getClass() const;
+            /** @brief Tells if the rule is "included" or not. @return The rule: true = included, false = excluded */
+            inline bool isIncluded() const { return this->bIncluded_; }
+            /** @brief Tells if the rule is "excluded" or not. @return The inverted rule: true = excluded, false = included */
+            inline bool isExcluded() const { return (!this->bIncluded_); }
+
+            /** @brief Returns the Identifier of the class the rule refers to. @return The Identifier representing the class */
+            inline const Identifier* getClass() const { return this->subclass_; }
+
+            /** @brief Returns true if the Node has some subnodes. */
+            inline bool hasSubnodes() const { return !this->subnodes_.empty(); }
 
         private:
@@ -133,10 +142,10 @@
             ~ClassTreeMaskIterator();
 
-            ClassTreeMaskIterator& operator++();
+            const ClassTreeMaskIterator& operator++();
             ClassTreeMaskNode* operator*() const;
             ClassTreeMaskNode* operator->() const;
-            operator bool();
-            bool operator==(ClassTreeMaskNode* compare);
-            bool operator!=(ClassTreeMaskNode* compare);
+            operator bool() const;
+            bool operator==(ClassTreeMaskNode* compare) const;
+            bool operator!=(ClassTreeMaskNode* compare) const;
 
         private:
@@ -159,4 +168,6 @@
     class _CoreExport ClassTreeMask
     {
+        friend class ClassTreeMaskObjectIterator;
+
         public:
             ClassTreeMask();
@@ -178,10 +189,15 @@
             bool isExcluded(const Identifier* subclass) const;
 
-            ClassTreeMask& operator=(const ClassTreeMask& other);
+            /** @brief Begin of the ClassTreeMaskObjectIterator. */
+            inline const ClassTreeMask& begin() const { return (*this); }
+            /** @brief End of the ClassTreeMaskObjectIterator. */
+            inline BaseObject*          end()   const { return 0; }
+
+            const ClassTreeMask& operator=(const ClassTreeMask& other);
 
             bool operator==(const ClassTreeMask& other) const;
             bool operator!=(const ClassTreeMask& other) const;
 
-            ClassTreeMask& operator+();
+            const ClassTreeMask& operator+() const;
             ClassTreeMask operator-() const;
 
@@ -191,7 +207,7 @@
             ClassTreeMask operator!() const;
 
-            ClassTreeMask& operator+=(const ClassTreeMask& other);
-            ClassTreeMask& operator*=(const ClassTreeMask& other);
-            ClassTreeMask& operator-=(const ClassTreeMask& other);
+            const ClassTreeMask& operator+=(const ClassTreeMask& other);
+            const ClassTreeMask& operator*=(const ClassTreeMask& other);
+            const ClassTreeMask& operator-=(const ClassTreeMask& other);
 
             ClassTreeMask operator&(const ClassTreeMask& other) const;
@@ -200,7 +216,7 @@
             ClassTreeMask operator~() const;
 
-            ClassTreeMask& operator&=(const ClassTreeMask& other);
-            ClassTreeMask& operator|=(const ClassTreeMask& other);
-            ClassTreeMask& operator^=(const ClassTreeMask& other);
+            const ClassTreeMask& operator&=(const ClassTreeMask& other);
+            const ClassTreeMask& operator|=(const ClassTreeMask& other);
+            const ClassTreeMask& operator^=(const ClassTreeMask& other);
 
             friend std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask);
@@ -219,10 +235,50 @@
     // ### ClassTreeMaskObjectIterator ###
     // ###################################
-    //! ...
-    /**
-        ...
+    //! The ClassTreeMaskObjectIterator iterates through all objects of all classes, included by a ClassTreeMask.
+    /**
+        The ClassTreeMaskObjectIterator iterates through all objects of all classes,
+        included by a ClassTreeMask. This is done the following way:
+
+        ClassTreeMask mask;
+        for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it)
+            it->doSomething();
+
+        Note: The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If
+              you want to use another class, you should use a dynamic_cast.
+
+        Performance of ClassTreeMaskObjectIterator is good as long as you don't exclude
+        subclasses of included classes. Of course you can still exlucde subclasses, but
+        if this is done more often, we need a new implementation using a second ObjectList
+        in the Identifier, containing all objects of exactly one class.
     */
     class _CoreExport ClassTreeMaskObjectIterator
     {
+        public:
+            /** @brief Defaultconstructor: Does nothing. */
+            inline ClassTreeMaskObjectIterator() {}
+            /** @brief Constructor: Initializes the iterator from a given ClassTreeMask. @param mask The mask */
+            inline ClassTreeMaskObjectIterator(const ClassTreeMask& mask) { (*this) = mask; }
+
+            const ClassTreeMaskObjectIterator& operator=(const ClassTreeMask& mask);
+
+            const ClassTreeMaskObjectIterator& operator++();
+
+            /** @brief Returns true if the ClassTreeMaskObjectIterator points at the given object. @param pointer The pointer of the object */
+            inline bool operator==(BaseObject* pointer) const { return ((*this->objectIterator_) == pointer); }
+            /** @brief Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. @param pointer The pointer of the object */
+            inline bool operator!=(BaseObject* pointer) const { return ((*this->objectIterator_) != pointer); }
+            /** @brief Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. */
+            inline operator bool() const { return (this->objectIterator_); }
+            /** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */
+            inline BaseObject* operator*() const { return (*this->objectIterator_); }
+            /** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */
+            inline BaseObject* operator->() const { return (*this->objectIterator_); }
+
+        private:
+            void create(ClassTreeMaskNode* node);
+
+            std::list<std::pair<const Identifier*, bool> >           subclasses_;       //!< A list of all Identifiers through which objects the iterator should iterate
+            std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; //!< The current class of the iterator
+            Iterator<BaseObject>                                     objectIterator_;   //!< The current object of the iterator
     };
 }
Index: code/trunk/src/core/CorePrereqs.h
===================================================================
--- code/trunk/src/core/CorePrereqs.h	(revision 1756)
+++ code/trunk/src/core/CorePrereqs.h	(revision 1757)
@@ -98,4 +98,5 @@
   class ClassTreeMaskIterator;
   class ClassTreeMaskNode;
+  class ClassTreeMaskObjectIterator;
   class Clock;
   class CommandEvaluation;
