Changeset 9684 in orxonox.OLD for branches/new_class_id/src/lib/lang
- Timestamp:
- Aug 22, 2006, 1:34:31 AM (19 years ago)
- Location:
- branches/new_class_id/src/lib/lang
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/lang/Makefile.am
r9677 r9684 9 9 libORXlang_a_SOURCES = \ 10 10 base_object.cc \ 11 class_list.cc \12 11 new_class_id.cc \ 13 12 new_object_list.cc … … 15 14 noinst_HEADERS = \ 16 15 base_object.h \ 17 class_list.h \18 16 new_class_id.h \ 19 17 new_object_list.h -
branches/new_class_id/src/lib/lang/base_object.cc
r9406 r9684 20 20 21 21 #include "util/loading/load_param.h" 22 #include "class_list.h"23 22 24 23 /** … … 28 27 BaseObject::BaseObject(const std::string& objectName) 29 28 { 30 this->classID = CL_BASE_OBJECT;31 29 this->className = "BaseObject"; 32 30 33 31 this->objectName = objectName; 34 this->classList = NULL;35 32 this->xmlElem = NULL; 36 33 … … 43 40 BaseObject::~BaseObject () 44 41 { 45 ClassList::removeFromClassList(this); 42 /// Remove from the NewObjectLists 43 ClassList::iterator it; 44 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 45 { 46 (*it)._objectList->unregisterObject((*it)._iterator); 47 delete (*it)._iterator; 48 } 46 49 47 50 if (this->xmlElem != NULL) … … 69 72 70 73 /** 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 74 * @brief set the name of the Object 90 75 * @param objectName The new name of the Object. … … 97 82 98 83 /** 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()); 84 * @brief Seeks in the Inheritance if it matches objectList. 85 * @param objectList The ObjectList this should be a member of (by Pointer-comparison). 86 * @return True if found, false if not. 104 87 */ 105 const ClassID& BaseObject::getLeafClassID() const88 bool BaseObject::isA(const NewObjectListBase& objectList) const 106 89 { 107 return this->leafClassID; 90 ClassList::const_iterator it; 91 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 92 if ((*it)._objectList == &objectList) 93 return true; 94 return false; 108 95 } 109 96 110 97 /** 98 * @brief Seeks in the Inheritance if it matches objectList. 99 * @param classID The ClassID of the class this should be a member of. 100 * @return True if found, false if not. 101 */ 102 bool BaseObject::isA(int classID) const 103 { 104 ClassList::const_iterator it; 105 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 106 if (*(*it)._objectList == classID) 107 return true; 108 return false; 109 } 111 110 112 111 /** 113 * @brief checks if the class is a classID114 * @param class ID the Identifier to check for115 * @return s true if it is, false otherwise116 */117 bool BaseObject::isA (ClassID classID) const112 * @brief Seeks in the Inheritance if it matches objectList. 113 * @param className The ClassName of the class this should be a member of. 114 * @return True if found, false if not. 115 */ 116 bool BaseObject::isA(const std::string& className) const 118 117 { 119 // if classID is a derivable object from a SUPERCLASS 120 if (classID & CL_MASK_SUPER_CLASS) 121 { 122 if( likely(this->classID & classID)) 118 ClassList::const_iterator it; 119 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 120 if (*(*it)._objectList == className) 123 121 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 122 return false; 139 123 } 140 124 141 125 126 void BaseObject::listInheritance() const 127 { 128 PRINT(0)("Listing inheritance diagram for ....: "); 129 ClassList::const_iterator it; 130 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 131 PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id()); 132 PRINT(0)("\n"); 142 133 143 /**144 * @brief checks if the class is a classID145 * @param classID the Identifier to check for146 * @returns true if it is, false otherwise147 */148 bool BaseObject::isA (const std::string& className) const149 {150 ClassID classID = ClassList::StringToID(className);151 if (classID != CL_NULL)152 return this->isA(classID);153 else154 return false;155 134 } 156 157 158 /**159 * @brief compares the ObjectName with an external name160 * @param objectName: the name to check.161 * @returns true on match, false otherwise.162 */163 bool BaseObject::operator==(const std::string& objectName) const164 {165 return (this->objectName == objectName);166 }167 -
branches/new_class_id/src/lib/lang/base_object.h
r9406 r9684 14 14 #define __BASE_OBJECT_H_ 15 15 16 #include " class_id.h"16 #include "new_object_list.h" 17 17 #include "sigslot/slot.h" 18 18 … … 41 41 inline TiXmlNode* getXmlElem() const { return this->xmlElem; }; 42 42 43 / ** @returns the className of the corresponding Object */44 inline const std::string& getClassName() const { return this->className; }43 // /** @returns the className of the corresponding Object */ 44 //inline const std::string& getClassName() const { return this->className; } 45 45 /** @returns the className of the corresponding Object as a C-compliant string (const char*) */ 46 46 inline const char* getClassCName() const { return this->className.c_str(); }; 47 /** @returns the classID of the corresponding Object */ 48 inline int getClassID() const { return this->classID; }; 49 const ClassID& getLeafClassID() const; 47 /** @returns the ClassName of the Topmost Object of the ClassStack */ 48 inline const std::string& getClassName() const { return _classes.front()._objectList->name(); } 50 49 51 bool isA (ClassID classID) const; 52 bool isA (const std::string& className) const; 50 /** @returns the ID of the Topmost object of the ClassStack */ 51 inline int getLeafClassID() const { return _classes.front()._objectList->id(); } 52 53 bool isA(const NewObjectListBase& objectList) const; 54 bool isA(int classID) const; 55 bool isA(const std::string& className) const; 56 57 void listInheritance() const; 53 58 54 59 /** @param classID comparer for a ClassID @returns true on match, false otherwise */ 55 bool operator==(ClassID classID) const { return this->isA(classID); }; 56 bool operator==(const std::string& objectName) const; 60 bool operator==(int classID) const { return this->isA(classID); }; 61 /** @param objectName: the name to check. * @returns true on match, false otherwise. */ 62 bool operator==(const std::string& objectName) const { return this->objectName == objectName;}; 57 63 58 64 protected: 59 void setClassID(ClassID classID, const std::string& className);65 template<class T> void registerObject(T* object, NewObjectList<T>& list); 60 66 61 67 protected: … … 63 69 64 70 private: 65 std::string className; //!< the name of the class66 long classID; //!< this is the id from the class_id.h enumeration67 ClassID leafClassID; //!< The Leaf Class ID68 69 ClassList* classList; //!< Pointer to the ClassList this Object is inside of70 71 71 72 TiXmlNode* xmlElem; //!< The XML Element with wich this Object was loaded(saved). 73 74 ////////////////////////////// 75 //// Type Definition Part //// 76 ////////////////////////////// 77 //! A ClassEntry so we can store Classes inside of Objects 78 struct ClassEntry 79 { 80 /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */ 81 inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {} 82 NewObjectListBase* _objectList; //!< A ObjectList this Object is part of 83 NewObjectListBase::IteratorBase* _iterator; //!< An iterator pointing to the position of the Object inside of the List. 84 }; 85 typedef std::list<ClassEntry> ClassList; //!< Type definition for the List. 86 87 std::string className; //!< the name of the class 88 ClassList _classes; //!< All Classes this object is part of. 89 72 90 }; 73 91 92 93 /** 94 * @brief Registeres an Object of Type T to objectList 95 * @param object The Object to append to the objectList. 96 * @param objectList The ObjectList to append the Object to. 97 * 98 * This function is essential to integrate objects into their designated ObjectList. 99 * Remember if you do not want objects to be stored in Lists (less overhead), 100 * do not attempt to call this function. 101 */ 102 template<class T> 103 inline void BaseObject::registerObject(T* object, NewObjectList<T>& objectList) 104 { 105 this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object))); 106 } 107 74 108 #endif /* __BASE_OBJECT_H_ */ -
branches/new_class_id/src/lib/lang/new_object_list.h
r9682 r9684 16 16 17 17 #define NewObjectListDeclaration(ClassName) \ 18 static NewObjectList<ClassName> objectList 18 public: \ 19 static const NewObjectList<ClassName>& objectList() { return ClassName::_objectList; }; \ 20 private: \ 21 static NewObjectList<ClassName> _objectList 19 22 20 23 #define NewObjectListDefinitionID(ClassName, ID) \ 21 NewObjectList<ClassName> ClassName:: objectList(#ClassName, ID)24 NewObjectList<ClassName> ClassName::_objectList(#ClassName, ID) 22 25 23 26 … … 157 160 T* NewObjectList<T>::getObject(const std::string& name) const 158 161 { 159 iterator it = std::find(this->_objects.begin(), this->_objects.end(), name);160 if (it != this->_objects.end())161 return *it;162 else163 162 const_iterator it; 163 for (it = this->_objects.begin(); it != this->_objects.end(); ++it) 164 if ((*it)->getName() == name) 165 return (*it); 166 return NULL; 164 167 } 165 168
Note: See TracChangeset
for help on using the changeset viewer.