Changeset 9667 for code/trunk/src/libraries/core/object/ObjectListBase.cc
- Timestamp:
- Aug 25, 2013, 9:08:42 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core6 merged: 9552-9554,9556-9574,9577-9579,9585-9593,9596-9612,9626-9662
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/object/ObjectListBase.cc
r9593 r9667 41 41 namespace orxonox 42 42 { 43 // ############################### 44 // ### ObjectListBaseElement ### 45 // ############################### 46 void ObjectListBaseElement::removeFromList() 47 { 48 if (this->list_) 49 this->list_->removeElement(this); 50 } 51 52 // ############################### 53 // ### ObjectListBase ### 54 // ############################### 43 55 /** 44 56 @brief Constructor: Sets default values. … … 48 60 this->first_ = 0; 49 61 this->last_ = 0; 62 this->size_ = 0; 50 63 } 51 64 … … 55 68 ObjectListBase::~ObjectListBase() 56 69 { 57 ObjectListBaseElement* temp;58 while ( this->first_)70 ObjectListBaseElement* current = this->first_; 71 while (current) 59 72 { 60 temp = this->first_->next_; 61 delete this->first_; 62 this->first_ = temp; 73 ObjectListBaseElement* next = current->next_; 74 75 current->list_ = 0; 76 current->next_ = 0; 77 current->prev_ = 0; 78 79 current = next; 63 80 } 64 81 } 65 82 66 83 /** 67 @brief Increases all Iterators that currently point on the given element (because it gets removed). 68 @param object The object that gets removed 84 @brief Notifies all listeners that the given element is about to get removed. 85 @param element The element that gets removed 86 This is mainly used for iterators which point at the removed element 69 87 */ 70 void ObjectListBase::notify Iterators(Listable* object) const88 void ObjectListBase::notifyRemovalListeners(ObjectListBaseElement* element) const 71 89 { 72 for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it) 73 ((Iterator<Listable>*)(*it))->incrementIfEqual(object); 74 for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it) 75 ((ObjectListIterator<Listable>*)(*it))->incrementIfEqual(object); 90 for (std::vector<ObjectListElementRemovalListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 91 (*it)->removedElement(element); 76 92 } 77 93 … … 79 95 @brief Adds a new object to the end of the list. 80 96 @param element The element to add 81 @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object82 97 */ 83 ObjectListBaseElement*ObjectListBase::addElement(ObjectListBaseElement* element)98 void ObjectListBase::addElement(ObjectListBaseElement* element) 84 99 { 100 if (element->list_) 101 { 102 orxout(internal_error) << "Element is already registered in another list" << endl; 103 return; 104 } 105 106 if (element->objectBase_) 107 orxout(verbose, context::object_list) << "Added object to " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 108 85 109 if (!this->last_) 86 110 { 87 111 // If the list is empty 88 112 this->last_ = element; 89 this->first_ = this->last_; // There's only one object in the list now113 this->first_ = element; // There's only one object in the list now 90 114 } 91 115 else … … 94 118 ObjectListBaseElement* temp = this->last_; 95 119 this->last_ = element; 96 this->last_->prev_ = temp;97 temp->next_ = this->last_;120 element->prev_ = temp; 121 temp->next_ = element; 98 122 } 99 123 100 return this->last_; 124 element->list_ = this; 125 ++this->size_; 101 126 } 102 127 128 /** 129 * @brief Removes the element from the list 130 */ 103 131 void ObjectListBase::removeElement(ObjectListBaseElement* element) 104 132 { 105 orxout(verbose, context::object_list) << "Removing Object from " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 106 this->notifyIterators(element->objectBase_); 133 if (element->list_ != this) 134 { 135 orxout(internal_error) << "Element is not registered in this list" << endl; 136 return; 137 } 138 139 if (element->objectBase_) 140 orxout(verbose, context::object_list) << "Removing Object from " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 141 this->notifyRemovalListeners(element); 107 142 108 143 if (element->next_) … … 115 150 else 116 151 this->first_ = element->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list 152 153 element->list_ = 0; 154 element->next_ = 0; 155 element->prev_ = 0; 156 --this->size_; 117 157 } 118 158 }
Note: See TracChangeset
for help on using the changeset viewer.