Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5400 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Oct 18, 2005, 9:32:34 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: a new Function to List.
This gives the ability to remove entities from the end of the List.
This is good, if you have an entity just added, and then deleted right afterwards

Location:
trunk/src/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/render2D/render_2d.cc

    r5399 r5400  
    101101  {
    102102    if (element2D->getLayer() != E2D_LAYER_EXTERN)
    103       this->element2DList[element2D->getLayer()]->remove(element2D);
     103      this->element2DList[element2D->getLayer()]->removeFromLast(element2D);
    104104    if (to != E2D_LAYER_EXTERN)
    105105      this->element2DList[to]->add(element2D);
  • trunk/src/lib/util/list.h

    r5285 r5400  
    3838    void addAtBeginning(T* entity); //!< @todo This should be made with an ENUM
    3939    void remove(const T* entity);
     40    void removeFromLast(const T* entity);
    4041    void removeLast();
    4142    void flush();
     
    159160    }
    160161    this->currentEl = this->currentEl->next;
     162  }
     163}
     164
     165/**
     166 * remove an entity from the list
     167 * @param entity: the entity to be removed
     168 *
     169 * this algorithm starts at the end of the List, working its way to the front
     170 * for finding the right entity.
     171 */
     172template<class T>
     173    inline void tList<T>::removeFromLast(const T* entity)
     174{
     175  this->currentEl = this->last;
     176  while( this->currentEl != NULL)
     177  {
     178    if( unlikely(this->currentEl->curr == entity))
     179    {
     180      // erstes element?
     181      if( unlikely(this->currentEl->prev == NULL)) this->first = this->currentEl->next;
     182      else this->currentEl->prev->next = this->currentEl->next;
     183
     184      // letztes element?
     185      if( unlikely(this->currentEl->next == NULL)) this->last = this->currentEl->prev;
     186      else this->currentEl->next->prev = this->currentEl->prev;
     187
     188      delete this->currentEl;
     189      this->size--;
     190      return;
     191    }
     192    this->currentEl = this->currentEl->prev;
    161193  }
    162194}
Note: See TracChangeset for help on using the changeset viewer.