Changeset 9869 in orxonox.OLD for trunk/src/lib/lang/base_object.cc
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/base_object.cc
r9406 r9869 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 19 17 #include "base_object.h" 20 18 19 #include "util/debug.h" 21 20 #include "util/loading/load_param.h" 22 #include "class_list.h" 21 22 ObjectListDefinition(BaseObject); 23 23 24 24 /** 25 25 * @brief sets the name from a LoadXML-Element 26 * @param root the element to load from26 * @param objectName: The name of the Object. 27 27 */ 28 28 BaseObject::BaseObject(const std::string& objectName) 29 29 { 30 this->classID = CL_BASE_OBJECT;31 30 this->className = "BaseObject"; 32 31 33 32 this->objectName = objectName; 34 this->classList = NULL;35 33 this->xmlElem = NULL; 36 37 //ClassList::addToClassList(this, this->classID, "BaseObject"); 34 this->registerObject(this, BaseObject::_objectList); 38 35 } 39 36 … … 43 40 BaseObject::~BaseObject () 44 41 { 45 ClassList::removeFromClassList(this); 42 /// Remove from the ObjectLists 43 ClassEntries::iterator it; 44 PRINTF(5)("Deleting Object of type %s::%s\n", this->getClassCName(), getCName()); 45 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 46 { 47 if (ORX_DEBUG >= 5) 48 assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this)); 49 (*it)._objectList->unregisterObject((*it)._iterator); 50 delete (*it)._iterator; 51 } 46 52 47 53 if (this->xmlElem != NULL) … … 69 75 70 76 /** 71 * @brief sets the class identifiers72 * @param id a number for the class from class_id.h enumeration73 * @param className the class name74 */75 void BaseObject::setClassID(ClassID classID, const std::string& className)76 {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 ));79 80 this->leafClassID = classID;81 this->classID |= (long)classID;82 this->className = className;83 84 this->classList = ClassList::addToClassList(this, classID, this->classID, className);85 }86 87 88 /**89 77 * @brief set the name of the Object 90 78 * @param objectName The new name of the Object. … … 97 85 98 86 /** 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()); 87 * @brief Seeks in the Inheritance if it matches objectList. 88 * @param objectList The ObjectList this should be a member of (by Pointer-comparison). 89 * @return True if found, false if not. 104 90 */ 105 const ClassID& BaseObject::getLeafClassID() const91 bool BaseObject::isA(const ObjectListBase& objectList) const 106 92 { 107 return this->leafClassID; 108 } 109 110 111 112 /** 113 * @brief checks if the class is a classID 114 * @param classID the Identifier to check for 115 * @returns true if it is, false otherwise 116 */ 117 bool BaseObject::isA (ClassID classID) const 118 { 119 // if classID is a derivable object from a SUPERCLASS 120 if (classID & CL_MASK_SUPER_CLASS) 121 { 122 if( likely(this->classID & classID)) 93 ClassEntries::const_iterator it; 94 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 95 if ((*it)._objectList == &objectList) 123 96 return true; 124 }125 // if classID is a SubSuperClass, and126 else if (classID & CL_MASK_SUBSUPER_CLASS)127 {128 if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&129 this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))130 return true;131 }132 // if classID is a LOWLEVEL-class133 else134 {135 if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))136 return true;137 }138 97 return false; 139 98 } 140 99 141 100 101 /** 102 * @brief Seeks in the Inheritance if it matches objectList. 103 * @param classID The ClassID this should be a member of (by Pointer-comparison). 104 * @return True if found, false if not. 105 */ 106 bool BaseObject::isA(const ClassID& classID) const 107 { 108 ClassEntries::const_iterator it; 109 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 110 if (*(*it)._objectList == classID) 111 return true; 112 return false; 113 } 142 114 143 115 /** 144 * @brief checks if the class is a classID145 * @param classID the Identifier to check for146 * @return s true if it is, false otherwise116 * @brief Seeks in the Inheritance if it matches objectList. 117 * @param classID The ClassID of the class this should be a member of. 118 * @return True if found, false if not. 147 119 */ 148 bool BaseObject::isA (const std::string& className) const120 bool BaseObject::isA(int classID) const 149 121 { 150 ClassID classID = ClassList::StringToID(className); 151 if (classID != CL_NULL) 152 return this->isA(classID); 153 else 154 return false; 122 ClassEntries::const_iterator it; 123 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 124 if (*(*it)._objectList == classID) 125 126 return true; 127 return false; 128 } 129 130 /** 131 * @brief Seeks in the Inheritance if it matches objectList. 132 * @param className The ClassName of the class this should be a member of. 133 * @return True if found, false if not. 134 */ 135 bool BaseObject::isA(const std::string& className) const 136 { 137 ClassEntries::const_iterator it; 138 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 139 if (*(*it)._objectList == className) 140 return true; 141 return false; 155 142 } 156 143 157 144 158 145 /** 159 * @brief compares the ObjectName with an external name160 * @param objectName: the name to check.161 * @returns true on match, false otherwise.146 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes. 147 * 148 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency. 162 149 */ 163 bool BaseObject::operator==(const std::string& objectName) const150 void BaseObject::listInheritance() const 164 151 { 165 return (this->objectName == objectName); 152 PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName()); 153 ClassEntries::const_iterator it; 154 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 155 PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id()); 156 PRINT(0)("\n"); 157 166 158 } 167
Note: See TracChangeset
for help on using the changeset viewer.