Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/object/ObjectListIterator.h @ 9667

Last change on this file since 9667 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
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/**
30    @file
31    @ingroup Object ObjectList
32    @brief Definition of the ObjectListIterator class, used to iterate through object-lists.
33
34    @anchor ObjectListIteratorExample
35
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
41    Usage:
42    @code
43    for (ObjectListIterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it)
44    {
45        it->someFunction(...);
46        myClass* myObject = *it;
47    }
48    @endcode
49
50    @note @ref orxonox::ObjectList::iterator "ObjectList<T>::iterator" is identical to
51          @ref orxonox::ObjectListIterator "ObjectListIterator<T>" (it's just a typedef).
52*/
53
54#ifndef _ObjectListIterator_H__
55#define _ObjectListIterator_H__
56
57#include "core/CorePrereqs.h"
58#include "core/class/Identifier.h"
59#include "ObjectList.h"
60#include "IteratorBase.h"
61
62namespace orxonox
63{
64    /**
65        @brief ObjectListIterator<T> allows to iterate through the ObjectList of class @a T.
66
67        @see See @ref ObjectListIteratorExample "ObjectListIterator.h" for more information an example.
68    */
69    template <class T>
70    class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T> >
71    {
72        public:
73            /**
74                @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
75            */
76            inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T> >(NULL) {}
77
78            /**
79                @brief Constructor: Sets this element to a given element.
80                @param element The element to start with
81            */
82            inline ObjectListIterator(ObjectListElement<T>* element) : IteratorBase<T, ObjectListIterator<T> >(element) {}
83
84            /**
85                @brief Constructor: Sets this element to the element of another ObjectListIterator.
86                @param other The other ObjectListIterator
87            */
88            inline ObjectListIterator(const IteratorBase<T, ObjectListIterator<T> >& other) : IteratorBase<T, ObjectListIterator<T> >(other) {}
89
90            /**
91                @brief Overloading of the *it operator: returns the pointer to the object.
92                @return The object the ObjectListIterator points at
93            */
94            inline T* operator*() const
95            {
96                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
97            }
98
99            /**
100                @brief Overloading of the it-> operator: returns the pointer to the object.
101                @return The object the ObjectListIterator points at
102            */
103            inline T* operator->() const
104            {
105                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
106            }
107    };
108}
109
110#endif /* _ObjectListIterator_H__ */
Note: See TracBrowser for help on using the repository browser.