Changeset 1063 for code/trunk/src/core
- Timestamp:
- Apr 14, 2008, 6:23:52 PM (17 years ago)
- Location:
- code/trunk/src/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/Identifier.h
r1062 r1063 303 303 void setName(const std::string& name); 304 304 /** @brief Returns the list of all existing objects of this class. @return The list */ 305 inline constObjectList<T>* getObjects() const { return this->objects_; }305 inline ObjectList<T>* getObjects() const { return this->objects_; } 306 306 /** @brief Returns a list of all existing objects of this class. @return The list */ 307 inline constObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; }307 inline ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; } 308 308 309 309 void updateConfigValues() const; -
code/trunk/src/core/Iterator.h
r1056 r1063 65 65 { 66 66 this->element_ = 0; 67 ClassManager<T>::getIdentifier()->getObjects()->registerIterator(this); 67 68 } 68 69 … … 74 75 { 75 76 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); 76 86 } 77 87 … … 91 101 Iterator<T> operator++() 92 102 { 93 this->element_ = this->element_->next_; 103 if (this->element_) 104 this->element_ = this->element_->next_; 94 105 return *this; 95 106 } … … 102 113 { 103 114 Iterator<T> copy = *this; 104 this->element_ = this->element_->next_; 115 if (this->element_) 116 this->element_ = this->element_->next_; 105 117 return copy; 106 118 } … … 112 124 Iterator<T> operator--() 113 125 { 114 this->element_ = this->element_->prev_; 126 if (this->element_) 127 this->element_ = this->element_->prev_; 115 128 return *this; 116 129 } … … 123 136 { 124 137 Iterator<T> copy = *this; 125 this->element_ = this->element_->prev_; 138 if (this->element_) 139 this->element_ = this->element_->prev_; 126 140 return copy; 127 141 } … … 133 147 T* operator*() 134 148 { 135 return this->element_->object_; 149 if (this->element_) 150 return this->element_->object_; 151 else 152 return 0; 136 153 } 137 154 … … 142 159 T* operator->() const 143 160 { 144 return this->element_->object_; 161 if (this->element_) 162 return this->element_->object_; 163 else 164 return 0; 145 165 146 166 } -
code/trunk/src/core/MetaObjectList.h
r1056 r1063 89 89 MetaObjectListElement<T>::~MetaObjectListElement() 90 90 { 91 COUT(5) << "*** MetaObjectList: Removing Object from " << ClassManager<T>::getIdentifier()->getName() << "-list." << std::endl; 92 this->list_->notifyIterators(this->element_); 93 91 94 if (this->element_->next_) 92 95 this->element_->next_->prev_ = this->element_->prev_; … … 99 102 this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list 100 103 101 102 COUT(5) << "*** MetaObjectList: Removing Object from " << ClassManager<T>::getIdentifier()->getName() << "-list." << std::endl;103 104 delete this->element_; 104 105 } … … 106 107 107 108 // ############################### 108 // ### ObjectList###109 // ### MetaObjectList ### 109 110 // ############################### 110 111 //! The MetaObjectList contains ObjectListElements and their ObjectLists. -
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.