/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * */ /** @file @ingroup Object ObjectList @brief Definition of the ObjectListIterator class, used to iterate through object-lists. @anchor ObjectListIteratorExample @ref orxonox::ObjectListIterator "ObjectListIterator" allows to iterate through @ref orxonox::ObjectList "ObjectList", containing all objects of type @a T. In contrast to @ref orxonox::Iterator "Iterator", this iterator is limited to the object-list of type @a T. It is, however, much faster as it doesn't need a @c dynamic_cast. Usage: @code for (ObjectListIterator it = ObjectList::begin(); it != ObjectList::end(); ++it) { it->someFunction(...); myClass* myObject = *it; } @endcode @note @ref orxonox::ObjectList::iterator "ObjectList::iterator" is identical to @ref orxonox::ObjectListIterator "ObjectListIterator" (it's just a typedef). */ #ifndef _ObjectListIterator_H__ #define _ObjectListIterator_H__ #include "core/CorePrereqs.h" #include "core/class/Identifier.h" #include "ObjectList.h" #include "IteratorBase.h" namespace orxonox { /** @brief ObjectListIterator allows to iterate through the ObjectList of class @a T. @see See @ref ObjectListIteratorExample "ObjectListIterator.h" for more information an example. */ template class ObjectListIterator : public IteratorBase > { public: /** @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero. */ inline ObjectListIterator() : IteratorBase >(NULL) {} /** @brief Constructor: Sets this element to a given element. @param element The element to start with */ inline ObjectListIterator(ObjectListElement* element) : IteratorBase >(element) {} /** @brief Constructor: Sets this element to the element of another ObjectListIterator. @param other The other ObjectListIterator */ inline ObjectListIterator(const IteratorBase >& other) : IteratorBase >(other) {} /** @brief Overloading of the *it operator: returns the pointer to the object. @return The object the ObjectListIterator points at */ inline T* operator*() const { return static_cast*>(this->element_)->object_; } /** @brief Overloading of the it-> operator: returns the pointer to the object. @return The object the ObjectListIterator points at */ inline T* operator->() const { return static_cast*>(this->element_)->object_; } }; } #endif /* _ObjectListIterator_H__ */