Changeset 365 for code/branches/objecthierarchy/src/orxonox/core/Iterator.h
- Timestamp:
- Dec 1, 2007, 4:24:56 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/core/Iterator.h
r258 r365 1 /*! 2 @file Iterator.h 3 @brief Definition of the Iterator class. 4 5 The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type. 6 This is the only way to access the objects in an ObjectList. 7 8 Usage: 9 for (Iterator<class> it = ObjectList<class>::start(); it != 0; ++it) 10 { 11 it->someFunction(...); 12 class* myObject = *it; 13 } 14 15 Warning: Don't delete an object directly through the iterator. 16 */ 17 1 18 #ifndef _Iterator_H__ 2 19 #define _Iterator_H__ … … 4 21 namespace orxonox 5 22 { 23 //! The iterator allows to iterate through an ObjectList of a given class. 6 24 template <class T> 7 25 class Iterator 8 26 { 9 27 public: 28 /** 29 @brief Constructor: Sets the element whereon the iterator points to zero. 30 */ 10 31 Iterator() 11 32 { … … 13 34 } 14 35 36 /** 37 @brief Constructor: Sets the element whereon the iterator points to a given element. 38 @param element The element to start with 39 */ 15 40 Iterator(ObjectListElement<T>* element) 16 41 { … … 18 43 } 19 44 45 /** 46 @brief Overloading of the ++it operator: Iterator iterates to the next object in the list. 47 @return The Iterator itself 48 */ 20 49 Iterator<T> operator++() 21 50 { … … 24 53 } 25 54 55 /** 56 @brief Overloading of the --it operator: Iterator iterates to the previous object in the list. 57 @return The Iterator itself 58 */ 26 59 Iterator<T> operator--() 27 60 { … … 30 63 } 31 64 65 /** 66 @brief Overloading of the *it operator: returns the pointer to the object. 67 @return The object the Iterator points at 68 */ 32 69 T* operator*() 33 70 { … … 35 72 } 36 73 74 /** 75 @brief Overloading of the it-> operator: returns the pointer to the object. 76 @return The object the Iterator points at 77 */ 37 78 T* operator->() const 38 79 { … … 41 82 } 42 83 84 /** 85 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object. 86 @return True if the iterator points to an existing object. 87 */ 43 88 operator bool() 44 89 { … … 46 91 } 47 92 93 /** 94 @brief Overloading of the (it != int) operator: Used for (it != 0) instead of typecast-operator to bool. 95 @param compare The integer (must be zero, everything else makes no sense). 96 @return True if the iterator points to an existing object. 97 */ 48 98 bool operator!=(int compare) 49 99 { 100 // Comparing with something except zero makes no sense 50 101 if (compare != 0) 51 102 std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n"; … … 55 106 56 107 private: 57 ObjectListElement<T>* element_; 108 ObjectListElement<T>* element_; //!< The element the Iterator points to 58 109 }; 59 110 }
Note: See TracChangeset
for help on using the changeset viewer.