- Timestamp:
- Mar 29, 2013, 2:12:41 PM (12 years ago)
- Location:
- code/branches/core6/src/libraries/core/object
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/object/Iterator.h
r9596 r9598 57 57 58 58 #include "ObjectListBase.h" 59 #include "IteratorBase.h" 59 60 60 61 namespace orxonox … … 69 70 */ 70 71 template <class T> 71 class Iterator 72 class Iterator : public IteratorBase<T, Iterator<T> > 72 73 { 73 74 public: … … 75 76 @brief Constructor: Sets the element, whereon the iterator points, to zero. 76 77 */ 77 inline Iterator() 78 { 79 this->element_ = NULL; 80 this->list_ = NULL; 81 } 78 inline Iterator() : IteratorBase<T, Iterator<T> >(NULL) {} 79 80 /** 81 @brief Constructor: Sets this element to a given element 82 @param element The element 83 */ 84 inline Iterator(ObjectListBaseElement* element) : IteratorBase<T, Iterator<T> >(element) {} 82 85 83 86 /** … … 85 88 @param other The other Iterator 86 89 */ 87 inline Iterator(const Iterator<T>& other) 88 { 89 this->element_ = other.element_; 90 this->registerIterator(); 91 } 92 93 /** 94 @brief Constructor: Sets this element to a given element 95 @param element The element 96 */ 97 inline Iterator(ObjectListBaseElement* element) 98 { 99 this->element_ = element; 100 this->registerIterator(); 101 } 102 103 /** 104 @brief Constructor: Sets this element to the element an ObjectListIterator. 105 @param other The ObjectListIterator 106 */ 107 template <class O> 108 inline Iterator(const ObjectListIterator<O>& other) 109 { 110 this->element_ = other.element_; 111 this->registerIterator(); 112 } 113 114 /** 115 @brief Unregisters the Iterator from the ObjectList. 116 */ 117 inline ~Iterator() 118 { 119 this->unregisterIterator(); 120 } 121 122 /** 123 @brief Assigns the element of another Iterator. 124 @param other The other Iterator 125 */ 126 inline Iterator<T>& operator=(const Iterator<T>& other) 127 { 128 this->unregisterIterator(); 129 this->element_ = other.element_; 130 this->registerIterator(); 131 132 return (*this); 133 } 90 inline Iterator(const Iterator<T>& other) : IteratorBase<T, Iterator<T> >(other) {} 134 91 135 92 /** … … 139 96 inline Iterator<T>& operator=(ObjectListBaseElement* element) 140 97 { 141 this->unregisterIterator(); 142 this->element_ = element; 143 this->registerIterator(); 144 98 this->setElement(element); 145 99 return (*this); 146 }147 148 /**149 @brief Assigns the element of an ObjectListIterator.150 @param other The ObjectListIterator151 */152 template <class O>153 inline Iterator<T>& operator=(const ObjectListIterator<O>& other)154 {155 this->unregisterIterator();156 this->element_ = other.element_;157 this->registerIterator();158 159 return (*this);160 }161 162 /**163 @brief Overloading of the ++it operator: Iterator points to the next object in the list.164 @return The Iterator itself165 */166 inline const Iterator<T>& operator++()167 {168 this->element_ = this->element_->next_;169 return *this;170 }171 172 /**173 @brief Overloading of the it++ operator: Iterator points to the next object in the list.174 @return The Iterator itself175 */176 inline Iterator<T> operator++(int)177 {178 Iterator<T> copy = *this;179 this->element_ = this->element_->next_;180 return copy;181 }182 183 /**184 @brief Overloading of the --it operator: Iterator points to the previous object in the list.185 @return The Iterator itself186 */187 inline const Iterator<T>& operator--()188 {189 this->element_ = this->element_->prev_;190 return *this;191 }192 193 /**194 @brief Overloading of the it-- operator: Iterator points to the previous object in the list.195 @return The Iterator itself196 */197 inline Iterator<T> operator--(int i)198 {199 Iterator<T> copy = *this;200 this->element_ = this->element_->prev_;201 return copy;202 100 } 203 101 … … 219 117 return orxonox_cast<T*>(this->element_->objectBase_); 220 118 } 221 222 /**223 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.224 @return True if the Iterator points to an existing object.225 */226 inline operator bool() const227 {228 return (this->element_ != NULL);229 }230 231 /**232 @brief Overloading of the == operator to compare with another Iterator.233 @param compare The other Iterator234 @return True if the iterators point to the same element235 */236 inline bool operator==(const Iterator<T>& compare) const237 {238 return (this->element_ == compare.element_);239 }240 241 /**242 @brief Overloading of the != operator to compare with another Iterator.243 @param compare The other Iterator244 @return True if the iterators point to different elements245 */246 inline bool operator!=(const Iterator<T>& compare) const247 {248 return (this->element_ != compare.element_);249 }250 251 /**252 @brief Increments the Iterator if it points at the given object.253 @param object The object to compare with254 */255 inline void incrementIfEqual(Listable* object)256 {257 if (this->element_ && this->element_->objectBase_ == object)258 this->operator++();259 }260 261 private:262 /**263 * @brief Registers the Iterator at the list to which it belongs264 */265 inline void registerIterator()266 {267 if (this->element_)268 {269 this->list_ = this->element_->list_;270 this->list_->registerIterator(this);271 }272 else273 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 at286 ObjectListBase* list_; //!< The list in which the Iterator registered itself287 119 }; 288 120 } -
code/branches/core6/src/libraries/core/object/ObjectListIterator.h
r9573 r9598 58 58 #include "core/class/Identifier.h" 59 59 #include "ObjectList.h" 60 #include "IteratorBase.h" 60 61 61 62 namespace orxonox … … 67 68 */ 68 69 template <class T> 69 class ObjectListIterator 70 class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T> > 70 71 { 71 72 template <class I> … … 76 77 @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero. 77 78 */ 78 inline ObjectListIterator() 79 { 80 this->element_ = 0; 81 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 82 } 79 inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >(NULL) {} 83 80 84 81 /** … … 86 83 @param element The element to start with 87 84 */ 88 inline ObjectListIterator(ObjectListElement<T>* element) 89 { 90 this->element_ = element; 91 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 92 } 85 inline ObjectListIterator(ObjectListElement<T>* element) : IteratorBase<T, ObjectListIterator<T> >(element) {} 93 86 94 87 /** … … 96 89 @param other The other ObjectListIterator 97 90 */ 98 inline ObjectListIterator(const ObjectListIterator<T>& other) 99 { 100 this->element_ = other.element_; 101 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 102 } 103 104 /** 105 @brief Unregisters the ObjectListIterator from the ObjectList. 106 */ 107 inline ~ObjectListIterator() 108 { 109 ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterObjectListIterator(this); 110 } 111 112 /** 113 @brief Assigns an ObjectListElement. 114 @param element The ObjectListElement 115 */ 116 inline ObjectListIterator<T>& operator=(ObjectListElement<T>* element) 117 { 118 this->element_ = element; 119 return (*this); 120 } 121 122 /** 123 @brief Assigns the element of another ObjectListIterator. 124 @param other The other ObjectListIterator 125 */ 126 inline ObjectListIterator<T>& operator=(const ObjectListIterator<T>& other) 127 { 128 this->element_ = other.element_; 129 return (*this); 130 } 131 132 /** 133 @brief Overloading of the ++it operator: ObjectListIterator points to the next object in the list. 134 @return The ObjectListIterator itself 135 */ 136 inline const ObjectListIterator<T>& operator++() 137 { 138 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 139 return *this; 140 } 141 142 /** 143 @brief Overloading of the it++ operator: ObjectListIterator points to the next object in the list. 144 @return The ObjectListIterator itself 145 */ 146 inline ObjectListIterator<T> operator++(int) 147 { 148 ObjectListIterator<T> copy = *this; 149 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 150 return copy; 151 } 152 153 /** 154 @brief Overloading of the --it operator: ObjectListIterator points to the previous object in the list. 155 @return The ObjectListIterator itself 156 */ 157 inline const ObjectListIterator<T>& operator--() 158 { 159 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 160 return *this; 161 } 162 163 /** 164 @brief Overloading of the it-- operator: ObjectListIterator points to the previous object in the list. 165 @return The ObjectListIterator itself 166 */ 167 inline ObjectListIterator<T> operator--(int i) 168 { 169 ObjectListIterator<T> copy = *this; 170 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 171 return copy; 172 } 91 inline ObjectListIterator(const IteratorBase<T, ObjectListIterator<T> >& other) : IteratorBase<T, ObjectListIterator<T> >(other) {} 173 92 174 93 /** … … 178 97 inline T* operator*() const 179 98 { 180 return this->element_->object_;99 return static_cast<ObjectListElement<T>*>(this->element_)->object_; 181 100 } 182 101 … … 187 106 inline T* operator->() const 188 107 { 189 return this->element_->object_;108 return static_cast<ObjectListElement<T>*>(this->element_)->object_; 190 109 } 191 192 /**193 @brief Overloading of the typecast-operator to bool: returns true if the ObjectListIterator points to an existing object.194 @return True if the ObjectListIterator points to an existing object.195 */196 inline operator bool() const197 {198 return (this->element_ != 0);199 }200 201 /**202 @brief Overloading of the == operator to compare with another ObjectListIterator.203 @param compare The other ObjectListIterator204 @return True if the ObjectListIterator point to the same element205 */206 inline bool operator==(const ObjectListIterator<T>& compare) const207 {208 return (this->element_ == compare.element_);209 }210 211 /**212 @brief Overloading of the != operator to compare with another ObjectListIterator.213 @param compare The other ObjectListIterator214 @return True if the ObjectListIterator point to different elements215 */216 inline bool operator!=(const ObjectListIterator<T>& compare) const217 {218 return (this->element_ != compare.element_);219 }220 221 /**222 @brief Increments the ObjectListIterator if it points at the given object.223 @param object The object to compare with224 */225 inline void incrementIfEqual(Listable* object)226 {227 if (this->element_ && this->element_->objectBase_ == object)228 this->operator++();229 }230 231 private:232 ObjectListElement<T>* element_; //!< The element the iterator points at233 110 }; 234 111 }
Note: See TracChangeset
for help on using the changeset viewer.