Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/MetaObjectList.h @ 704

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

added a new class: Language
it's a manager for different language files to store translations of ingame text (it uses the default text, defined in the code, if no translation in the configured language is available)

File size: 4.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/*!
29    @file MetaObjectList.h
30    @brief Definition of the MetaObjectList class.
31
32    The MetaObjectList is a single-linked list, containing all list-elements and their
33    lists wherein the object, owning the MetaObjectList, is registered.
34    This allows much faster deletion of objects because no iteration is needed.
35*/
36
37#ifndef _MetaObjectList_H__
38#define _MetaObjectList_H__
39
40#include "CorePrereqs.h"
41
42#include "ObjectList.h"
43#include "Identifier.h"
44#include "Debug.h"
45
46namespace orxonox
47{
48    //! Base-class of MetaObjectListElement, because those is a template
49    class BaseMetaObjectListElement
50    {
51        public:
52            /** @brief Default destructor */
53            virtual ~BaseMetaObjectListElement() {};
54
55            BaseMetaObjectListElement* next_;       //!< The next Element in the list
56    };
57
58    // ###############################
59    // ###  MetaObjectListElement  ###
60    // ###############################
61    //! The list-element of the MetaObjectList
62    template <class T>
63    class MetaObjectListElement : public BaseMetaObjectListElement
64    {
65        public:
66            MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element);
67            virtual ~MetaObjectListElement();
68
69            ObjectListElement<T>* element_;         //!< The list element, containing the object
70            ObjectList<T>* list_;                   //!< The list, containing the element
71    };
72
73    /**
74        @brief Constructor: Creates the list-element with given list and element.
75    */
76    template <class T>
77    MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element)
78    {
79        this->element_ = element;
80        this->list_ = list;
81        this->next_ = 0;
82    }
83
84    /**
85        @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement.
86    */
87    template <class T>
88    MetaObjectListElement<T>::~MetaObjectListElement()
89    {
90        if (this->element_->next_)
91            this->element_->next_->prev_ = this->element_->prev_;
92        else
93            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
94
95        if (this->element_->prev_)
96            this->element_->prev_->next_ = this->element_->next_;
97        else
98            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
99
100
101        COUT(4) << "*** Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;
102        delete this->element_;
103    }
104
105
106    // ###############################
107    // ###       ObjectList        ###
108    // ###############################
109    //!  The MetaObjectList contains ObjectListElements and their ObjectLists.
110    /**
111        The MetaObjectList is a single-linked list, containing all list-elements and their
112        lists wherein the object that owns the MetaObjectList is registered.
113        This allows much faster deletion of objects because no iteration is needed.
114    */
115    class MetaObjectList
116    {
117        public:
118            MetaObjectList();
119            ~MetaObjectList();
120            template <class T>
121            void add(ObjectList<T>* list, ObjectListElement<T>* element);
122
123            BaseMetaObjectListElement* first_;      //!< The first element in the list
124    };
125
126    /**
127        @brief Adds an ObjectList and an element of that list to the MetaObjectList.
128        @param list The ObjectList wherein the element is
129        @param element The element wherein the object is
130    */
131    template <class T>
132    void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element)
133    {
134        BaseMetaObjectListElement* temp = this->first_;
135        this->first_ = new MetaObjectListElement<T>(list, element);
136        this->first_->next_ = temp;
137    }
138}
139
140#endif /* _MetaObjectList_H__ */
Note: See TracBrowser for help on using the repository browser.