| [1505] | 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 |
|---|
| [1505] | 31 | @brief Implementation of the OrxonoxClass Class. |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | #include "OrxonoxClass.h" |
|---|
| [3196] | 35 | |
|---|
| [6105] | 36 | #include <cassert> |
|---|
| [1505] | 37 | #include "MetaObjectList.h" |
|---|
| 38 | #include "Identifier.h" |
|---|
| [5929] | 39 | #include "WeakPtr.h" |
|---|
| [1505] | 40 | |
|---|
| 41 | namespace orxonox |
|---|
| 42 | { |
|---|
| 43 | /** @brief Constructor: Sets the default values. */ |
|---|
| [1747] | 44 | OrxonoxClass::OrxonoxClass() |
|---|
| [1505] | 45 | { |
|---|
| [1747] | 46 | this->identifier_ = 0; |
|---|
| 47 | this->parents_ = 0; |
|---|
| [1505] | 48 | this->metaList_ = new MetaObjectList(); |
|---|
| [5929] | 49 | this->referenceCount_ = 0; |
|---|
| 50 | this->requestedDestruction_ = false; |
|---|
| [6417] | 51 | // Optimisation |
|---|
| 52 | this->objectPointers_.reserve(6); |
|---|
| [1505] | 53 | } |
|---|
| 54 | |
|---|
| 55 | /** @brief Destructor: Deletes, if existing, the list of the parents. */ |
|---|
| 56 | OrxonoxClass::~OrxonoxClass() |
|---|
| 57 | { |
|---|
| [5929] | 58 | // if (!this->requestedDestruction_) |
|---|
| [6417] | 59 | // COUT(2) << "Warning: Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << std::endl; |
|---|
| [5929] | 60 | |
|---|
| 61 | assert(this->referenceCount_ <= 0); |
|---|
| 62 | |
|---|
| [6417] | 63 | this->unregisterObject(); |
|---|
| [1505] | 64 | |
|---|
| 65 | // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class |
|---|
| 66 | if (this->parents_) |
|---|
| 67 | delete this->parents_; |
|---|
| [6417] | 68 | |
|---|
| [5929] | 69 | // reset all weak pointers pointing to this object |
|---|
| 70 | for (std::set<WeakPtr<OrxonoxClass>*>::iterator it = this->weakPointers_.begin(); it != this->weakPointers_.end(); ) |
|---|
| 71 | (*(it++))->objectDeleted(); |
|---|
| [1505] | 72 | } |
|---|
| 73 | |
|---|
| [5929] | 74 | /** @brief Deletes the object if no smart pointers point to this object. Otherwise schedules the object to be deleted as soon as possible. */ |
|---|
| 75 | void OrxonoxClass::destroy() |
|---|
| 76 | { |
|---|
| [6105] | 77 | assert(this); // Just in case someone tries to delete a NULL pointer |
|---|
| [5929] | 78 | this->requestedDestruction_ = true; |
|---|
| 79 | if (this->referenceCount_ == 0) |
|---|
| [6417] | 80 | { |
|---|
| 81 | this->preDestroy(); |
|---|
| 82 | if (this->referenceCount_ == 0) |
|---|
| 83 | delete this; |
|---|
| 84 | } |
|---|
| [5929] | 85 | } |
|---|
| 86 | |
|---|
| [6417] | 87 | void OrxonoxClass::unregisterObject() |
|---|
| 88 | { |
|---|
| 89 | if (this->metaList_) |
|---|
| 90 | delete this->metaList_; |
|---|
| 91 | this->metaList_ = 0; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| [1505] | 94 | /** @brief Returns true if the objects class is of the given type or a derivative. */ |
|---|
| 95 | bool OrxonoxClass::isA(const Identifier* identifier) |
|---|
| 96 | { return this->getIdentifier()->isA(identifier); } |
|---|
| 97 | /** @brief Returns true if the objects class is exactly of the given type. */ |
|---|
| 98 | bool OrxonoxClass::isExactlyA(const Identifier* identifier) |
|---|
| 99 | { return this->getIdentifier()->isExactlyA(identifier); } |
|---|
| 100 | /** @brief Returns true if the objects class is a child of the given type. */ |
|---|
| 101 | bool OrxonoxClass::isChildOf(const Identifier* identifier) |
|---|
| 102 | { return this->getIdentifier()->isChildOf(identifier); } |
|---|
| 103 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 104 | bool OrxonoxClass::isDirectChildOf(const Identifier* identifier) |
|---|
| 105 | { return this->getIdentifier()->isDirectChildOf(identifier); } |
|---|
| 106 | /** @brief Returns true if the objects class is a parent of the given type. */ |
|---|
| 107 | bool OrxonoxClass::isParentOf(const Identifier* identifier) |
|---|
| 108 | { return this->getIdentifier()->isParentOf(identifier); } |
|---|
| 109 | /** @brief Returns true if the objects class is a direct parent of the given type. */ |
|---|
| 110 | bool OrxonoxClass::isDirectParentOf(const Identifier* identifier) |
|---|
| 111 | { return this->getIdentifier()->isDirectParentOf(identifier); } |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | /** @brief Returns true if the objects class is of the given type or a derivative. */ |
|---|
| 115 | bool OrxonoxClass::isA(const OrxonoxClass* object) |
|---|
| 116 | { return this->getIdentifier()->isA(object->getIdentifier()); } |
|---|
| 117 | /** @brief Returns true if the objects class is exactly of the given type. */ |
|---|
| 118 | bool OrxonoxClass::isExactlyA(const OrxonoxClass* object) |
|---|
| 119 | { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } |
|---|
| 120 | /** @brief Returns true if the objects class is a child of the given type. */ |
|---|
| 121 | bool OrxonoxClass::isChildOf(const OrxonoxClass* object) |
|---|
| 122 | { return this->getIdentifier()->isChildOf(object->getIdentifier()); } |
|---|
| 123 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 124 | bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object) |
|---|
| 125 | { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } |
|---|
| 126 | /** @brief Returns true if the objects class is a parent of the given type. */ |
|---|
| 127 | bool OrxonoxClass::isParentOf(const OrxonoxClass* object) |
|---|
| 128 | { return this->getIdentifier()->isParentOf(object->getIdentifier()); } |
|---|
| 129 | /** @brief Returns true if the objects class is a direct child of the given type. */ |
|---|
| 130 | bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object) |
|---|
| 131 | { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } |
|---|
| 132 | } |
|---|