Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/object/Iterator.h @ 10179

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

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 4.0 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 Iterator class, used to iterate through object-lists.
33
34    @anchor IteratorExample
35
36    @ref orxonox::Iterator "Iterator" allows to iterate through an @ref orxonox::ObjectListBase
37    "ObjectListBase". Objects in this list are cast to the template argument @a T of Iterator<T> using
38    @c dynamic_cast. In contrast to @ref orxonox::ObjectListIterator "ObjectListIterator<T>",
39    @ref orxonox::Iterator "Iterator<T>" can iterate through every object-list. In practice though it
40    is limited to objects of type @a T and its subclasses. Because of the @c dynamic_cast, this iterator
41    is much slower than ObjectListIterator.
42
43    Usage:
44    @code
45    for (Iterator<myClass> it = anyidentifier->getObjects()->begin(); it != anyidentifier->getObjects()->end(); ++it)
46    {
47        it->someFunction(...);
48        myClass* myObject = *it;
49    }
50    @endcode
51*/
52
53#ifndef _Iterator_H__
54#define _Iterator_H__
55
56#include "core/CorePrereqs.h"
57
58#include "ObjectListBase.h"
59#include "IteratorBase.h"
60
61namespace orxonox
62{
63    /**
64        @brief The Iterator allows to iterate through a given ObjectList.
65
66        Independent of the object-list's type, the objects in the list are always casted
67        to @a T using @c dynamic_cast.
68
69        @see See @ref IteratorExample "Iterator.h" for more information an example.
70    */
71    template <class T>
72    class Iterator : public IteratorBase<T, Iterator<T> >
73    {
74        public:
75            /**
76                @brief Constructor: Sets the element, whereon the iterator points, to zero.
77            */
78            inline Iterator() : IteratorBase<T, Iterator<T> >(NULL) {}
79
80            /**
81                @brief Constructor: Sets this element to a given element
82                @param element The element
83            */
84            inline Iterator(ObjectListBaseElement* element) : IteratorBase<T, Iterator<T> >(element) {}
85
86            /**
87                @brief Constructor: Sets this element to the element of another Iterator.
88                @param other The other Iterator
89            */
90            inline Iterator(const Iterator<T>& other) : IteratorBase<T, Iterator<T> >(other) {}
91
92            /**
93                @brief Assigns a given element.
94                @param element The element
95            */
96            inline Iterator<T>& operator=(ObjectListBaseElement* element)
97            {
98                this->setElement(element);
99                return (*this);
100            }
101
102            /**
103                @brief Overloading of the *it operator: returns the pointer to the object.
104                @return The object the Iterator points at
105            */
106            inline T* operator*() const
107            {
108                return orxonox_cast<T*>(this->element_->objectBase_);
109            }
110
111            /**
112                @brief Overloading of the it-> operator: returns the pointer to the object.
113                @return The object the Iterator points at
114            */
115            inline T* operator->() const
116            {
117                return orxonox_cast<T*>(this->element_->objectBase_);
118            }
119    };
120}
121
122#endif /* _Iterator_H__ */
Note: See TracBrowser for help on using the repository browser.