[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" |
---|
[4747] | 22 | #include "class_list.h" |
---|
[3302] | 23 | |
---|
| 24 | /** |
---|
[6280] | 25 | * @brief sets the name from a LoadXML-Element |
---|
[4836] | 26 | * @param root the element to load from |
---|
[5439] | 27 | */ |
---|
[7661] | 28 | BaseObject::BaseObject(const std::string& objectName) |
---|
[3531] | 29 | { |
---|
[7221] | 30 | this->classID = CL_BASE_OBJECT; |
---|
[6276] | 31 | this->className = "BaseObject"; |
---|
[4435] | 32 | |
---|
[7661] | 33 | this->objectName = objectName; |
---|
[6280] | 34 | this->classList = NULL; |
---|
[6517] | 35 | this->xmlElem = NULL; |
---|
[4436] | 36 | |
---|
[7429] | 37 | //ClassList::addToClassList(this, this->classID, "BaseObject"); |
---|
[3531] | 38 | } |
---|
[3302] | 39 | |
---|
| 40 | /** |
---|
[6280] | 41 | * @brief standard deconstructor |
---|
[3302] | 42 | */ |
---|
[4591] | 43 | BaseObject::~BaseObject () |
---|
[3531] | 44 | { |
---|
[4747] | 45 | ClassList::removeFromClassList(this); |
---|
| 46 | |
---|
[6517] | 47 | if (this->xmlElem != NULL) |
---|
| 48 | delete this->xmlElem; |
---|
[5447] | 49 | } |
---|
[3302] | 50 | |
---|
[4436] | 51 | /** |
---|
[6280] | 52 | * @brief loads parameters |
---|
[4836] | 53 | * @param root the element to load from |
---|
[5439] | 54 | */ |
---|
[4436] | 55 | void BaseObject::loadParams(const TiXmlElement* root) |
---|
| 56 | { |
---|
[9347] | 57 | // all loadParams should arrive here, and be tested for (root != NULL) |
---|
[6517] | 58 | assert (root != NULL); |
---|
| 59 | |
---|
[9347] | 60 | // copy the xml-element for to know how it was loaded. |
---|
[6517] | 61 | if (this->xmlElem != NULL) |
---|
| 62 | delete this->xmlElem; |
---|
| 63 | this->xmlElem = root->Clone(); |
---|
[9347] | 64 | |
---|
[4436] | 65 | // name setup |
---|
[5671] | 66 | LoadParam(root, "name", this, BaseObject, setName) |
---|
[5645] | 67 | .describe("the Name of the Object."); |
---|
[4436] | 68 | } |
---|
[4321] | 69 | |
---|
| 70 | /** |
---|
[6280] | 71 | * @brief sets the class identifiers |
---|
[4836] | 72 | * @param id a number for the class from class_id.h enumeration |
---|
| 73 | * @param className the class name |
---|
[4321] | 74 | */ |
---|
[7221] | 75 | void BaseObject::setClassID(ClassID classID, const std::string& className) |
---|
[4320] | 76 | { |
---|
[6282] | 77 | //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID); |
---|
| 78 | assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA )); |
---|
[6276] | 79 | |
---|
[7954] | 80 | this->leafClassID = classID; |
---|
[5791] | 81 | this->classID |= (long)classID; |
---|
[4320] | 82 | this->className = className; |
---|
[4747] | 83 | |
---|
[6280] | 84 | this->classList = ClassList::addToClassList(this, classID, this->classID, className); |
---|
[4320] | 85 | } |
---|
[4318] | 86 | |
---|
[6280] | 87 | |
---|
[4435] | 88 | /** |
---|
[6280] | 89 | * @brief set the name of the Object |
---|
[9347] | 90 | * @param objectName The new name of the Object. |
---|
[4591] | 91 | */ |
---|
[7221] | 92 | void BaseObject::setName (const std::string& objectName) |
---|
[4435] | 93 | { |
---|
[7221] | 94 | this->objectName = objectName; |
---|
[4435] | 95 | } |
---|
[4592] | 96 | |
---|
[6281] | 97 | |
---|
[6280] | 98 | /** |
---|
| 99 | * @brief queries for the ClassID of the Leaf Class (the last made class of this type |
---|
| 100 | * @returns the ClassID of the Leaf Class (e.g. the ID of the Class) |
---|
| 101 | * |
---|
| 102 | * the returned ID can be used to generate new Objects of the same type through |
---|
| 103 | * Factory::fabricate(Object->getLeafClassID()); |
---|
| 104 | */ |
---|
[7954] | 105 | const ClassID& BaseObject::getLeafClassID() const |
---|
[6280] | 106 | { |
---|
[7954] | 107 | return this->leafClassID; |
---|
[6280] | 108 | } |
---|
[4592] | 109 | |
---|
[6280] | 110 | |
---|
| 111 | |
---|
[4592] | 112 | /** |
---|
[6280] | 113 | * @brief checks if the class is a classID |
---|
[4836] | 114 | * @param classID the Identifier to check for |
---|
| 115 | * @returns true if it is, false otherwise |
---|
[4592] | 116 | */ |
---|
[6077] | 117 | bool BaseObject::isA (ClassID classID) const |
---|
[4592] | 118 | { |
---|
[4837] | 119 | // if classID is a derivable object from a SUPERCLASS |
---|
| 120 | if (classID & CL_MASK_SUPER_CLASS) |
---|
[4594] | 121 | { |
---|
[4837] | 122 | if( likely(this->classID & classID)) |
---|
[4594] | 123 | return true; |
---|
[4837] | 124 | } |
---|
| 125 | // if classID is a SubSuperClass, and |
---|
| 126 | else if (classID & CL_MASK_SUBSUPER_CLASS) |
---|
| 127 | { |
---|
[7123] | 128 | if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) && |
---|
[5915] | 129 | this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB)) |
---|
[4837] | 130 | return true; |
---|
| 131 | } |
---|
| 132 | // if classID is a LOWLEVEL-class |
---|
[4594] | 133 | else |
---|
| 134 | { |
---|
[4837] | 135 | if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)) |
---|
[4594] | 136 | return true; |
---|
| 137 | } |
---|
[4592] | 138 | return false; |
---|
| 139 | } |
---|
| 140 | |
---|
[6280] | 141 | |
---|
| 142 | |
---|
[4592] | 143 | /** |
---|
[6280] | 144 | * @brief checks if the class is a classID |
---|
[5513] | 145 | * @param classID the Identifier to check for |
---|
| 146 | * @returns true if it is, false otherwise |
---|
| 147 | */ |
---|
[7221] | 148 | bool BaseObject::isA (const std::string& className) const |
---|
[5513] | 149 | { |
---|
[6077] | 150 | ClassID classID = ClassList::StringToID(className); |
---|
[5513] | 151 | if (classID != CL_NULL) |
---|
| 152 | return this->isA(classID); |
---|
[8145] | 153 | else |
---|
| 154 | return false; |
---|
[5513] | 155 | } |
---|
| 156 | |
---|
[6280] | 157 | |
---|
[5626] | 158 | /** |
---|
[6280] | 159 | * @brief compares the ObjectName with an external name |
---|
[5626] | 160 | * @param objectName: the name to check. |
---|
| 161 | * @returns true on match, false otherwise. |
---|
| 162 | */ |
---|
[9347] | 163 | bool BaseObject::operator==(const std::string& objectName) const |
---|
[5626] | 164 | { |
---|
[7221] | 165 | return (this->objectName == objectName); |
---|
[5626] | 166 | } |
---|
[5513] | 167 | |
---|