Changeset 9596 for code/branches/core6/src
- Timestamp:
- Mar 29, 2013, 12:42:24 AM (12 years ago)
- Location:
- code/branches/core6/src/libraries/core/object
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/object/Iterator.h
r9573 r9596 56 56 #include "core/CorePrereqs.h" 57 57 58 #include "core/class/Identifier.h"59 58 #include "ObjectListBase.h" 60 59 … … 78 77 inline Iterator() 79 78 { 80 this->element_ = 0; 81 this->list_ = 0; 82 } 83 84 /** 85 @brief Constructor: Sets this element to the exported element. 86 @param exp The exported element 87 */ 88 inline Iterator(const ObjectListBase::Export& exp) 89 { 90 this->element_ = exp.element_; 91 this->list_ = exp.list_; 92 this->list_->registerIterator(this); 79 this->element_ = NULL; 80 this->list_ = NULL; 93 81 } 94 82 … … 100 88 { 101 89 this->element_ = other.element_; 102 this->list_ = other.list_; 103 this->list_->registerIterator(this); 90 this->registerIterator(); 104 91 } 105 92 … … 108 95 @param element The element 109 96 */ 110 template <class O> 111 inline Iterator(ObjectListElement<O>* element) 97 inline Iterator(ObjectListBaseElement* element) 112 98 { 113 99 this->element_ = element; 114 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 115 this->list_->registerIterator(this); 100 this->registerIterator(); 116 101 } 117 102 … … 124 109 { 125 110 this->element_ = other.element_; 126 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 127 this->list_->registerIterator(this); 111 this->registerIterator(); 128 112 } 129 113 … … 133 117 inline ~Iterator() 134 118 { 135 this->list_->unregisterIterator(this); 136 } 137 138 /** 139 @brief Assigns an exported element. 140 @param exp The exported element 141 */ 142 inline Iterator<T>& operator=(const ObjectListBase::Export& exp) 143 { 144 if (this->list_) 145 this->list_->unregisterIterator(this); 146 147 this->element_ = exp.element_; 148 this->list_ = exp.list_; 149 this->list_->registerIterator(this); 150 151 return (*this); 119 this->unregisterIterator(); 152 120 } 153 121 … … 158 126 inline Iterator<T>& operator=(const Iterator<T>& other) 159 127 { 160 if (this->list_) 161 this->list_->unregisterIterator(this); 162 163 this->element_ = other.element_; 164 this->list_ = other.list_; 165 this->list_->registerIterator(this); 128 this->unregisterIterator(); 129 this->element_ = other.element_; 130 this->registerIterator(); 166 131 167 132 return (*this); … … 172 137 @param element The element 173 138 */ 174 template <class O> 175 inline Iterator<T>& operator=(ObjectListElement<O>* element) 176 { 177 if (this->list_) 178 this->list_->unregisterIterator(this); 179 139 inline Iterator<T>& operator=(ObjectListBaseElement* element) 140 { 141 this->unregisterIterator(); 180 142 this->element_ = element; 181 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 182 this->list_->registerIterator(this); 143 this->registerIterator(); 183 144 184 145 return (*this); … … 192 153 inline Iterator<T>& operator=(const ObjectListIterator<O>& other) 193 154 { 194 if (this->list_) 195 this->list_->unregisterIterator(this); 196 197 this->element_ = other.element_; 198 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 199 this->list_->registerIterator(this); 155 this->unregisterIterator(); 156 this->element_ = other.element_; 157 this->registerIterator(); 200 158 201 159 return (*this); … … 268 226 inline operator bool() const 269 227 { 270 return (this->element_ != 0);228 return (this->element_ != NULL); 271 229 } 272 230 … … 301 259 } 302 260 303 protected: 304 ObjectListBaseElement* element_; //!< The element the Iterator points at 305 ObjectListBase* list_; //!< The list wherein the element is 261 private: 262 /** 263 * @brief Registers the Iterator at the list to which it belongs 264 */ 265 inline void registerIterator() 266 { 267 if (this->element_) 268 { 269 this->list_ = this->element_->list_; 270 this->list_->registerIterator(this); 271 } 272 else 273 this->list_ = NULL; 274 } 275 276 /** 277 * @brief Unregisters the Iterator from the list (if any) 278 */ 279 inline void unregisterIterator() 280 { 281 if (this->list_) 282 this->list_->unregisterIterator(this); 283 } 284 285 ObjectListBaseElement* element_; //!< The element the Iterator points at 286 ObjectListBase* list_; //!< The list in which the Iterator registered itself 306 287 }; 307 288 } -
code/branches/core6/src/libraries/core/object/MetaObjectList.cc
r9593 r9596 48 48 MetaObjectListElement::~MetaObjectListElement() 49 49 { 50 this->list_->removeElement(this->element_);51 50 delete this->element_; 52 51 } -
code/branches/core6/src/libraries/core/object/ObjectList.h
r9557 r9596 72 72 { 73 73 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects(); 74 return static_cast<ObjectListElement<T>*>(list->begin() .element_);74 return static_cast<ObjectListElement<T>*>(list->begin()); 75 75 } 76 76 … … 79 79 { 80 80 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects(); 81 return static_cast<ObjectListElement<T>*>(list->end() .element_);81 return static_cast<ObjectListElement<T>*>(list->end()); 82 82 } 83 83 … … 86 86 { 87 87 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects(); 88 return static_cast<ObjectListElement<T>*>(list->rbegin() .element_);88 return static_cast<ObjectListElement<T>*>(list->rbegin()); 89 89 } 90 90 … … 93 93 { 94 94 ObjectListBase* list = ClassIdentifier<T>::getIdentifier()->getObjects(); 95 return static_cast<ObjectListElement<T>*>(list->rend() .element_);95 return static_cast<ObjectListElement<T>*>(list->rend()); 96 96 } 97 97 }; -
code/branches/core6/src/libraries/core/object/ObjectListBase.cc
r9593 r9596 41 41 namespace orxonox 42 42 { 43 ObjectListBaseElement::~ObjectListBaseElement() 44 { 45 this->list_->removeElement(this); 46 } 47 43 48 /** 44 49 @brief Constructor: Sets default values. -
code/branches/core6/src/libraries/core/object/ObjectListBase.h
r9593 r9596 56 56 @param objectBase The object to store 57 57 */ 58 ObjectListBaseElement(Listable* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {} 58 ObjectListBaseElement(Listable* object, ObjectListBase* list) : next_(0), prev_(0), objectBase_(object), list_(list) {} 59 ~ObjectListBaseElement(); 59 60 60 61 ObjectListBaseElement* next_; //!< The next element in the list 61 62 ObjectListBaseElement* prev_; //!< The previous element in the list 62 Listable* objectBase_; 63 Listable* objectBase_; //!< The object 64 ObjectListBase* list_; //!< The list 63 65 }; 64 66 … … 72 74 { 73 75 public: 74 ObjectListElement(T* object ) : ObjectListBaseElement(static_cast<Listable*>(object)), object_(object) {}76 ObjectListElement(T* object, ObjectListBase* list) : ObjectListBaseElement(static_cast<Listable*>(object), list), object_(object) {} 75 77 T* object_; //!< The object 76 78 }; … … 99 101 template <class T> 100 102 inline ObjectListBaseElement* add(T* object) 101 { return this->addElement(new ObjectListElement<T>(object )); }103 { return this->addElement(new ObjectListElement<T>(object, this)); } 102 104 103 105 ObjectListBaseElement* addElement(ObjectListBaseElement* element); 104 106 void removeElement(ObjectListBaseElement* element); 105 107 106 /// Helper struct, used to export an element and the list to an instance of Iterator.107 struct Export108 {109 Export(ObjectListBase* list, ObjectListBaseElement* element) : list_(list), element_(element) {}110 ObjectListBase* list_;111 ObjectListBaseElement* element_;112 };113 114 108 /// Returns a pointer to the first element in the list. Works only with Iterator. 115 inline Export begin() { return ObjectListBase::Export(this, this->first_); }109 inline ObjectListBaseElement* begin() { return this->first_; } 116 110 /// Returns a pointer to the element after the last element in the list. Works only with Iterator. 117 inline Export end() { return ObjectListBase::Export(this, 0); }111 inline ObjectListBaseElement* end() { return 0; } 118 112 /// Returns a pointer to the last element in the list. Works only with Iterator. 119 inline Export rbegin() { return ObjectListBase::Export(this, this->last_); }113 inline ObjectListBaseElement* rbegin() { return this->last_; } 120 114 /// Returns a pointer to the element in front of the first element in the list. Works only with Iterator. 121 inline Export rend() { return ObjectListBase::Export(this, 0); }115 inline ObjectListBaseElement* rend() { return 0; } 122 116 123 117 inline void registerIterator(void* iterator) { this->iterators_.push_back(iterator); }
Note: See TracChangeset
for help on using the changeset viewer.