Changeset 1063 for code/trunk/src/core/ObjectList.h
- Timestamp:
- Apr 14, 2008, 6:23:52 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/ObjectList.h
r1062 r1063 38 38 #ifndef _ObjectList_H__ 39 39 #define _ObjectList_H__ 40 41 #include <set> 40 42 41 43 #include "CorePrereqs.h" … … 90 92 91 93 ObjectListElement<T>* add(T* object); 92 // void remove(OrxonoxClass* object, bool bIterateForwards = true);93 94 94 95 /** @brief Returns the first element in the list. @return The first element */ … … 104 105 { return Iterator<T>(ClassManager<T>::getIdentifier()->getObjects()->last_); } 105 106 107 inline void registerIterator(Iterator<T>* iterator) 108 { this->iterators_.insert(this->iterators_.end(), (void*)iterator); } 109 inline void unregisterIterator(Iterator<T>* iterator) 110 { this->iterators_.erase((void*)iterator); } 111 void notifyIterators(ObjectListElement<T>* element); 112 106 113 ObjectListElement<T>* first_; //!< The first element in the list 107 114 ObjectListElement<T>* last_; //!< The last element in the list 115 116 private: 117 std::set<void*> iterators_; //!< A list of iterators pointing on an element in this list 108 118 }; 109 119 … … 134 144 135 145 /** 146 @brief Increases all Iterators that currently point on the given element (because it gets removed). 147 @param element The element that gets removed 148 */ 149 template <class T> 150 void ObjectList<T>::notifyIterators(ObjectListElement<T>* element) 151 { 152 for (std::set<void*>::iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it) 153 if ((*(*((Iterator<T>*)(*it)))) == element->object_) 154 ++(*((Iterator<T>*)(*it))); 155 } 156 157 /** 136 158 @brief Adds a new object to the end of the list. 137 159 @param object The object to add … … 158 180 return this->last_; 159 181 } 160 161 162 // /**163 // @brief Removes an object from the list.164 // @param object The object to remove165 // @param bIterateForwards If true: Start searching the object at the beginning of the list166 // */167 /*168 template <class T>169 void ObjectList<T>::remove(OrxonoxClass* object, bool bIterateForwards)170 {171 if (!object || !this->first_ || !this->last_)172 return;173 174 // If there's only one object in the list, we have to set first_ and last_ to zero175 if (this->first_ == this->last_)176 {177 if (this->first_->object_ == object)178 {179 delete this->first_;180 this->first_ = 0;181 this->last_ = 0;182 }183 184 return;185 }186 187 // Now we are sure we have more than one element in the list188 if (bIterateForwards)189 {190 // Start at the beginning of the list191 192 // Check if it's the first object193 if (this->first_->object_ == object)194 {195 ObjectListElement<T>* temp = this->first_->next_;196 delete this->first_;197 this->first_ = temp;198 this->first_->prev_ = 0;199 200 return;201 }202 203 // Iterate through the whole list204 ObjectListElement<T>* temp = this->first_;205 while (temp->next_)206 {207 if (temp->next_->object_ == object)208 {209 ObjectListElement<T>* temp2 = temp->next_->next_;210 delete temp->next_;211 temp->next_ = temp2;212 if (temp2)213 temp2->prev_ = temp;214 else215 this->last_ = temp; // If there is no next_, we deleted the last element and have to update the last_ pointer.216 217 return;218 }219 220 temp = temp->next_;221 }222 }223 else224 {225 // Start at the end of the list226 227 // Check if it's the last object228 if (this->last_->object_ == object)229 {230 ObjectListElement<T>* temp = this->last_->prev_;231 delete this->last_;232 this->last_ = temp;233 this->last_->next_ = 0;234 235 return;236 }237 238 // Iterate through the whole list239 ObjectListElement<T>* temp = this->last_;240 while (temp->prev_)241 {242 if (temp->prev_->object_ == object)243 {244 ObjectListElement<T>* temp2 = temp->prev_->prev_;245 delete temp->prev_;246 temp->prev_ = temp2;247 if (temp2)248 temp2->next_ = temp;249 else250 this->first_ = temp; // If there is no prev_, we deleted the first element and have to update the first_ pointer.251 252 return;253 }254 255 temp = temp->prev_;256 }257 }258 }259 */260 182 } 261 183
Note: See TracChangeset
for help on using the changeset viewer.