Changeset 3605 in orxonox.OLD for orxonox/branches/levelloader/src/lib/util
- Timestamp:
- Mar 18, 2005, 11:52:15 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/lib/util/list.h
r3499 r3605 86 86 T* enumerate(); 87 87 T* nextElement(); 88 T* nextElement(T* toEntity); 88 89 T* toArray(); 89 90 void debug(); … … 101 102 template<class T> 102 103 tList<T>::~tList () 103 {} 104 { 105 this->currentEl = this->first; 106 while(this->currentEl != NULL) 107 { 108 listElement* le = this->currentEl->next; 109 //delete this->currentEl->curr; 110 delete this->currentEl; 111 this->currentEl = le; 112 } 113 this->first = NULL; 114 this->last = NULL; 115 this->size = 0; 116 } 117 104 118 105 119 template<class T> 106 120 void tList<T>::add(T* entity) 107 121 { 122 if( entity == NULL) return; 108 123 listElement* el = new listElement; 109 124 el->prev = this->last; … … 113 128 this->last = el; 114 129 115 if( this->size == 0) this->first = el;130 if(el->prev == NULL) this->first = el; /* if first element */ 116 131 else el->prev->next = el; 117 132 this->size++; … … 122 137 void tList<T>::remove(T* entity) 123 138 { 139 if( entity == NULL) return; 124 140 this->currentEl = this->first; 125 141 listElement* te; … … 134 150 else this->currentEl->next->prev = this->currentEl->prev; 135 151 136 te = this->currentEl->next; 152 te = this->currentEl->next; // for what am i doing this? 137 153 delete this->currentEl; 138 154 this->currentEl = te; 155 this->size--; 139 156 return; 140 157 } … … 151 168 { 152 169 listElement* le = this->currentEl->next; 153 delete this->currentEl->curr;170 //delete this->currentEl->curr; 154 171 delete this->currentEl; 155 172 this->currentEl = le; … … 185 202 T* tList<T>::enumerate() 186 203 { 204 //if( this->last == this->first == NULL) return NULL; 187 205 if(this->size == 0) return NULL; 188 206 this->currentEl = this->first; … … 194 212 T* tList<T>::nextElement() 195 213 { 214 // if( this->last == this->first == NULL) return NULL; 196 215 if(this->size == 0) return NULL; 197 216 this->currentEl = this->currentEl->next; … … 201 220 202 221 222 /** 223 \brief this returns the next element after toEntity or the first if toEntity is last 224 */ 225 template<class T> 226 T* tList<T>::nextElement(T* toEntity) 227 { 228 //if( this->last == this->first == NULL) return NULL; 229 if(this->size == 0) return NULL; 230 if( toEntity == NULL) return this->first->curr; 231 if( toEntity == this->last->curr ) return this->first->curr; 232 this->currentEl = this->first; 233 while(this->currentEl->curr != toEntity && this->currentEl->next != NULL) 234 { 235 this->currentEl = this->currentEl->next; 236 } 237 if(this->currentEl == NULL) return NULL; 238 return this->currentEl->next->curr; 239 } 240 241 203 242 template<class T> 204 243 T* tList<T>::toArray()
Note: See TracChangeset
for help on using the changeset viewer.