Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 25, 2009, 12:54:12 AM (15 years ago)
Author:
landauf
Message:

Removed end-iterator-safety from Iterator and ObjectListIterator. This means, when you reach end(), don't use *it anymore (this returned 0 in the past, now you'll get a segfault).
Changed ClassTreeMask and Radar accordingly.

Also, please always use "for (…) { (it++)→function() }" instead of "for (…; ++it) { it→function() }" if there's a chance function() destroys the object pointed by the iterator. Our objectlists are deletionsafe, but you'll encounter strange problems like overleaped elements and run-over-end() situations if you use the second pattern and don't doublecheck the iterator in the loop.
Changed GSRoot accordingly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/Iterator.h

    r5738 r5785  
    167167
    168168                return (*this);
    169                 return *this;
    170169            }
    171170
     
    193192            inline const Iterator<T>& operator++()
    194193            {
    195                 if (this->element_)
    196                     this->element_ = this->element_->next_;
     194                this->element_ = this->element_->next_;
    197195                return *this;
    198196            }
     
    205203            {
    206204                Iterator<T> copy = *this;
    207                 if (this->element_)
    208                     this->element_ = this->element_->next_;
     205                this->element_ = this->element_->next_;
    209206                return copy;
    210207            }
     
    216213            inline const Iterator<T>& operator--()
    217214            {
    218                 if (this->element_)
    219                     this->element_ = this->element_->prev_;
     215                this->element_ = this->element_->prev_;
    220216                return *this;
    221217            }
     
    228224            {
    229225                Iterator<T> copy = *this;
    230                 if (this->element_)
    231                     this->element_ = this->element_->prev_;
     226                this->element_ = this->element_->prev_;
    232227                return copy;
    233228            }
     
    239234            inline T* operator*() const
    240235            {
    241                 if (this->element_)
    242                     return orxonox_cast<T*>(this->element_->objectBase_);
    243                 else
    244                     return 0;
     236                return orxonox_cast<T*>(this->element_->objectBase_);
    245237            }
    246238
     
    251243            inline T* operator->() const
    252244            {
    253                 if (this->element_)
    254                     return orxonox_cast<T*>(this->element_->objectBase_);
    255                 else
    256                     return 0;
     245                return orxonox_cast<T*>(this->element_->objectBase_);
    257246            }
    258247
Note: See TracChangeset for help on using the changeset viewer.