Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.