[1574] | 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 | /** |
---|
[2171] | 30 | @file |
---|
[1574] | 31 | @brief Implementation of the ObjectListBase class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[3196] | 34 | #include "ObjectListBase.h" |
---|
| 35 | |
---|
[1574] | 36 | #include <set> |
---|
| 37 | #include "Identifier.h" |
---|
[1591] | 38 | #include "Iterator.h" |
---|
[3196] | 39 | #include "ObjectListIterator.h" |
---|
[1574] | 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
| 43 | /** |
---|
| 44 | @brief Constructor: Sets default values. |
---|
| 45 | */ |
---|
| 46 | ObjectListBase::ObjectListBase(Identifier* identifier) |
---|
| 47 | { |
---|
| 48 | this->identifier_ = identifier; |
---|
| 49 | this->first_ = 0; |
---|
| 50 | this->last_ = 0; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS. |
---|
| 55 | */ |
---|
| 56 | ObjectListBase::~ObjectListBase() |
---|
| 57 | { |
---|
| 58 | ObjectListBaseElement* temp; |
---|
| 59 | while (this->first_) |
---|
| 60 | { |
---|
| 61 | temp = this->first_->next_; |
---|
| 62 | delete this->first_; |
---|
| 63 | this->first_ = temp; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | @brief Increases all Iterators that currently point on the given element (because it gets removed). |
---|
[7401] | 69 | @param object The object that gets removed |
---|
[1574] | 70 | */ |
---|
[1591] | 71 | void ObjectListBase::notifyIterators(OrxonoxClass* object) const |
---|
[1574] | 72 | { |
---|
[2784] | 73 | for (std::vector<void*>::const_iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it) |
---|
[1591] | 74 | ((Iterator<OrxonoxClass>*)(*it))->incrementIfEqual(object); |
---|
[2784] | 75 | for (std::vector<void*>::const_iterator it = this->objectListIterators_.begin(); it != this->objectListIterators_.end(); ++it) |
---|
[1591] | 76 | ((ObjectListIterator<OrxonoxClass>*)(*it))->incrementIfEqual(object); |
---|
[1574] | 77 | } |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | @brief Adds a new object to the end of the list. |
---|
[7401] | 81 | @param element The element to add |
---|
[1574] | 82 | @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object |
---|
| 83 | */ |
---|
[1591] | 84 | ObjectListBaseElement* ObjectListBase::add(ObjectListBaseElement* element) |
---|
[1574] | 85 | { |
---|
| 86 | if (!this->last_) |
---|
| 87 | { |
---|
| 88 | // If the list is empty |
---|
[1591] | 89 | this->last_ = element; |
---|
[1574] | 90 | this->first_ = this->last_; // There's only one object in the list now |
---|
| 91 | } |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | // If the list isn't empty |
---|
| 95 | ObjectListBaseElement* temp = this->last_; |
---|
[1591] | 96 | this->last_ = element; |
---|
[1574] | 97 | this->last_->prev_ = temp; |
---|
| 98 | temp->next_ = this->last_; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | return this->last_; |
---|
| 102 | } |
---|
| 103 | } |
---|