Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/MetaObjectList.h @ 1720

Last change on this file since 1720 was 1543, checked in by rgrieder, 16 years ago
  • applied patch to remove ClassManager (wouldn't wanna maintain it anymore ;))
  • sorted core CMLs a little bit
  • updated OrxonoxStableHeaders.h
  • Property svn:eol-style set to native
File size: 4.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 MetaObjectList.h
31    @brief Definition of the MetaObjectList class.
32
33    The MetaObjectList is a single-linked list, containing all list-elements and their
34    lists wherein the object, owning the MetaObjectList, is registered.
35    This allows much faster deletion of objects because no iteration is needed.
36*/
37
38#ifndef _MetaObjectList_H__
39#define _MetaObjectList_H__
40
41#include "CorePrereqs.h"
42
43#include "ObjectList.h"
44#include "Identifier.h"
45#include "Debug.h"
46
47namespace orxonox
48{
49    //! Base-class of MetaObjectListElement, because those is a template
50    class BaseMetaObjectListElement
51    {
52        public:
53            /** @brief Default destructor */
54            virtual ~BaseMetaObjectListElement() {};
55
56            BaseMetaObjectListElement* next_;       //!< The next Element in the list
57    };
58
59    // ###############################
60    // ###  MetaObjectListElement  ###
61    // ###############################
62    //! The list-element of the MetaObjectList
63    template <class T>
64    class MetaObjectListElement : public BaseMetaObjectListElement
65    {
66        public:
67            MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element);
68            virtual ~MetaObjectListElement();
69
70            ObjectListElement<T>* element_;         //!< The list element, containing the object
71            ObjectList<T>* list_;                   //!< The list, containing the element
72    };
73
74    /**
75        @brief Constructor: Creates the list-element with given list and element.
76    */
77    template <class T>
78    MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element)
79    {
80        this->element_ = element;
81        this->list_ = list;
82        this->next_ = 0;
83    }
84
85    /**
86        @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement.
87    */
88    template <class T>
89    MetaObjectListElement<T>::~MetaObjectListElement()
90    {
91        COUT(5) << "*** MetaObjectList: Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;
92        this->list_->notifyIterators(this->element_);
93
94        if (this->element_->next_)
95            this->element_->next_->prev_ = this->element_->prev_;
96        else
97            this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list
98
99        if (this->element_->prev_)
100            this->element_->prev_->next_ = this->element_->next_;
101        else
102            this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list
103
104        delete this->element_;
105    }
106
107
108    // ###############################
109    // ###     MetaObjectList      ###
110    // ###############################
111    //!  The MetaObjectList contains ObjectListElements and their ObjectLists.
112    /**
113        The MetaObjectList is a single-linked list, containing all list-elements and their
114        lists wherein the object that owns the MetaObjectList is registered.
115        This allows much faster deletion of objects because no iteration is needed.
116    */
117    class _CoreExport MetaObjectList
118    {
119        public:
120            MetaObjectList();
121            ~MetaObjectList();
122            template <class T>
123            void add(ObjectList<T>* list, ObjectListElement<T>* element);
124
125            BaseMetaObjectListElement* first_;      //!< The first element in the list
126    };
127
128    /**
129        @brief Adds an ObjectList and an element of that list to the MetaObjectList.
130        @param list The ObjectList wherein the element is
131        @param element The element wherein the object is
132    */
133    template <class T>
134    void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element)
135    {
136        BaseMetaObjectListElement* temp = this->first_;
137        this->first_ = new MetaObjectListElement<T>(list, element);
138        this->first_->next_ = temp;
139    }
140}
141
142#endif /* _MetaObjectList_H__ */
Note: See TracBrowser for help on using the repository browser.