Changeset 9599 for code/branches/core6/src/libraries
- Timestamp:
- Mar 29, 2013, 2:33:04 PM (12 years ago)
- Location:
- code/branches/core6/src/libraries/core/object
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/object/IteratorBase.h
r9598 r9599 47 47 */ 48 48 template <class T, class I> 49 class IteratorBase 49 class IteratorBase : public ObjectListElementRemovalListener 50 50 { 51 51 public: … … 169 169 170 170 /** 171 @brief Increments the Iterator if it points at the given object.171 @brief Increments the Iterator if it points at the given element. 172 172 @param object The object to compare with 173 173 */ 174 inline void incrementIfEqual(Listable* object)175 { 176 if (this->element_ && this->element_->objectBase_ == object)174 virtual void removedElement(ObjectListBaseElement* element) 175 { 176 if (this->element_ == element) 177 177 this->operator++(); 178 178 } … … 194 194 { 195 195 this->list_ = this->element_->list_; 196 this->list_->register Iterator(this);196 this->list_->registerRemovalListener(this); 197 197 } 198 198 else … … 206 206 { 207 207 if (this->list_) 208 this->list_->unregister Iterator(this);208 this->list_->unregisterRemovalListener(this); 209 209 } 210 210 -
code/branches/core6/src/libraries/core/object/ObjectListBase.cc
r9597 r9599 70 70 71 71 /** 72 @brief Increases all Iterators that currently point on the given element (because it gets removed). 73 @param object The object that gets removed 72 @brief Notifies all listeners that the given element is about to get removed. 73 @param element The element that gets removed 74 This is mainly used for iterators which point at the removed element 74 75 */ 75 void ObjectListBase::notify Iterators(Listable* object) const76 void ObjectListBase::notifyRemovalListeners(ObjectListBaseElement* element) const 76 77 { 77 for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it) 78 ((Iterator<Listable>*)(*it))->incrementIfEqual(object); 79 for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it) 80 ((ObjectListIterator<Listable>*)(*it))->incrementIfEqual(object); 78 for (std::vector<ObjectListElementRemovalListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 79 (*it)->removedElement(element); 81 80 } 82 81 … … 109 108 { 110 109 orxout(verbose, context::object_list) << "Removing Object from " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 111 this->notify Iterators(element->objectBase_);110 this->notifyRemovalListeners(element); 112 111 113 112 if (element->next_) -
code/branches/core6/src/libraries/core/object/ObjectListBase.h
r9597 r9599 79 79 80 80 81 // ######################################## 82 // ### ObjectListElementRemovalListener ### 83 // ######################################## 84 /// Gets called by the object list if an element is removed 85 class _CoreExport ObjectListElementRemovalListener 86 { 87 public: 88 virtual ~ObjectListElementRemovalListener() {} 89 virtual void removedElement(ObjectListBaseElement* element) = 0; 90 }; 91 81 92 // ############################### 82 93 // ### ObjectListBase ### … … 119 130 inline ObjectListBaseElement* rend() { return 0; } 120 131 121 inline void register Iterator(void* iterator) { this->iterators_.push_back(iterator); }122 inline void unregister Iterator(void* iterator)132 inline void registerRemovalListener(ObjectListElementRemovalListener* listener) { this->listeners_.push_back(listener); } 133 inline void unregisterRemovalListener(ObjectListElementRemovalListener* listener) 123 134 { 124 for (unsigned int i = 0; i < this-> iterators_.size(); ++i)135 for (unsigned int i = 0; i < this->listeners_.size(); ++i) 125 136 { 126 if ( iterators_[i] == iterator)137 if (listeners_[i] == listener) 127 138 { 128 iterators_.erase(iterators_.begin() + i);139 listeners_.erase(listeners_.begin() + i); 129 140 break; 130 141 } 131 142 } 132 143 } 133 inline void registerObjectListIterator(void* iterator) { this->objectListIterators_.push_back(iterator); }134 inline void unregisterObjectListIterator(void* iterator)135 {136 for (unsigned int i = 0; i < this->objectListIterators_.size(); ++i)137 {138 if (objectListIterators_[i] == iterator)139 {140 objectListIterators_.erase(objectListIterators_.begin() + i);141 break;142 }143 }144 }145 void notifyIterators(Listable* object) const;146 144 147 145 private: 148 ObjectListBaseElement* first_; //!< The first element in the list 149 ObjectListBaseElement* last_; //!< The last element in the list 150 std::vector<void*> iterators_; //!< A list of Iterators pointing on an element in this list 151 std::vector<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list 146 void notifyRemovalListeners(ObjectListBaseElement* element) const; 147 148 ObjectListBaseElement* first_; //!< The first element in the list 149 ObjectListBaseElement* last_; //!< The last element in the list 150 std::vector<ObjectListElementRemovalListener*> listeners_; //!< A list of Iterators pointing on an element in this list 152 151 }; 153 152 }
Note: See TracChangeset
for help on using the changeset viewer.