- Timestamp:
- Dec 1, 2007, 4:24:56 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/core/ObjectList.h
r258 r365 1 /*! 2 @file ObjectList.h 3 @brief Definition of the ObjectList class. 4 5 The ObjectList is a double-linked list, used by Identifiers to store all objects of a specific class in it. 6 Created objects are added through the RegisterObject-macro in its constructor. 7 Use Iterator<class> to iterate through all objects of the class. 8 */ 9 1 10 #ifndef _ObjectList_H__ 2 11 #define _ObjectList_H__ … … 4 13 namespace orxonox 5 14 { 6 class OrxonoxClass; 15 class OrxonoxClass; // Forward declaration 7 16 8 17 // ############################### 9 18 // ### ObjectListElement ### 10 19 // ############################### 20 //! The list-element of the ObjectList 11 21 template <class T> 12 22 class ObjectListElement … … 14 24 public: 15 25 ObjectListElement(T* object); 16 ~ObjectListElement(); 17 18 T* object_; 19 ObjectListElement* next_; 20 ObjectListElement* prev_; 26 27 T* object_; //!< The object 28 ObjectListElement* next_; //!< The next element in the list 29 ObjectListElement* prev_; //!< The previous element in the list 21 30 }; 22 31 32 /** 33 @brief Constructor: Creates the list-element with an object. 34 @param Object The object to store 35 */ 23 36 template <class T> 24 37 ObjectListElement<T>::ObjectListElement(T* object) … … 29 42 } 30 43 31 template <class T>32 ObjectListElement<T>::~ObjectListElement()33 {34 }35 36 44 37 45 // ############################### … … 39 47 // ############################### 40 48 template <class T> 41 class Iterator; 42 49 class Iterator; // Forward declaration 50 51 //! The ObjectList contains all objects of a specific class. 52 /** 53 The ObjectList is used by Identifiers to store all objects of a specific class in it. 54 Use Iterator<class> to iterate through all objects in the list. 55 */ 43 56 template <class T> 44 57 class ObjectList … … 48 61 ~ObjectList(); 49 62 ObjectListElement<T>* add(T* object); 50 void remove(OrxonoxClass* object, bool bIterateForwards = true); 51 63 // void remove(OrxonoxClass* object, bool bIterateForwards = true); 64 65 /** @returns the first element in the list */ 52 66 inline static Iterator<T> start() 53 67 { return Iterator<T>(pointer_s->first_); } 68 69 /** @returns the last element in the list */ 54 70 inline static Iterator<T> end() 55 71 { return Iterator<T>(pointer_s->last_); } 56 72 57 ObjectListElement<T>* first_; 58 ObjectListElement<T>* last_; 73 ObjectListElement<T>* first_; //!< The first element in the list 74 ObjectListElement<T>* last_; //!< The last element in the list 59 75 60 76 private: 61 static ObjectList<T>* pointer_s; 77 static ObjectList<T>* pointer_s; //!< A static pointer to the last created list (different for all T) 62 78 }; 63 79 64 80 template <class T> 65 ObjectList<T>* ObjectList<T>::pointer_s = 0; 66 81 ObjectList<T>* ObjectList<T>::pointer_s = 0; // Set the static member variable pointer_s to zero 82 83 /** 84 @brief Constructor: Sets first_ and last_ to zero and the static member variable pointer_s to _this_ 85 */ 67 86 template <class T> 68 87 ObjectList<T>::ObjectList() … … 71 90 this->last_ = 0; 72 91 92 // ObjectLists are only created by Identifiers and therefore only one ObjectList of each T will exist. 93 // Thats why pointer_s is in fact a pointer to the only ObjectList for a type, which makes it almost a singleton. 73 94 this->pointer_s = this; 74 95 } 75 96 97 /** 98 @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS. 99 */ 76 100 template <class T> 77 101 ObjectList<T>::~ObjectList() … … 86 110 } 87 111 112 /** 113 @brief Adds a new object to the end of the list. 114 @param object The object to add 115 @return The pointer to the new ObjectListElement, needed by the MetaObjectList of the added object 116 */ 88 117 template <class T> 89 118 ObjectListElement<T>* ObjectList<T>::add(T* object) … … 91 120 if (!this->last_) 92 121 { 122 // If the list is empty 93 123 this->last_ = new ObjectListElement<T>(object); 94 this->first_ = this->last_; 124 this->first_ = this->last_; // There's only one object in the list now 95 125 } 96 126 else 97 127 { 128 // If the list isn't empty 98 129 ObjectListElement<T>* temp = this->last_; 99 130 this->last_ = new ObjectListElement<T>(object); … … 105 136 } 106 137 138 139 // /** 140 // @brief Removes an object from the list. 141 // @param object The object to remove 142 // @param bIterateForwards If true: Start searching the object at the beginning of the list 143 // */ 144 /* 107 145 template <class T> 108 146 void ObjectList<T>::remove(OrxonoxClass* object, bool bIterateForwards) … … 111 149 return; 112 150 151 // If there's only one object in the list, we have to set first_ and last_ to zero 113 152 if (this->first_ == this->last_) 114 153 { … … 123 162 } 124 163 164 // Now we are sure we have more than one element in the list 125 165 if (bIterateForwards) 126 166 { 167 // Start at the beginning of the list 168 169 // Check if it's the first object 127 170 if (this->first_->object_ == object) 128 171 { … … 135 178 } 136 179 180 // Iterate through the whole list 137 181 ObjectListElement<T>* temp = this->first_; 138 182 while (temp->next_) … … 146 190 temp2->prev_ = temp; 147 191 else 148 this->last_ = temp; 192 this->last_ = temp; // If there is no next_, we deleted the last element and have to update the last_ pointer. 149 193 150 194 return; … … 156 200 else 157 201 { 202 // Start at the end of the list 203 204 // Check if it's the last object 158 205 if (this->last_->object_ == object) 159 206 { … … 166 213 } 167 214 215 // Iterate through the whole list 168 216 ObjectListElement<T>* temp = this->last_; 169 217 while (temp->prev_) … … 177 225 temp2->next_ = temp; 178 226 else 179 this->first_ = temp; 227 this->first_ = temp; // If there is no prev_, we deleted the first element and have to update the first_ pointer. 180 228 181 229 return; … … 186 234 } 187 235 } 236 */ 188 237 } 189 238
Note: See TracChangeset
for help on using the changeset viewer.