Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/core/ObjectListBase.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.1 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.cc
31    @brief Implementation 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#include <set>
38
39#include "CorePrereqs.h"
40
41#include "ObjectListBase.h"
42#include "Identifier.h"
43#include "IteratorBase.h"
44
45namespace orxonox
46{
47    /**
48        @brief Constructor: Sets default values.
49    */
50    ObjectListBase::ObjectListBase(Identifier* identifier)
51    {
52        this->identifier_ = identifier;
53        this->first_ = 0;
54        this->last_ = 0;
55    }
56
57    /**
58        @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.
59    */
60    ObjectListBase::~ObjectListBase()
61    {
62        ObjectListBaseElement* temp;
63        while (this->first_)
64        {
65            temp = this->first_->next_;
66            delete this->first_;
67            this->first_ = temp;
68        }
69    }
70
71    /**
72        @brief Increases all Iterators that currently point on the given element (because it gets removed).
73        @param element The element that gets removed
74    */
75    void ObjectListBase::notifyIterators(ObjectListBaseElement* element)
76    {
77        for (std::set<IteratorBase*>::iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)
78            if ((*(*(*it))) == element->object_)
79                ++(*(*it));
80    }
81
82    /**
83        @brief Adds a new object to the end of the list.
84        @param object The object to add
85        @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object
86    */
87    ObjectListBaseElement* ObjectListBase::add(OrxonoxClass* object)
88    {
89        if (!this->last_)
90        {
91            // If the list is empty
92            this->last_ = new ObjectListBaseElement(object);
93            this->first_ = this->last_; // There's only one object in the list now
94        }
95        else
96        {
97            // If the list isn't empty
98            ObjectListBaseElement* temp = this->last_;
99            this->last_ = new ObjectListBaseElement(object);
100            this->last_->prev_ = temp;
101            temp->next_ = this->last_;
102        }
103
104        return this->last_;
105    }
106}
Note: See TracBrowser for help on using the repository browser.