[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 |
---|
[9567] | 31 | @brief Implementation of Identifiable. |
---|
[1505] | 32 | */ |
---|
| 33 | |
---|
[9565] | 34 | #include "Identifiable.h" |
---|
[3196] | 35 | |
---|
[6105] | 36 | #include <cassert> |
---|
[9563] | 37 | #include "core/object/MetaObjectList.h" |
---|
| 38 | #include "core/object/Context.h" |
---|
[1505] | 39 | #include "Identifier.h" |
---|
| 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[7401] | 43 | /** |
---|
| 44 | @brief Constructor: Sets the default values. |
---|
| 45 | */ |
---|
[9565] | 46 | Identifiable::Identifiable() |
---|
[1505] | 47 | { |
---|
[1747] | 48 | this->identifier_ = 0; |
---|
| 49 | this->parents_ = 0; |
---|
[1505] | 50 | this->metaList_ = new MetaObjectList(); |
---|
[6417] | 51 | // Optimisation |
---|
| 52 | this->objectPointers_.reserve(6); |
---|
[1505] | 53 | } |
---|
| 54 | |
---|
[7401] | 55 | /** |
---|
[9565] | 56 | @brief Destructor: Removes the object from the object-lists |
---|
[7401] | 57 | */ |
---|
[9565] | 58 | Identifiable::~Identifiable() |
---|
[1505] | 59 | { |
---|
[5929] | 60 | // if (!this->requestedDestruction_) |
---|
[8858] | 61 | // orxout(internal_warning) << "Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << endl; |
---|
[5929] | 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_; |
---|
| 68 | } |
---|
| 69 | |
---|
[7401] | 70 | /** |
---|
| 71 | @brief Removes this object from the object-lists. |
---|
| 72 | */ |
---|
[9565] | 73 | void Identifiable::unregisterObject() |
---|
[6417] | 74 | { |
---|
| 75 | if (this->metaList_) |
---|
| 76 | delete this->metaList_; |
---|
| 77 | this->metaList_ = 0; |
---|
| 78 | } |
---|
| 79 | |
---|
[7401] | 80 | /// Returns true if the object's class is of the given type or a derivative. |
---|
[9565] | 81 | bool Identifiable::isA(const Identifier* identifier) |
---|
[1505] | 82 | { return this->getIdentifier()->isA(identifier); } |
---|
[7401] | 83 | /// Returns true if the object's class is exactly of the given type. |
---|
[9565] | 84 | bool Identifiable::isExactlyA(const Identifier* identifier) |
---|
[1505] | 85 | { return this->getIdentifier()->isExactlyA(identifier); } |
---|
[7401] | 86 | /// Returns true if the object's class is a child of the given type. |
---|
[9565] | 87 | bool Identifiable::isChildOf(const Identifier* identifier) |
---|
[1505] | 88 | { return this->getIdentifier()->isChildOf(identifier); } |
---|
[7401] | 89 | /// Returns true if the object's class is a direct child of the given type. |
---|
[9565] | 90 | bool Identifiable::isDirectChildOf(const Identifier* identifier) |
---|
[1505] | 91 | { return this->getIdentifier()->isDirectChildOf(identifier); } |
---|
[7401] | 92 | /// Returns true if the object's class is a parent of the given type. |
---|
[9565] | 93 | bool Identifiable::isParentOf(const Identifier* identifier) |
---|
[1505] | 94 | { return this->getIdentifier()->isParentOf(identifier); } |
---|
[7401] | 95 | /// Returns true if the object's class is a direct parent of the given type. |
---|
[9565] | 96 | bool Identifiable::isDirectParentOf(const Identifier* identifier) |
---|
[1505] | 97 | { return this->getIdentifier()->isDirectParentOf(identifier); } |
---|
| 98 | |
---|
| 99 | |
---|
[7401] | 100 | /// Returns true if the object's class is of the given type or a derivative. |
---|
[9565] | 101 | bool Identifiable::isA(const Identifiable* object) |
---|
[1505] | 102 | { return this->getIdentifier()->isA(object->getIdentifier()); } |
---|
[7401] | 103 | /// Returns true if the object's class is exactly of the given type. |
---|
[9565] | 104 | bool Identifiable::isExactlyA(const Identifiable* object) |
---|
[1505] | 105 | { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } |
---|
[7401] | 106 | /// Returns true if the object's class is a child of the given type. |
---|
[9565] | 107 | bool Identifiable::isChildOf(const Identifiable* object) |
---|
[1505] | 108 | { return this->getIdentifier()->isChildOf(object->getIdentifier()); } |
---|
[7401] | 109 | /// Returns true if the object's class is a direct child of the given type. |
---|
[9565] | 110 | bool Identifiable::isDirectChildOf(const Identifiable* object) |
---|
[1505] | 111 | { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } |
---|
[7401] | 112 | /// Returns true if the object's class is a parent of the given type. |
---|
[9565] | 113 | bool Identifiable::isParentOf(const Identifiable* object) |
---|
[1505] | 114 | { return this->getIdentifier()->isParentOf(object->getIdentifier()); } |
---|
[7401] | 115 | /// Returns true if the object's class is a direct child of the given type. |
---|
[9565] | 116 | bool Identifiable::isDirectParentOf(const Identifiable* object) |
---|
[1505] | 117 | { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } |
---|
| 118 | } |
---|