Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/ObjectListBase.h @ 2037

Last change on this file since 2037 was 1854, checked in by landauf, 16 years ago
  • some cmake fixes for ceguilua and mingw
  • small change in XMLPort
  • Property svn:eol-style set to native
File size: 5.4 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 <list>
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* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {}
58
59            ObjectListBaseElement* next_;       //!< The next element in the list
60            ObjectListBaseElement* prev_;       //!< The previous element in the list
61            OrxonoxClass* objectBase_;
62    };
63
64
65    // ###############################
66    // ###    ObjectListElement    ###
67    // ###############################
68    //! The list-element that actually contains the object
69    template <class T>
70    class ObjectListElement : public ObjectListBaseElement
71    {
72        public:
73            ObjectListElement(T* object) : ObjectListBaseElement((OrxonoxClass*)object), object_(object) {}
74            T* object_;              //!< The object
75    };
76
77
78    // ###############################
79    // ###     ObjectListBase      ###
80    // ###############################
81    //! The ObjectListBase contains all objects of a given class.
82    /**
83        The ObjectListBase is used by Identifiers to store all objects of their given class.
84        Use ObjectList<T> to get the list of all T's and Iterator<T> to iterate through them.
85    */
86    class _CoreExport ObjectListBase
87    {
88        friend class MetaObjectListElement;
89
90        public:
91            ObjectListBase(Identifier* identifier);
92            ~ObjectListBase();
93
94            ObjectListBaseElement* add(ObjectListBaseElement* element);
95
96            struct Export
97            {
98                Export(ObjectListBase* list, ObjectListBaseElement* element) : list_(list), element_(element) {}
99                ObjectListBase* list_;
100                ObjectListBaseElement* element_;
101            };
102
103            /** @brief Returns a pointer to the first element in the list. @return The element */
104            inline Export begin() { return ObjectListBase::Export(this, this->first_); }
105            /** @brief Returns a pointer to the element after the last element in the list. @return The element */
106            inline Export end() { return ObjectListBase::Export(this, 0); }
107            /** @brief Returns a pointer to the last element in the list. @return The element */
108            inline Export rbegin() { return ObjectListBase::Export(this, this->last_); }
109            /** @brief Returns a pointer to the element in front of the first element in the list. @return The element */
110            inline Export rend() { return ObjectListBase::Export(this, 0); }
111
112            inline std::list<void*>::iterator registerIterator(void* iterator) { return this->iterators_.insert(this->iterators_.begin(), iterator); }
113            inline void unregisterIterator(const std::list<void*>::iterator& iterator) { this->iterators_.erase(iterator); }
114            inline std::list<void*>::iterator registerObjectListIterator(void* iterator) { return this->objectListIterators_.insert(this->objectListIterators_.begin(), iterator); }
115            inline void unregisterObjectListIterator(const std::list<void*>::iterator& iterator) { this->objectListIterators_.erase(iterator); }
116            void notifyIterators(OrxonoxClass* object) const;
117
118            inline Identifier* getIdentifier() const { return this->identifier_; }
119
120        private:
121            Identifier* identifier_;               //!< The Iterator owning this list
122            ObjectListBaseElement* first_;         //!< The first element in the list
123            ObjectListBaseElement* last_;          //!< The last element in the list
124            std::list<void*> iterators_;           //!< A list of Iterators pointing on an element in this list
125            std::list<void*> objectListIterators_; //!< A list of ObjectListIterators pointing on an element in this list
126    };
127}
128
129#endif /* _ObjectListBase_H__ */
Note: See TracBrowser for help on using the repository browser.