Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 10, 2008, 2:30:36 AM (16 years ago)
Author:
landauf
Message:

added ClassTreeMaskObjectIterator
this iterator iterates through all objects of all classes, included by a given ClassTreeMask.

Note: The ClassTreeMaskObjectIterator is fast if you only include classes. If you exclude a subclass of an included class, the performance is not that good.
If we'll use this more often, we have to think about a new implementation, using a second ObjectList with all objects of exactly one class.

Additionally, there is a small change in MultiType.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/ClassTreeMask.h

    r1755 r1757  
    7676#include <stack>
    7777
     78#include "Iterator.h"
     79
    7880namespace orxonox
    7981{
     
    9193        friend class ClassTreeMask;
    9294        friend class ClassTreeMaskIterator;
     95        friend class ClassTreeMaskObjectIterator;
    9396
    9497        public:
     
    102105            void addSubnode(ClassTreeMaskNode* subnode);
    103106
    104             bool isIncluded() const;
    105             bool isExcluded() const;
    106 
    107             const Identifier* getClass() const;
     107            /** @brief Tells if the rule is "included" or not. @return The rule: true = included, false = excluded */
     108            inline bool isIncluded() const { return this->bIncluded_; }
     109            /** @brief Tells if the rule is "excluded" or not. @return The inverted rule: true = excluded, false = included */
     110            inline bool isExcluded() const { return (!this->bIncluded_); }
     111
     112            /** @brief Returns the Identifier of the class the rule refers to. @return The Identifier representing the class */
     113            inline const Identifier* getClass() const { return this->subclass_; }
     114
     115            /** @brief Returns true if the Node has some subnodes. */
     116            inline bool hasSubnodes() const { return !this->subnodes_.empty(); }
    108117
    109118        private:
     
    133142            ~ClassTreeMaskIterator();
    134143
    135             ClassTreeMaskIterator& operator++();
     144            const ClassTreeMaskIterator& operator++();
    136145            ClassTreeMaskNode* operator*() const;
    137146            ClassTreeMaskNode* operator->() const;
    138             operator bool();
    139             bool operator==(ClassTreeMaskNode* compare);
    140             bool operator!=(ClassTreeMaskNode* compare);
     147            operator bool() const;
     148            bool operator==(ClassTreeMaskNode* compare) const;
     149            bool operator!=(ClassTreeMaskNode* compare) const;
    141150
    142151        private:
     
    159168    class _CoreExport ClassTreeMask
    160169    {
     170        friend class ClassTreeMaskObjectIterator;
     171
    161172        public:
    162173            ClassTreeMask();
     
    178189            bool isExcluded(const Identifier* subclass) const;
    179190
    180             ClassTreeMask& operator=(const ClassTreeMask& other);
     191            /** @brief Begin of the ClassTreeMaskObjectIterator. */
     192            inline const ClassTreeMask& begin() const { return (*this); }
     193            /** @brief End of the ClassTreeMaskObjectIterator. */
     194            inline BaseObject*          end()   const { return 0; }
     195
     196            const ClassTreeMask& operator=(const ClassTreeMask& other);
    181197
    182198            bool operator==(const ClassTreeMask& other) const;
    183199            bool operator!=(const ClassTreeMask& other) const;
    184200
    185             ClassTreeMask& operator+();
     201            const ClassTreeMask& operator+() const;
    186202            ClassTreeMask operator-() const;
    187203
     
    191207            ClassTreeMask operator!() const;
    192208
    193             ClassTreeMask& operator+=(const ClassTreeMask& other);
    194             ClassTreeMask& operator*=(const ClassTreeMask& other);
    195             ClassTreeMask& operator-=(const ClassTreeMask& other);
     209            const ClassTreeMask& operator+=(const ClassTreeMask& other);
     210            const ClassTreeMask& operator*=(const ClassTreeMask& other);
     211            const ClassTreeMask& operator-=(const ClassTreeMask& other);
    196212
    197213            ClassTreeMask operator&(const ClassTreeMask& other) const;
     
    200216            ClassTreeMask operator~() const;
    201217
    202             ClassTreeMask& operator&=(const ClassTreeMask& other);
    203             ClassTreeMask& operator|=(const ClassTreeMask& other);
    204             ClassTreeMask& operator^=(const ClassTreeMask& other);
     218            const ClassTreeMask& operator&=(const ClassTreeMask& other);
     219            const ClassTreeMask& operator|=(const ClassTreeMask& other);
     220            const ClassTreeMask& operator^=(const ClassTreeMask& other);
    205221
    206222            friend std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask);
     
    219235    // ### ClassTreeMaskObjectIterator ###
    220236    // ###################################
    221     //! ...
    222     /**
    223         ...
     237    //! The ClassTreeMaskObjectIterator iterates through all objects of all classes, included by a ClassTreeMask.
     238    /**
     239        The ClassTreeMaskObjectIterator iterates through all objects of all classes,
     240        included by a ClassTreeMask. This is done the following way:
     241
     242        ClassTreeMask mask;
     243        for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it)
     244            it->doSomething();
     245
     246        Note: The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If
     247              you want to use another class, you should use a dynamic_cast.
     248
     249        Performance of ClassTreeMaskObjectIterator is good as long as you don't exclude
     250        subclasses of included classes. Of course you can still exlucde subclasses, but
     251        if this is done more often, we need a new implementation using a second ObjectList
     252        in the Identifier, containing all objects of exactly one class.
    224253    */
    225254    class _CoreExport ClassTreeMaskObjectIterator
    226255    {
     256        public:
     257            /** @brief Defaultconstructor: Does nothing. */
     258            inline ClassTreeMaskObjectIterator() {}
     259            /** @brief Constructor: Initializes the iterator from a given ClassTreeMask. @param mask The mask */
     260            inline ClassTreeMaskObjectIterator(const ClassTreeMask& mask) { (*this) = mask; }
     261
     262            const ClassTreeMaskObjectIterator& operator=(const ClassTreeMask& mask);
     263
     264            const ClassTreeMaskObjectIterator& operator++();
     265
     266            /** @brief Returns true if the ClassTreeMaskObjectIterator points at the given object. @param pointer The pointer of the object */
     267            inline bool operator==(BaseObject* pointer) const { return ((*this->objectIterator_) == pointer); }
     268            /** @brief Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. @param pointer The pointer of the object */
     269            inline bool operator!=(BaseObject* pointer) const { return ((*this->objectIterator_) != pointer); }
     270            /** @brief Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. */
     271            inline operator bool() const { return (this->objectIterator_); }
     272            /** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */
     273            inline BaseObject* operator*() const { return (*this->objectIterator_); }
     274            /** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */
     275            inline BaseObject* operator->() const { return (*this->objectIterator_); }
     276
     277        private:
     278            void create(ClassTreeMaskNode* node);
     279
     280            std::list<std::pair<const Identifier*, bool> >           subclasses_;       //!< A list of all Identifiers through which objects the iterator should iterate
     281            std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; //!< The current class of the iterator
     282            Iterator<BaseObject>                                     objectIterator_;   //!< The current object of the iterator
    227283    };
    228284}
Note: See TracChangeset for help on using the changeset viewer.