[1591] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
[3196] | 30 | @file |
---|
[7401] | 31 | @ingroup Object ObjectList |
---|
| 32 | @brief Definition of the ObjectListIterator class, used to iterate through object-lists. |
---|
[1591] | 33 | |
---|
[7401] | 34 | @anchor ObjectListIteratorExample |
---|
[1591] | 35 | |
---|
[7401] | 36 | @ref orxonox::ObjectListIterator "ObjectListIterator<T>" allows to iterate through |
---|
| 37 | @ref orxonox::ObjectList "ObjectList<T>", containing all objects of type @a T. In contrast to |
---|
| 38 | @ref orxonox::Iterator "Iterator<T>", this iterator is limited to the object-list of type @a T. |
---|
| 39 | It is, however, much faster as it doesn't need a @c dynamic_cast. |
---|
| 40 | |
---|
[1591] | 41 | Usage: |
---|
[7401] | 42 | @code |
---|
[11071] | 43 | ObjectList<myClass> list; |
---|
| 44 | for (ObjectListIterator<myClass> it = list.begin(); it != list.end(); ++it) |
---|
[1591] | 45 | { |
---|
| 46 | it->someFunction(...); |
---|
| 47 | myClass* myObject = *it; |
---|
| 48 | } |
---|
[7401] | 49 | @endcode |
---|
| 50 | |
---|
| 51 | @note @ref orxonox::ObjectList::iterator "ObjectList<T>::iterator" is identical to |
---|
| 52 | @ref orxonox::ObjectListIterator "ObjectListIterator<T>" (it's just a typedef). |
---|
[1591] | 53 | */ |
---|
| 54 | |
---|
| 55 | #ifndef _ObjectListIterator_H__ |
---|
| 56 | #define _ObjectListIterator_H__ |
---|
| 57 | |
---|
[9557] | 58 | #include "core/CorePrereqs.h" |
---|
[9563] | 59 | #include "core/class/Identifier.h" |
---|
[3196] | 60 | #include "ObjectList.h" |
---|
[9667] | 61 | #include "IteratorBase.h" |
---|
[1591] | 62 | |
---|
| 63 | namespace orxonox |
---|
| 64 | { |
---|
[7401] | 65 | /** |
---|
| 66 | @brief ObjectListIterator<T> allows to iterate through the ObjectList of class @a T. |
---|
| 67 | |
---|
| 68 | @see See @ref ObjectListIteratorExample "ObjectListIterator.h" for more information an example. |
---|
| 69 | */ |
---|
[1591] | 70 | template <class T> |
---|
[11071] | 71 | class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T>> |
---|
[1591] | 72 | { |
---|
| 73 | public: |
---|
| 74 | /** |
---|
| 75 | @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero. |
---|
| 76 | */ |
---|
[11071] | 77 | inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T>>() {} |
---|
[1591] | 78 | |
---|
| 79 | /** |
---|
| 80 | @brief Constructor: Sets this element to a given element. |
---|
| 81 | @param element The element to start with |
---|
| 82 | */ |
---|
[11071] | 83 | inline ObjectListIterator(ObjectListElement<T>* element) : IteratorBase<T, ObjectListIterator<T>>(element) {} |
---|
[1591] | 84 | |
---|
| 85 | /** |
---|
| 86 | @brief Constructor: Sets this element to the element of another ObjectListIterator. |
---|
| 87 | @param other The other ObjectListIterator |
---|
| 88 | */ |
---|
[11071] | 89 | template <class OI> |
---|
| 90 | inline ObjectListIterator(const IteratorBase<T, OI>& other) : IteratorBase<T, ObjectListIterator<T>>(other) {} |
---|
[1591] | 91 | |
---|
| 92 | /** |
---|
| 93 | @brief Overloading of the *it operator: returns the pointer to the object. |
---|
| 94 | @return The object the ObjectListIterator points at |
---|
| 95 | */ |
---|
| 96 | inline T* operator*() const |
---|
| 97 | { |
---|
[9667] | 98 | return static_cast<ObjectListElement<T>*>(this->element_)->object_; |
---|
[1591] | 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | @brief Overloading of the it-> operator: returns the pointer to the object. |
---|
| 103 | @return The object the ObjectListIterator points at |
---|
| 104 | */ |
---|
| 105 | inline T* operator->() const |
---|
| 106 | { |
---|
[9667] | 107 | return static_cast<ObjectListElement<T>*>(this->element_)->object_; |
---|
[1591] | 108 | } |
---|
| 109 | }; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | #endif /* _ObjectListIterator_H__ */ |
---|