Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

don't panic, no codechanges!
added a link to www.orxonox.net

File size: 5.0 KB
RevLine 
[790]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[790]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
[871]29/**
[790]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
[246]38#ifndef _MetaObjectList_H__
39#define _MetaObjectList_H__
40
[790]41#include "CorePrereqs.h"
42
[246]43#include "ObjectList.h"
44#include "Identifier.h"
[790]45#include "Debug.h"
[246]46
47namespace orxonox
48{
[790]49    //! Base-class of MetaObjectListElement, because those is a template
[246]50    class BaseMetaObjectListElement
51    {
52        public:
[790]53            /** @brief Default destructor */
[246]54            virtual ~BaseMetaObjectListElement() {};
55
[790]56            BaseMetaObjectListElement* next_;       //!< The next Element in the list
[246]57    };
58
59    // ###############################
60    // ###  MetaObjectListElement  ###
61    // ###############################
[790]62    //! The list-element of the MetaObjectList
[246]63    template <class T>
64    class MetaObjectListElement : public BaseMetaObjectListElement
65    {
66        public:
67            MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element);
[790]68            virtual ~MetaObjectListElement();
[246]69
[790]70            ObjectListElement<T>* element_;         //!< The list element, containing the object
71            ObjectList<T>* list_;                   //!< The list, containing the element
[246]72    };
73
[790]74    /**
75        @brief Constructor: Creates the list-element with given list and element.
76    */
[246]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
[790]85    /**
86        @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement.
87    */
[246]88    template <class T>
89    MetaObjectListElement<T>::~MetaObjectListElement()
90    {
91        if (this->element_->next_)
92            this->element_->next_->prev_ = this->element_->prev_;
93        else
[790]94            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
[246]95
96        if (this->element_->prev_)
97            this->element_->prev_->next_ = this->element_->next_;
98        else
[790]99            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
[246]100
101
[1052]102        COUT(5) << "*** MetaObjectList: Removing Object from " << ClassManager<T>::getIdentifier()->getName() << "-list." << std::endl;
[246]103        delete this->element_;
104    }
105
106
107    // ###############################
108    // ###       ObjectList        ###
109    // ###############################
[790]110    //!  The MetaObjectList contains ObjectListElements and their ObjectLists.
111    /**
112        The MetaObjectList is a single-linked list, containing all list-elements and their
113        lists wherein the object that owns the MetaObjectList is registered.
114        This allows much faster deletion of objects because no iteration is needed.
115    */
[1024]116    class _CoreExport MetaObjectList
[246]117    {
118        public:
119            MetaObjectList();
120            ~MetaObjectList();
121            template <class T>
122            void add(ObjectList<T>* list, ObjectListElement<T>* element);
123
[790]124            BaseMetaObjectListElement* first_;      //!< The first element in the list
[246]125    };
126
[790]127    /**
128        @brief Adds an ObjectList and an element of that list to the MetaObjectList.
129        @param list The ObjectList wherein the element is
130        @param element The element wherein the object is
131    */
[246]132    template <class T>
133    void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element)
134    {
135        BaseMetaObjectListElement* temp = this->first_;
136        this->first_ = new MetaObjectListElement<T>(list, element);
137        this->first_->next_ = temp;
138    }
139}
140
[790]141#endif /* _MetaObjectList_H__ */
Note: See TracBrowser for help on using the repository browser.