Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/core/MetaObjectList.cc @ 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: 3.3 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.cc
31    @brief Implementation of the MetaObjectList class.
32*/
33
34#include "MetaObjectList.h"
35#include "Debug.h"
36
37namespace orxonox
38{
39    // ###############################
40    // ###  MetaObjectListElement  ###
41    // ###############################
42    /**
43        @brief Destructor: Removes the ObjectListBaseElement from the ObjectListBase by linking next_ and prev_ of the ObjectListBaseElement.
44    */
45    MetaObjectListElement::~MetaObjectListElement()
46    {
47        COUT(5) << "*** MetaObjectList: Removing Object from " << this->list_->getIdentifier()->getName() << "-list." << std::endl;
48        this->list_->notifyIterators(this->element_);
49
50        if (this->element_->next_)
51            this->element_->next_->prev_ = this->element_->prev_;
52        else
53            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
54
55        if (this->element_->prev_)
56            this->element_->prev_->next_ = this->element_->next_;
57        else
58            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
59
60        delete this->element_;
61    }
62
63
64    // ###############################
65    // ###     MetaObjectList      ###
66    // ###############################
67    /**
68        @brief Constructor: Sets first_ to zero.
69    */
70    MetaObjectList::MetaObjectList()
71    {
72        this->first_ = 0;
73    }
74
75    /**
76        @brief Destructor: Removes all elements from the list, causing them to remove the stored ObjectListElement from the ObjectList.
77    */
78    MetaObjectList::~MetaObjectList()
79    {
80        MetaObjectListElement* temp;
81        while (this->first_)
82        {
83            temp = this->first_->next_;
84            delete this->first_;
85            this->first_ = temp;
86        }
87    }
88
89    /**
90        @brief Adds an ObjectList and an element of that list to the MetaObjectList.
91        @param list The ObjectList wherein the element is
92        @param element The element wherein the object is
93    */
94    void MetaObjectList::add(ObjectListBase* list, ObjectListBaseElement* element)
95    {
96        MetaObjectListElement* temp = this->first_;
97        this->first_ = new MetaObjectListElement(list, element);
98        this->first_->next_ = temp;
99    }
100}
Note: See TracBrowser for help on using the repository browser.