Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 14, 2008, 6:23:52 PM (16 years ago)
Author:
landauf
Message:

fixed an interesting bug in ObjectList/MetaObjectList/Iterator: it's now possible to delete multiple objects in one function-call while iterating through the objects. (and it would have crashed with std::list as well, so no stupid comments please :D)

added a feature in Timer.cc, allowing timers to tick faster than orxonox. this is from core2-branch but got lost while merging.

File:
1 edited

Legend:

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

    r1056 r1063  
    6565            {
    6666                this->element_ = 0;
     67                ClassManager<T>::getIdentifier()->getObjects()->registerIterator(this);
    6768            }
    6869
     
    7475            {
    7576                this->element_ = element;
     77                ClassManager<T>::getIdentifier()->getObjects()->registerIterator(this);
     78            }
     79
     80            /**
     81                @brief Unregisters the Iterator from the ObjectList.
     82            */
     83            ~Iterator()
     84            {
     85                ClassManager<T>::getIdentifier()->getObjects()->unregisterIterator(this);
    7686            }
    7787
     
    91101            Iterator<T> operator++()
    92102            {
    93                 this->element_ = this->element_->next_;
     103                if (this->element_)
     104                    this->element_ = this->element_->next_;
    94105                return *this;
    95106            }
     
    102113            {
    103114                Iterator<T> copy = *this;
    104                 this->element_ = this->element_->next_;
     115                if (this->element_)
     116                    this->element_ = this->element_->next_;
    105117                return copy;
    106118            }
     
    112124            Iterator<T> operator--()
    113125            {
    114                 this->element_ = this->element_->prev_;
     126                if (this->element_)
     127                    this->element_ = this->element_->prev_;
    115128                return *this;
    116129            }
     
    123136            {
    124137                Iterator<T> copy = *this;
    125                 this->element_ = this->element_->prev_;
     138                if (this->element_)
     139                    this->element_ = this->element_->prev_;
    126140                return copy;
    127141            }
     
    133147            T* operator*()
    134148            {
    135                 return this->element_->object_;
     149                if (this->element_)
     150                    return this->element_->object_;
     151                else
     152                    return 0;
    136153            }
    137154
     
    142159            T* operator->() const
    143160            {
    144                 return this->element_->object_;
     161                if (this->element_)
     162                    return this->element_->object_;
     163                else
     164                    return 0;
    145165
    146166            }
Note: See TracChangeset for help on using the changeset viewer.