[3302] | 1 | |
---|
| 2 | |
---|
[4591] | 3 | /* |
---|
[3302] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[6640] | 15 | co-programmer: Benjamin Grauer |
---|
[3302] | 16 | */ |
---|
[5439] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE |
---|
[3302] | 18 | |
---|
| 19 | #include "base_object.h" |
---|
[4747] | 20 | |
---|
[7193] | 21 | #include "util/loading/load_param.h" |
---|
[3302] | 22 | |
---|
[9715] | 23 | ObjectListDefinition(BaseObject); |
---|
[9691] | 24 | |
---|
[3302] | 25 | /** |
---|
[6280] | 26 | * @brief sets the name from a LoadXML-Element |
---|
[9724] | 27 | * @param objectName: The name of the Object. |
---|
[5439] | 28 | */ |
---|
[7661] | 29 | BaseObject::BaseObject(const std::string& objectName) |
---|
[3531] | 30 | { |
---|
[6276] | 31 | this->className = "BaseObject"; |
---|
[4435] | 32 | |
---|
[7661] | 33 | this->objectName = objectName; |
---|
[6517] | 34 | this->xmlElem = NULL; |
---|
[4436] | 35 | |
---|
[7429] | 36 | //ClassList::addToClassList(this, this->classID, "BaseObject"); |
---|
[3531] | 37 | } |
---|
[3302] | 38 | |
---|
| 39 | /** |
---|
[6280] | 40 | * @brief standard deconstructor |
---|
[3302] | 41 | */ |
---|
[4591] | 42 | BaseObject::~BaseObject () |
---|
[3531] | 43 | { |
---|
[9715] | 44 | /// Remove from the ObjectLists |
---|
[9684] | 45 | ClassList::iterator it; |
---|
| 46 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
| 47 | { |
---|
| 48 | (*it)._objectList->unregisterObject((*it)._iterator); |
---|
| 49 | delete (*it)._iterator; |
---|
| 50 | } |
---|
[4747] | 51 | |
---|
[6517] | 52 | if (this->xmlElem != NULL) |
---|
| 53 | delete this->xmlElem; |
---|
[5447] | 54 | } |
---|
[3302] | 55 | |
---|
[4436] | 56 | /** |
---|
[6280] | 57 | * @brief loads parameters |
---|
[4836] | 58 | * @param root the element to load from |
---|
[5439] | 59 | */ |
---|
[4436] | 60 | void BaseObject::loadParams(const TiXmlElement* root) |
---|
| 61 | { |
---|
[9406] | 62 | // all loadParams should arrive here, and be tested for (root != NULL) |
---|
[6517] | 63 | assert (root != NULL); |
---|
| 64 | |
---|
[9406] | 65 | // copy the xml-element for to know how it was loaded. |
---|
[6517] | 66 | if (this->xmlElem != NULL) |
---|
| 67 | delete this->xmlElem; |
---|
| 68 | this->xmlElem = root->Clone(); |
---|
[9406] | 69 | |
---|
[4436] | 70 | // name setup |
---|
[5671] | 71 | LoadParam(root, "name", this, BaseObject, setName) |
---|
[5645] | 72 | .describe("the Name of the Object."); |
---|
[4436] | 73 | } |
---|
[4321] | 74 | |
---|
| 75 | /** |
---|
[6280] | 76 | * @brief set the name of the Object |
---|
[9406] | 77 | * @param objectName The new name of the Object. |
---|
[4591] | 78 | */ |
---|
[7221] | 79 | void BaseObject::setName (const std::string& objectName) |
---|
[4435] | 80 | { |
---|
[7221] | 81 | this->objectName = objectName; |
---|
[4435] | 82 | } |
---|
[4592] | 83 | |
---|
[6281] | 84 | |
---|
[6280] | 85 | /** |
---|
[9684] | 86 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
| 87 | * @param objectList The ObjectList this should be a member of (by Pointer-comparison). |
---|
| 88 | * @return True if found, false if not. |
---|
[6280] | 89 | */ |
---|
[9715] | 90 | bool BaseObject::isA(const ObjectListBase& objectList) const |
---|
[6280] | 91 | { |
---|
[9684] | 92 | ClassList::const_iterator it; |
---|
| 93 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
| 94 | if ((*it)._objectList == &objectList) |
---|
| 95 | return true; |
---|
| 96 | return false; |
---|
[6280] | 97 | } |
---|
[4592] | 98 | |
---|
[9686] | 99 | |
---|
[4592] | 100 | /** |
---|
[9684] | 101 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
[9724] | 102 | * @param classID The ClassID this should be a member of (by Pointer-comparison). |
---|
[9686] | 103 | * @return True if found, false if not. |
---|
| 104 | */ |
---|
[9715] | 105 | bool BaseObject::isA(const ClassID& classID) const |
---|
[9686] | 106 | { |
---|
| 107 | ClassList::const_iterator it; |
---|
| 108 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
| 109 | if (*(*it)._objectList == classID) |
---|
| 110 | return true; |
---|
| 111 | return false; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
[9684] | 116 | * @param classID The ClassID of the class this should be a member of. |
---|
| 117 | * @return True if found, false if not. |
---|
| 118 | */ |
---|
| 119 | bool BaseObject::isA(int classID) const |
---|
[4592] | 120 | { |
---|
[9684] | 121 | ClassList::const_iterator it; |
---|
| 122 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
| 123 | if (*(*it)._objectList == classID) |
---|
[4594] | 124 | return true; |
---|
[4592] | 125 | return false; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | /** |
---|
[9684] | 129 | * @brief Seeks in the Inheritance if it matches objectList. |
---|
| 130 | * @param className The ClassName of the class this should be a member of. |
---|
| 131 | * @return True if found, false if not. |
---|
[5513] | 132 | */ |
---|
[9684] | 133 | bool BaseObject::isA(const std::string& className) const |
---|
[5513] | 134 | { |
---|
[9684] | 135 | ClassList::const_iterator it; |
---|
| 136 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
| 137 | if (*(*it)._objectList == className) |
---|
| 138 | return true; |
---|
| 139 | return false; |
---|
[5513] | 140 | } |
---|
| 141 | |
---|
[6280] | 142 | |
---|
[9724] | 143 | /** |
---|
| 144 | * @brief This is for debug purposes, to see the Inheritances of this Object and its classes. |
---|
| 145 | * |
---|
| 146 | * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency. |
---|
| 147 | */ |
---|
[9684] | 148 | void BaseObject::listInheritance() const |
---|
[5626] | 149 | { |
---|
[9684] | 150 | PRINT(0)("Listing inheritance diagram for ....: "); |
---|
| 151 | ClassList::const_iterator it; |
---|
| 152 | for (it = this->_classes.begin(); it != this->_classes.end(); ++it) |
---|
| 153 | PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id()); |
---|
| 154 | PRINT(0)("\n"); |
---|
| 155 | |
---|
[5626] | 156 | } |
---|