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