Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/libraries/core/object/ObjectListIterator.h @ 12177

Last change on this file since 12177 was 12177, checked in by siramesh, 5 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

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    ObjectList<myClass> list;
44    for (ObjectListIterator<myClass> it = list.begin(); it != list.end(); ++it)
45    {
46        it->someFunction(...);
47        myClass* myObject = *it;
48    }
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).
53*/
54
55#ifndef _ObjectListIterator_H__
56#define _ObjectListIterator_H__
57
58#include "core/CorePrereqs.h"
59#include "core/class/Identifier.h"
60#include "ObjectList.h"
61#include "IteratorBase.h"
62
63namespace orxonox
64{
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    */
70    template <class T>
71    class ObjectListIterator : public IteratorBase<T, ObjectListIterator<T>>
72    {
73        public:
74            /**
75                @brief Constructor: Sets the element, whereon the ObjectListIterator points, to zero.
76            */
77            inline ObjectListIterator() : IteratorBase<T, ObjectListIterator<T>>() {}
78
79            /**
80                @brief Constructor: Sets this element to a given element.
81                @param element The element to start with
82            */
83            inline ObjectListIterator(ObjectListElement<T>* element) : IteratorBase<T, ObjectListIterator<T>>(element) {}
84
85            /**
86                @brief Constructor: Sets this element to the element of another ObjectListIterator.
87                @param other The other ObjectListIterator
88            */
89            template <class OI>
90            inline ObjectListIterator(const IteratorBase<T, OI>& other) : IteratorBase<T, ObjectListIterator<T>>(other) {}
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            {
98                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
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            {
107                return static_cast<ObjectListElement<T>*>(this->element_)->object_;
108            }
109    };
110}
111
112#endif /* _ObjectListIterator_H__ */
Note: See TracBrowser for help on using the repository browser.