/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: Benjamin Grauer */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE #include "base_object.h" #include "util/loading/load_param.h" #include "class_list.h" /** * @brief sets the name from a LoadXML-Element * @param root the element to load from */ BaseObject::BaseObject(const std::string& objectName) { this->classID = CL_BASE_OBJECT; this->className = "BaseObject"; this->objectName = objectName; this->classList = NULL; this->xmlElem = NULL; //ClassList::addToClassList(this, this->classID, "BaseObject"); } /** * @brief standard deconstructor */ BaseObject::~BaseObject () { ClassList::removeFromClassList(this); if (this->xmlElem != NULL) delete this->xmlElem; } /** * @brief loads parameters * @param root the element to load from */ void BaseObject::loadParams(const TiXmlElement* root) { // all loadParams should arrive here, and be tested for (root != NULL) assert (root != NULL); // copy the xml-element for to know how it was loaded. if (this->xmlElem != NULL) delete this->xmlElem; this->xmlElem = root->Clone(); // name setup LoadParam(root, "name", this, BaseObject, setName) .describe("the Name of the Object."); } /** * @brief sets the class identifiers * @param id a number for the class from class_id.h enumeration * @param className the class name */ void BaseObject::setClassID(ClassID classID, const std::string& className) { //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID); assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA )); this->leafClassID = classID; this->classID |= (long)classID; this->className = className; this->classList = ClassList::addToClassList(this, classID, this->classID, className); } /** * @brief set the name of the Object * @param objectName The new name of the Object. */ void BaseObject::setName (const std::string& objectName) { this->objectName = objectName; } /** * @brief queries for the ClassID of the Leaf Class (the last made class of this type * @returns the ClassID of the Leaf Class (e.g. the ID of the Class) * * the returned ID can be used to generate new Objects of the same type through * Factory::fabricate(Object->getLeafClassID()); */ const ClassID& BaseObject::getLeafClassID() const { return this->leafClassID; } /** * @brief checks if the class is a classID * @param classID the Identifier to check for * @returns true if it is, false otherwise */ bool BaseObject::isA (ClassID classID) const { // if classID is a derivable object from a SUPERCLASS if (classID & CL_MASK_SUPER_CLASS) { if( likely(this->classID & classID)) return true; } // if classID is a SubSuperClass, and else if (classID & CL_MASK_SUBSUPER_CLASS) { if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) && this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB)) return true; } // if classID is a LOWLEVEL-class else { if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)) return true; } return false; } /** * @brief checks if the class is a classID * @param classID the Identifier to check for * @returns true if it is, false otherwise */ bool BaseObject::isA (const std::string& className) const { ClassID classID = ClassList::StringToID(className); if (classID != CL_NULL) return this->isA(classID); else return false; } /** * @brief compares the ObjectName with an external name * @param objectName: the name to check. * @returns true on match, false otherwise. */ bool BaseObject::operator==(const std::string& objectName) const { return (this->objectName == objectName); }