- Timestamp:
- Aug 25, 2013, 9:08:42 PM (11 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/ObjectListIterator.h
r9573 r9667 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 template <class I>72 friend class Iterator;73 74 72 public: 75 73 /** 76 74 @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero. 77 75 */ 78 inline ObjectListIterator() 79 { 80 this->element_ = 0; 81 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 82 } 76 inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >(NULL) {} 83 77 84 78 /** … … 86 80 @param element The element to start with 87 81 */ 88 inline ObjectListIterator(ObjectListElement<T>* element) 89 { 90 this->element_ = element; 91 ClassIdentifier<T>::getIdentifier()->getObjects()->registerObjectListIterator(this); 92 } 82 inline ObjectListIterator(ObjectListElement<T>* element) : IteratorBase<T, ObjectListIterator<T> >(element) {} 93 83 94 84 /** … … 96 86 @param other The other ObjectListIterator 97 87 */ 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 } 88 inline ObjectListIterator(const IteratorBase<T, ObjectListIterator<T> >& other) : IteratorBase<T, ObjectListIterator<T> >(other) {} 173 89 174 90 /** … … 178 94 inline T* operator*() const 179 95 { 180 return this->element_->object_;96 return static_cast<ObjectListElement<T>*>(this->element_)->object_; 181 97 } 182 98 … … 187 103 inline T* operator->() const 188 104 { 189 return this->element_->object_;105 return static_cast<ObjectListElement<T>*>(this->element_)->object_; 190 106 } 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 107 }; 234 108 }
Note: See TracChangeset
for help on using the changeset viewer.