Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 807


Ignore:
Timestamp:
Feb 12, 2008, 8:36:19 PM (16 years ago)
Author:
landauf
Message:
  • fixed a small bug in ClassTreeMask
  • added more operators to ClassTreeMask
  • added testing code for ClassTreeMask
Location:
code/branches/core/src/orxonox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core/src/orxonox/Orxonox.cc

    r806 r807  
    764764        #define TestClassTreeMask(mask) \
    765765            std::cout << "========== ClassTreeMask-Test ===========" << std::endl; \
     766            std::cout << mask << std::endl << std::endl; \
    766767            std::cout << "                 "; \
    767768            BoolToYesNo(mask.isIncluded(Class(BaseObject))); \
     
    808809
    809810        ClassTreeMask test13_1;
    810 //        test13_1.include(Class(BaseObject));
    811811        test13_1.exclude(Class(A1B1));
    812812        test13_1.exclude(Class(A2));
     
    817817        test13_1.exclude(Class(A3B2C1));
    818818        test13_1.exclude(Class(A3B2C2));
     819        std::cout << "Mask 1:\n";
     820        TestClassTreeMask(test13_1);
    819821
    820822        ClassTreeMask test13_2;
     
    828830        test13_2.include(Class(A3B2));
    829831        test13_2.exclude(Class(A3B2C2));
    830 
     832        std::cout << std::endl;
     833        std::cout << "Mask 2:\n";
     834        TestClassTreeMask(test13_2);
     835
     836        ClassTreeMask test13_3;
     837        test13_3.include(Class(A1));
     838        test13_3.exclude(Class(A1B2));
     839        test13_3.exclude(Class(A1B1C2));
     840        test13_3.include(Class(A2));
     841        test13_3.exclude(Class(A2B2));
     842        test13_3.include(Class(A3B1));
     843        test13_3.include(Class(A3B2));
     844        test13_3.exclude(Class(A3B2C2));
     845        std::cout << std::endl;
     846        std::cout << "Mask 2 without excluded BaseObject:\n";
     847        TestClassTreeMask(test13_3);
     848        test13_3.exclude(Class(BaseObject));
     849        std::cout << std::endl;
     850        std::cout << "Mask 2 with BaseObject excluded afterwards:\n";
     851        TestClassTreeMask(test13_3);
     852
     853        ClassTreeMask test13_3_2;
     854        test13_3_2.include(Class(A1));
     855        test13_3_2.exclude(Class(A1B2));
     856        test13_3_2.exclude(Class(A1B1C2));
     857        test13_3_2.include(Class(A2));
     858        test13_3_2.exclude(Class(A2B2));
     859        test13_3_2.include(Class(A3B1));
     860        test13_3_2.include(Class(A3B2));
     861        test13_3_2.exclude(Class(A3B2C2));
     862        test13_3_2.clean();
     863        test13_3_2.exclude(Class(BaseObject));
     864        std::cout << std::endl;
     865        std::cout << "Mask 2 with BaseObject excluded afterwards, but cleaned before:\n";
     866        TestClassTreeMask(test13_3_2);
     867        test13_3_2.include(Class(BaseObject));
     868        std::cout << std::endl;
     869        std::cout << "Mask 2 from before, but BaseObject re-included without cleaning:\n";
     870        TestClassTreeMask(test13_3_2);
     871
     872        ClassTreeMask test13_4;
     873        test13_4.include(Class(A3B2));
     874        test13_4.exclude(Class(A1B1C2));
     875        test13_4.include(Class(A3B1));
     876        test13_4.exclude(Class(A3B2C2));
     877        test13_4.exclude(Class(BaseObject));
     878        test13_4.include(Class(A2));
     879        test13_4.exclude(Class(A1B2));
     880        test13_4.exclude(Class(A2B2));
     881        test13_4.include(Class(A1));
     882        std::cout << std::endl;
     883        std::cout << "Mask 2 created in random order:\n";
     884        TestClassTreeMask(test13_4);
     885
     886        std::cout << "2\n";
     887
     888        ClassTreeMask test13_5 = test13_1;
     889        std::cout << std::endl;
     890        std::cout << "Mask 1 assigned to a new ClassTestMask:\n";
     891        TestClassTreeMask(test13_5);
     892
     893        std::cout << "3\n";
     894
     895        ClassTreeMask test13_6 = !test13_1;
     896        std::cout << std::endl;
     897        std::cout << "Mask 1 inverted:\n";
     898        TestClassTreeMask(test13_6);
     899
     900        std::cout << "4\n";
     901
     902        ClassTreeMask test13_7 = test13_1 + test13_2;
     903        std::cout << std::endl;
     904        std::cout << "Mask 1 + Mask 2:\n";
     905        TestClassTreeMask(test13_7);
     906
     907        std::cout << "5\n";
     908
     909        ClassTreeMask test13_8 = test13_1 * test13_2;
     910        std::cout << std::endl;
     911        std::cout << "Mask 1 * Mask 2:\n";
     912        TestClassTreeMask(test13_8);
     913
     914        std::cout << "6\n";
     915
     916        ClassTreeMask test13_9 = test13_1 - test13_2;
     917        std::cout << std::endl;
     918        std::cout << "Mask 1 - Mask 2:\n";
     919        TestClassTreeMask(test13_9);
     920
     921        std::cout << "7\n";
     922
     923        ClassTreeMask test13_10 = test13_1 ^ test13_2;
     924        std::cout << std::endl;
     925        std::cout << "Mask 1 ^ Mask 2:\n";
     926        TestClassTreeMask(test13_10);
     927        test13_10 = test13_10;
     928        TestClassTreeMask(test13_10);
     929
     930        std::cout << "8\n";
     931
     932        std::cout << std::endl;
     933        ClassTreeMask test13_11(test13_1);
     934        std::cout << std::endl;
     935        std::cout << "Mask 1 assigned with copyconstructor + original mask 1:\n";
     936        TestClassTreeMask(test13_11);
    831937        TestClassTreeMask(test13_1);
     938
     939        ClassTreeMask test13_12(!test13_11);
     940        std::cout << std::endl;
     941        std::cout << "Mask 1 inverted assigned with copyconstructor + the original from before:\n";
     942        TestClassTreeMask(test13_12);
     943        TestClassTreeMask(test13_11);
     944
     945        ClassTreeMask test13_13;
     946        test13_13 = test13_2;
     947        std::cout << std::endl;
     948        std::cout << "Mask 2 assigned with = operator + original mask 2:\n";
     949        TestClassTreeMask(test13_13);
    832950        TestClassTreeMask(test13_2);
    833951
    834         std::cout << "2\n";
    835 
    836         std::cout << "3\n";
     952        ClassTreeMask test13_14 = test13_11 + test13_13;
     953        std::cout << std::endl;
     954        std::cout << "Mask 1 + Mask 2 assigned with copyconstructor + originals from before:\n";
     955        TestClassTreeMask(test13_14);
     956        TestClassTreeMask(test13_11);
     957        TestClassTreeMask(test13_13);
     958
     959        test13_11 += test13_13;
     960        std::cout << std::endl;
     961        std::cout << "Mask 1 + Mask 2 with += operator + original of mask 2 from before:\n";
     962        TestClassTreeMask(test13_11);
     963        TestClassTreeMask(test13_13);
     964
     965        std::cout << "9\n";
    837966
    838967//    startRenderLoop();
  • code/branches/core/src/orxonox/core/ClassTreeMask.cc

    r806 r807  
    8888    ClassTreeMaskIterator::ClassTreeMaskIterator(ClassTreeMaskNode* node)
    8989    {
    90         std::list<ClassTreeMaskNode*> templist;
    91         std::list<ClassTreeMaskNode*>::iterator tempiterator = templist.insert(templist.end(), node);
    92         this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(tempiterator, templist.end()));
     90        std::list<ClassTreeMaskNode*>::iterator it = this->rootlist_.insert(this->rootlist_.end(), node);
     91        this->nodes_.push(std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator>(it, this->rootlist_.end()));
    9392    }
    9493
     
    157156    {
    158157        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true);
     158    }
     159
     160    ClassTreeMask::ClassTreeMask(const ClassTreeMask& other)
     161    {
     162        this->root_ = new ClassTreeMaskNode(ClassManager<BaseObject>::getIdentifier("BaseObject"), true);
     163        for (ClassTreeMaskIterator it = other.root_; it; ++it)
     164            this->add(it->getClass(), it->isIncluded());
    159165    }
    160166
     
    241247        if (subclass->isA(node->getClass()))
    242248        {
    243 //std::cout << "1_2\n";
    244249            // Check for the special case
    245250            if (subclass == node->getClass())
    246             {
    247 //std::cout << "1_3\n";
    248251                return node->isIncluded();
    249             }
    250 
    251 //std::cout << "1_4\n";
     252
    252253            // Go through the list of subnodes and look for a node containing the searched subclass
    253254            for (std::list<ClassTreeMaskNode*>::iterator it = node->subnodes_.begin(); it != node->subnodes_.end(); ++it)
     
    255256                    return isIncluded(*it, subclass);
    256257
    257 //std::cout << "1_5\n";
    258258            // There is no subnode containing our class -> the rule of the current node takes in effect
    259259            return node->isIncluded();
     
    261261        else
    262262        {
    263 //std::cout << "1_6\n";
    264263            // The class is not included in the mask: return false
    265264            return false;
     
    285284                node->subnodes_.insert(node->subnodes_.end(), (*it)->subnodes_.begin(), (*it)->subnodes_.end());
    286285                (*it)->subnodes_.clear();
    287                 node->subnodes_.erase(it++);
     286                node->subnodes_.erase(it);
     287                it = node->subnodes_.begin();
    288288            }
    289289            else
     
    294294    }
    295295
     296    ClassTreeMask& ClassTreeMask::operator=(const ClassTreeMask& other)
     297    {
     298        ClassTreeMask temp(other);
     299
     300        this->reset();
     301
     302        for (ClassTreeMaskIterator it = temp.root_; it; ++it)
     303            this->add(it->getClass(), it->isIncluded());
     304
     305        return (*this);
     306    }
     307
     308    ClassTreeMask& ClassTreeMask::operator+()
     309    {
     310        return (*this);
     311    }
     312
     313    ClassTreeMask ClassTreeMask::operator-() const
     314    {
     315        return (!(*this));
     316    }
     317
    296318    ClassTreeMask ClassTreeMask::operator+(const ClassTreeMask& other) const
    297319    {
     
    330352    }
    331353
     354    ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const
     355    {
     356        return ((*this) * (!other));
     357    }
     358
    332359    ClassTreeMask ClassTreeMask::operator!() const
    333360    {
     
    338365            newmask.add(subclass, !this->isIncluded(subclass));
    339366        }
    340 
    341367        return newmask;
    342368    }
    343369
    344     ClassTreeMask ClassTreeMask::operator-(const ClassTreeMask& other) const
    345     {
    346         return ((*this) * (!other));
     370    ClassTreeMask& ClassTreeMask::operator+=(const ClassTreeMask& other)
     371    {
     372        (*this) = (*this) + other;
     373        return (*this);
     374    }
     375
     376    ClassTreeMask& ClassTreeMask::operator*=(const ClassTreeMask& other)
     377    {
     378        (*this) = (*this) * other;
     379        return (*this);
     380    }
     381
     382    ClassTreeMask& ClassTreeMask::operator-=(const ClassTreeMask& other)
     383    {
     384        (*this) = (*this) - other;
     385        return (*this);
    347386    }
    348387
     
    379418        return (!(*this));
    380419    }
     420
     421    ClassTreeMask& ClassTreeMask::operator&=(const ClassTreeMask& other)
     422    {
     423        (*this) = (*this) & other;
     424        return (*this);
     425    }
     426
     427    ClassTreeMask& ClassTreeMask::operator|=(const ClassTreeMask& other)
     428    {
     429        (*this) = (*this) | other;
     430        return (*this);
     431    }
     432
     433    ClassTreeMask& ClassTreeMask::operator^=(const ClassTreeMask& other)
     434    {
     435        (*this) = (*this) ^ other;
     436        return (*this);
     437    }
     438
     439    std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask)
     440    {
     441        for (ClassTreeMaskIterator it = mask.root_; it; ++it)
     442        {
     443            if (it->isIncluded())
     444                out << "+";
     445            else
     446                out << "-";
     447
     448            out << it->getClass()->getName() << " ";
     449        }
     450
     451        return out;
     452    }
    381453}
  • code/branches/core/src/orxonox/core/ClassTreeMask.h

    r803 r807  
    7777        private:
    7878            std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_;
     79            std::list<ClassTreeMaskNode*> rootlist_;
    7980    };
    8081
     
    8384        public:
    8485            ClassTreeMask();
     86            ClassTreeMask(const ClassTreeMask& other);
    8587            ~ClassTreeMask();
    8688
     
    9496            bool isExcluded(const Identifier* subclass) const;
    9597
     98            ClassTreeMask& operator=(const ClassTreeMask& other);
     99
     100            ClassTreeMask& operator+();
     101            ClassTreeMask operator-() const;
     102
    96103            ClassTreeMask operator+(const ClassTreeMask& other) const;
    97104            ClassTreeMask operator*(const ClassTreeMask& other) const;
     105            ClassTreeMask operator-(const ClassTreeMask& other) const;
    98106            ClassTreeMask operator!() const;
    99             ClassTreeMask operator-(const ClassTreeMask& other) const;
     107
     108            ClassTreeMask& operator+=(const ClassTreeMask& other);
     109            ClassTreeMask& operator*=(const ClassTreeMask& other);
     110            ClassTreeMask& operator-=(const ClassTreeMask& other);
    100111
    101112            ClassTreeMask operator&(const ClassTreeMask& other) const;
     
    103114            ClassTreeMask operator^(const ClassTreeMask& other) const;
    104115            ClassTreeMask operator~() const;
     116
     117            ClassTreeMask& operator&=(const ClassTreeMask& other);
     118            ClassTreeMask& operator|=(const ClassTreeMask& other);
     119            ClassTreeMask& operator^=(const ClassTreeMask& other);
     120
     121            friend std::ostream& operator<<(std::ostream& out, const ClassTreeMask& mask);
    105122
    106123        private:
Note: See TracChangeset for help on using the changeset viewer.