Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 3:54:49 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/lib/util/list.h

    r3605 r3746  
    4646};
    4747
    48 class Iterator
    49 {
    50 
     48
     49
     50template<class T> struct listElement
     51{
     52  listElement* prev;
     53  T* curr;
     54  listElement* next;
     55};
     56
     57template<class T> class tIterator
     58{
    5159 public:
    52   bool hasNext();
    53   WorldEntity* next();
     60  tIterator(listElement<T>* startElement);
     61  ~tIterator();
     62 
     63  T* nextElement();
    5464
    5565 private:
    56 
    57 };
     66  listElement<T>* currentEl;
     67  listElement<T>* tmpEl;
     68};
     69
     70
     71template<class T>
     72inline tIterator<T>::tIterator (listElement<T>* startElement)
     73{
     74  this->currentEl = startElement;
     75  this->tmpEl = NULL;
     76}
     77
     78
     79template<class T>
     80tIterator<T>::~tIterator ()
     81{
     82  this->currentEl = NULL;
     83}
     84
     85
     86template<class T>
     87inline T* tIterator<T>::nextElement ()
     88{
     89  if( this->currentEl == NULL)
     90    return NULL;
     91
     92  this->tmpEl = this->currentEl;
     93  this->currentEl = this->currentEl->next;
     94  return this->tmpEl->curr;
     95}
     96
    5897
    5998
    6099template<class T> class tList
    61100{
    62  private:
    63   struct listElement
    64   {
    65     listElement* prev;
    66     T* curr;
    67     listElement* next;
    68   };
    69 
    70   Uint32 size;
    71   listElement* first;
    72   listElement* last;
    73   listElement* currentEl;
    74  
    75101 public:
    76102  tList ();
    77103  ~tList ();
    78  
    79104
    80105  void add(T* entity);
     
    85110  int getSize();
    86111  T* enumerate();
     112  tIterator<T>* getIterator();
    87113  T* nextElement();
    88114  T* nextElement(T* toEntity);
    89115  T* toArray();
    90116  void debug();
     117
     118 private:
     119  Uint32 size;
     120  listElement<T>* first;
     121  listElement<T>* last;
     122  listElement<T>* currentEl;
    91123};
    92124
     
    106138  while(this->currentEl != NULL)
    107139    {
    108       listElement* le = this->currentEl->next;
     140      listElement<T>* le = this->currentEl->next;
    109141      //delete this->currentEl->curr;
    110142      delete this->currentEl;
     
    118150
    119151template<class T>
    120 void tList<T>::add(T* entity)
     152inline void tList<T>::add(T* entity)
    121153{
    122154  if( entity == NULL) return;
    123   listElement* el = new listElement;
     155  listElement<T>* el = new listElement<T>;
    124156  el->prev = this->last;
    125157  el->curr = entity;
     
    135167
    136168template<class T>
    137 void tList<T>::remove(T* entity)
     169inline void tList<T>::remove(T* entity)
    138170{
    139171  if( entity == NULL) return;
    140172  this->currentEl = this->first;
    141   listElement* te;
     173  listElement<T>* te;
    142174  while( this->currentEl != NULL)
    143175    {
     
    150182          else this->currentEl->next->prev = this->currentEl->prev;
    151183
    152           te = this->currentEl->next;  // for what am i doing this?
     184          //te = this->currentEl->next;  // for what am i doing this?
    153185          delete this->currentEl;
    154           this->currentEl = te;
     186          //this->currentEl = te;
     187          this->currentEl = NULL;
    155188          this->size--;
    156189          return;
     
    167200  while(this->currentEl != NULL)
    168201    {
    169       listElement* le = this->currentEl->next;
     202      listElement<T>* le = this->currentEl->next;
    170203      //delete this->currentEl->curr;
    171204      delete this->currentEl;
     
    203236{
    204237  //if( this->last == this->first == NULL) return NULL;
    205   if(this->size == 0) return NULL;
     238  if( this->size == 0) return NULL;
    206239  this->currentEl = this->first;
    207240  return this->currentEl->curr;
     
    210243
    211244template<class T>
     245inline tIterator<T>* tList<T>::getIterator()
     246{
     247  tIterator<T>* iterator = new tIterator<T>(this->first);
     248  return iterator;
     249}
     250
     251
     252template<class T>
    212253T* tList<T>::nextElement()
    213254{
    214255  // if( this->last == this->first == NULL) return NULL;
    215   if(this->size == 0) return NULL;
     256  if( this->size == 0) return NULL;
    216257  this->currentEl = this->currentEl->next;
    217   if(this->currentEl == NULL) return NULL;
     258  if( this->currentEl == NULL) return NULL;
    218259  return this->currentEl->curr;
    219260}
Note: See TracChangeset for help on using the changeset viewer.