- Timestamp:
- Mar 30, 2013, 3:38:02 PM (12 years ago)
- Location:
- code/branches/core6/src/libraries/core/object
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/object/ObjectList.h
r9596 r9604 68 68 typedef ObjectListIterator<T> iterator; 69 69 70 /// Returns the size of the list 71 inline static size_t size() 72 { 73 return ClassIdentifier<T>::getIdentifier()->getObjects()->size(); 74 } 75 70 76 /// Returns an Iterator to the first element in the list. 71 77 inline static ObjectListElement<T>* begin() -
code/branches/core6/src/libraries/core/object/ObjectListBase.cc
r9599 r9604 43 43 ObjectListBaseElement::~ObjectListBaseElement() 44 44 { 45 this->list_->removeElement(this); 45 if (this->list_) 46 this->list_->removeElement(this); 46 47 } 47 48 … … 53 54 this->first_ = 0; 54 55 this->last_ = 0; 56 this->size_ = 0; 55 57 } 56 58 … … 60 62 ObjectListBase::~ObjectListBase() 61 63 { 62 ObjectListBaseElement* temp;63 64 while (this->first_) 64 {65 temp = this->first_->next_;66 65 delete this->first_; 67 this->first_ = temp;68 }69 66 } 70 67 … … 86 83 void ObjectListBase::addElement(ObjectListBaseElement* element) 87 84 { 85 if (element->list_) 86 { 87 orxout(internal_error) << "Element is already registered in another list" << endl; 88 return; 89 } 90 88 91 if (!this->last_) 89 92 { 90 93 // If the list is empty 91 94 this->last_ = element; 92 this->first_ = this->last_; // There's only one object in the list now95 this->first_ = element; // There's only one object in the list now 93 96 } 94 97 else … … 97 100 ObjectListBaseElement* temp = this->last_; 98 101 this->last_ = element; 99 this->last_->prev_ = temp;100 temp->next_ = this->last_;102 element->prev_ = temp; 103 temp->next_ = element; 101 104 } 105 106 element->list_ = this; 107 ++this->size_; 102 108 } 103 109 … … 107 113 void ObjectListBase::removeElement(ObjectListBaseElement* element) 108 114 { 109 orxout(verbose, context::object_list) << "Removing Object from " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 115 if (element->list_ != this) 116 { 117 orxout(internal_error) << "Element is not registered in this list" << endl; 118 return; 119 } 120 121 if (element->objectBase_) 122 orxout(verbose, context::object_list) << "Removing Object from " << element->objectBase_->getIdentifier()->getName() << "-list." << endl; 110 123 this->notifyRemovalListeners(element); 111 124 … … 119 132 else 120 133 this->first_ = element->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list 134 135 element->list_ = 0; 136 element->next_ = 0; 137 element->prev_ = 0; 138 --this->size_; 121 139 } 122 140 } -
code/branches/core6/src/libraries/core/object/ObjectListBase.h
r9599 r9604 56 56 @param objectBase The object to store 57 57 */ 58 ObjectListBaseElement(Listable* object , ObjectListBase* list) : next_(0), prev_(0), objectBase_(object), list_(list) {}58 ObjectListBaseElement(Listable* object) : next_(0), prev_(0), objectBase_(object), list_(0) {} 59 59 ~ObjectListBaseElement(); 60 60 … … 74 74 { 75 75 public: 76 ObjectListElement(T* object , ObjectListBase* list) : ObjectListBaseElement(static_cast<Listable*>(object), list), object_(object) {}76 ObjectListElement(T* object) : ObjectListBaseElement(static_cast<Listable*>(object)), object_(object) {} 77 77 T* object_; //!< The object 78 78 }; … … 113 113 inline ObjectListBaseElement* add(T* object) 114 114 { 115 ObjectListBaseElement* element = new ObjectListElement<T>(object , this);115 ObjectListBaseElement* element = new ObjectListElement<T>(object); 116 116 this->addElement(element); 117 117 return element; … … 120 120 void addElement(ObjectListBaseElement* element); 121 121 void removeElement(ObjectListBaseElement* element); 122 123 size_t size() const { return this->size_; } 122 124 123 125 /// Returns a pointer to the first element in the list. Works only with Iterator. … … 148 150 ObjectListBaseElement* first_; //!< The first element in the list 149 151 ObjectListBaseElement* last_; //!< The last element in the list 152 size_t size_; //!< The number of elements in the list 150 153 std::vector<ObjectListElementRemovalListener*> listeners_; //!< A list of Iterators pointing on an element in this list 151 154 }; -
code/branches/core6/src/libraries/core/object/ObjectListIterator.h
r9598 r9604 70 70 class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T> > 71 71 { 72 template <class I>73 friend class Iterator;74 75 72 public: 76 73 /**
Note: See TracChangeset
for help on using the changeset viewer.