Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/core/ObjectListBase.h @ 1574

Last change on this file since 1574 was 1574, checked in by landauf, 16 years ago

big change in ObjectList: separated the class into a non-template base and a template wrapper for the base. this also changes the Iterator, there is now a non-template IteratorBase. this brings much more flexibility, like iterating through all objects of a given identifier without knowing the type. however this needs a dynamic_cast, which isn't quite optimal, but I think there are much worser things than that out there. ;)

there isn't much you have to know about this, except there is no more ObjectList<myClass>::start() function but a ObjectList<myClass>::begin() to be more STLish. another thing: ObjectList<myClass>::end() points now to the element _after_ the last element, so it's possible to iterate in a for-loop until (it != ObjectList<myClass>::end()). the reason is the same as above. however, (it) as a boolean still works perfectly fine.

  • Property svn:eol-style set to native
File size: 4.2 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 ObjectListBase.h
31    @brief Definition of the ObjectListBase class.
32
33    The ObjectListBase is a double-linked list, used by Identifiers to store all objects of a given class.
34    Newly created objects are added through the RegisterObject-macro in its constructor.
35*/
36
37#ifndef _ObjectListBase_H__
38#define _ObjectListBase_H__
39
40#include <set>
41
42#include "CorePrereqs.h"
43
44namespace orxonox
45{
46    // ###############################
47    // ###  ObjectListBaseElement  ###
48    // ###############################
49    //! The list-element of the ObjectListBase
50    class _CoreExport ObjectListBaseElement
51    {
52        public:
53            /**
54                @brief Constructor: Creates the list-element with an object.
55                @param object The object to store
56            */
57            ObjectListBaseElement(OrxonoxClass* object) : object_(object), next_(0), prev_(0) {}
58
59            OrxonoxClass* object_;              //!< The object
60            ObjectListBaseElement* next_;       //!< The next element in the list
61            ObjectListBaseElement* prev_;       //!< The previous element in the list
62    };
63
64
65    // ###############################
66    // ###     ObjectListBase      ###
67    // ###############################
68    //! The ObjectListBase contains all objects of a given class.
69    /**
70        The ObjectListBase is used by Identifiers to store all objects of their given class.
71        Use ObjectList<T> to get the list of all T's and Iterator<T> to iterate through them.
72    */
73    class _CoreExport ObjectListBase
74    {
75        friend class MetaObjectListElement;
76
77        public:
78            ObjectListBase(Identifier* identifier);
79            ~ObjectListBase();
80
81            ObjectListBaseElement* add(OrxonoxClass* object);
82
83            /** @brief Returns a pointer to the first element in the list. @return The element */
84            inline ObjectListBaseElement* begin() const { return this->first_; }
85            /** @brief Returns a pointer to the element after the last element in the list. @return The element */
86            inline ObjectListBaseElement* end() const { return 0; }
87            /** @brief Returns a pointer to the last element in the list. @return The element */
88            inline ObjectListBaseElement* rbegin() const { return this->last_; }
89            /** @brief Returns a pointer to the element in front of the first element in the list. @return The element */
90            inline ObjectListBaseElement* rend() const { return 0; }
91
92            inline void registerIterator(IteratorBase* iterator)
93                { this->iterators_.insert(this->iterators_.end(), iterator); }
94            inline void unregisterIterator(IteratorBase* iterator)
95                { this->iterators_.erase(iterator); }
96            void notifyIterators(ObjectListBaseElement* element);
97
98            inline Identifier* getIdentifier() const { return this->identifier_; }
99
100        private:
101            Identifier* identifier_;             //!< The Iterator owning this list
102            ObjectListBaseElement* first_;       //!< The first element in the list
103            ObjectListBaseElement* last_;        //!< The last element in the list
104            std::set<IteratorBase*> iterators_;  //!< A list of iterators pointing on an element in this list
105    };
106}
107
108#endif /* _ObjectListBase_H__ */
Note: See TracBrowser for help on using the repository browser.