Changeset 9667 for code/trunk/src/libraries/core/object/Iterator.h
- 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/Iterator.h
r9573 r9667 56 56 #include "core/CorePrereqs.h" 57 57 58 #include "core/class/Identifier.h"59 58 #include "ObjectListBase.h" 59 #include "IteratorBase.h" 60 60 61 61 namespace orxonox … … 70 70 */ 71 71 template <class T> 72 class Iterator 72 class Iterator : public IteratorBase<T, Iterator<T> > 73 73 { 74 74 public: … … 76 76 @brief Constructor: Sets the element, whereon the iterator points, to zero. 77 77 */ 78 inline Iterator() 79 { 80 this->element_ = 0; 81 this->list_ = 0; 82 } 78 inline Iterator() : IteratorBase<T, Iterator<T> >(NULL) {} 83 79 84 80 /** 85 @brief Constructor: Sets this element to the exported element.86 @param e xp The exportedelement81 @brief Constructor: Sets this element to a given element 82 @param element The element 87 83 */ 88 inline Iterator(const ObjectListBase::Export& exp) 89 { 90 this->element_ = exp.element_; 91 this->list_ = exp.list_; 92 this->list_->registerIterator(this); 93 } 84 inline Iterator(ObjectListBaseElement* element) : IteratorBase<T, Iterator<T> >(element) {} 94 85 95 86 /** … … 97 88 @param other The other Iterator 98 89 */ 99 inline Iterator(const Iterator<T>& other) 100 { 101 this->element_ = other.element_; 102 this->list_ = other.list_; 103 this->list_->registerIterator(this); 104 } 105 106 /** 107 @brief Constructor: Sets this element to a given element 108 @param element The element 109 */ 110 template <class O> 111 inline Iterator(ObjectListElement<O>* element) 112 { 113 this->element_ = element; 114 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 115 this->list_->registerIterator(this); 116 } 117 118 /** 119 @brief Constructor: Sets this element to the element an ObjectListIterator. 120 @param other The ObjectListIterator 121 */ 122 template <class O> 123 inline Iterator(const ObjectListIterator<O>& other) 124 { 125 this->element_ = other.element_; 126 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 127 this->list_->registerIterator(this); 128 } 129 130 /** 131 @brief Unregisters the Iterator from the ObjectList. 132 */ 133 inline ~Iterator() 134 { 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); 152 } 153 154 /** 155 @brief Assigns the element of another Iterator. 156 @param other The other Iterator 157 */ 158 inline Iterator<T>& operator=(const Iterator<T>& other) 159 { 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); 166 167 return (*this); 168 } 90 inline Iterator(const Iterator<T>& other) : IteratorBase<T, Iterator<T> >(other) {} 169 91 170 92 /** … … 172 94 @param element The element 173 95 */ 174 template <class O> 175 inline Iterator<T>& operator=(ObjectListElement<O>* element) 96 inline Iterator<T>& operator=(ObjectListBaseElement* element) 176 97 { 177 if (this->list_) 178 this->list_->unregisterIterator(this); 179 180 this->element_ = element; 181 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 182 this->list_->registerIterator(this); 183 98 this->setElement(element); 184 99 return (*this); 185 }186 187 /**188 @brief Assigns the element of an ObjectListIterator.189 @param other The ObjectListIterator190 */191 template <class O>192 inline Iterator<T>& operator=(const ObjectListIterator<O>& other)193 {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);200 201 return (*this);202 }203 204 /**205 @brief Overloading of the ++it operator: Iterator points to the next object in the list.206 @return The Iterator itself207 */208 inline const Iterator<T>& operator++()209 {210 this->element_ = this->element_->next_;211 return *this;212 }213 214 /**215 @brief Overloading of the it++ operator: Iterator points to the next object in the list.216 @return The Iterator itself217 */218 inline Iterator<T> operator++(int)219 {220 Iterator<T> copy = *this;221 this->element_ = this->element_->next_;222 return copy;223 }224 225 /**226 @brief Overloading of the --it operator: Iterator points to the previous object in the list.227 @return The Iterator itself228 */229 inline const Iterator<T>& operator--()230 {231 this->element_ = this->element_->prev_;232 return *this;233 }234 235 /**236 @brief Overloading of the it-- operator: Iterator points to the previous object in the list.237 @return The Iterator itself238 */239 inline Iterator<T> operator--(int i)240 {241 Iterator<T> copy = *this;242 this->element_ = this->element_->prev_;243 return copy;244 100 } 245 101 … … 261 117 return orxonox_cast<T*>(this->element_->objectBase_); 262 118 } 263 264 /**265 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.266 @return True if the Iterator points to an existing object.267 */268 inline operator bool() const269 {270 return (this->element_ != 0);271 }272 273 /**274 @brief Overloading of the == operator to compare with another Iterator.275 @param compare The other Iterator276 @return True if the iterators point to the same element277 */278 inline bool operator==(const Iterator<T>& compare) const279 {280 return (this->element_ == compare.element_);281 }282 283 /**284 @brief Overloading of the != operator to compare with another Iterator.285 @param compare The other Iterator286 @return True if the iterators point to different elements287 */288 inline bool operator!=(const Iterator<T>& compare) const289 {290 return (this->element_ != compare.element_);291 }292 293 /**294 @brief Increments the Iterator if it points at the given object.295 @param object The object to compare with296 */297 inline void incrementIfEqual(Listable* object)298 {299 if (this->element_ && this->element_->objectBase_ == object)300 this->operator++();301 }302 303 protected:304 ObjectListBaseElement* element_; //!< The element the Iterator points at305 ObjectListBase* list_; //!< The list wherein the element is306 119 }; 307 120 }
Note: See TracChangeset
for help on using the changeset viewer.