Changeset 9685 in orxonox.OLD for branches/new_class_id/src/lib/lang
- Timestamp:
- Aug 22, 2006, 1:16:23 PM (18 years ago)
- Location:
- branches/new_class_id/src/lib/lang
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/lib/lang/new_class_id.cc
r9681 r9685 17 17 18 18 #include "new_class_id.h" 19 #include <cassert>20 #include "debug.h"21 22 ///////////////////////////////////////////////////////////23 //// CLASS ID definiton. //////////////////////////////////24 ///////////////////////////////////////////////////////////25 /**26 * @brief standard constructor27 */28 NewClassID::NewClassID ()29 {}30 31 32 /**33 * @brief standard deconstructor34 */35 NewClassID::~NewClassID ()36 {37 ClassList::iterator it;38 for (it = this->_classes.begin(); it != this->_classes.end(); ++it)39 {40 (*it)._objectList->unregisterObject((*it)._iterator);41 delete (*it)._iterator;42 }43 }44 45 46 /**47 * @brief Seeks in the Inheritance if it matches objectList.48 * @param objectList The ObjectList this should be a member of (by Pointer-comparison).49 * @return True if found, false if not.50 */51 bool NewClassID::isA(const NewObjectListBase& objectList) const52 {53 ClassList::const_iterator it;54 for (it = this->_classes.begin(); it != this->_classes.end(); ++it)55 if ((*it)._objectList == &objectList)56 return true;57 return false;58 }59 60 /**61 * @brief Seeks in the Inheritance if it matches objectList.62 * @param classID The ClassID of the class this should be a member of.63 * @return True if found, false if not.64 */65 bool NewClassID::isA(int classID) const66 {67 ClassList::const_iterator it;68 for (it = this->_classes.begin(); it != this->_classes.end(); ++it)69 if (*(*it)._objectList == classID)70 return true;71 return false;72 }73 74 /**75 * @brief Seeks in the Inheritance if it matches objectList.76 * @param className The ClassName of the class this should be a member of.77 * @return True if found, false if not.78 */79 bool NewClassID::isA(const std::string& className) const80 {81 ClassList::const_iterator it;82 for (it = this->_classes.begin(); it != this->_classes.end(); ++it)83 if (*(*it)._objectList == className)84 return true;85 return false;86 }87 88 89 void NewClassID::listInheritance() const90 {91 PRINT(0)("Listing inheritance diagram for ....: ");92 ClassList::const_iterator it;93 for (it = this->_classes.begin(); it != this->_classes.end(); ++it)94 PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id());95 PRINT(0)("\n");96 97 } -
branches/new_class_id/src/lib/lang/new_class_id.h
r9682 r9685 8 8 #define _NEW_CLASS_ID_H 9 9 10 #include "new_object_list.h"11 12 10 #include <string> 13 #include <list>14 11 15 12 //! A class to dynamically allocate ClassID's and support a isA operator … … 17 14 { 18 15 public: 19 NewClassID(); 20 ~NewClassID(); 16 NewClassID() : _id(-1), _name("") { }; 17 NewClassID(int id, const std::string& name) : _id(id), _name(name) { }; 18 // the copy constructor is also defined. 19 int id() const { return _id; }; 20 const std::string& name() const { return _name; }; 21 21 22 /** @returns the ClassName of the Topmost Object of the ClassStack */ 23 inline const std::string& getClassName() const { return _classes.front()._objectList->name(); } 24 /** @returns the ID of the Topmost object of the ClassStack */ 25 inline int leafClassID() const { return _classes.front()._objectList->id(); } 26 27 template<class T> void registerObject(T* object, NewObjectList<T>& list); 28 bool isA(const NewObjectListBase& objectList) const; 29 bool isA(int classID) const; 30 bool isA(const std::string& className) const; 31 32 void listInheritance() const; 22 bool operator==(NewClassID id) const { return _id == id._id || _name == id._name; }; 23 bool operator==(int id) const { return _id == id; }; 24 bool operator==(const std::string& name) const { return _name == name; }; 33 25 34 26 private: 35 ////////////////////////////// 36 //// Type Definition Part //// 37 ////////////////////////////// 38 //! A ClassEntry so we can store Classes inside of Objects 39 struct ClassEntry 40 { 41 /** Simple Constuctor @param objectList the NewObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */ 42 inline ClassEntry (NewObjectListBase* objectList, NewObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {} 43 NewObjectListBase* _objectList; //!< A ObjectList this Object is part of 44 NewObjectListBase::IteratorBase* _iterator; //!< An iterator pointing to the position of the Object inside of the List. 45 }; 46 typedef std::list<ClassEntry> ClassList; //!< Type definition for the List. 47 48 ClassList _classes; //!< All Classes this object is part of. 27 int _id; 28 std::string _name; 49 29 }; 50 51 52 /**53 * @brief Registeres an Object of Type T to objectList54 * @param object The Object to append to the objectList.55 * @param objectList The ObjectList to append the Object to.56 *57 * This function is essential to integrate objects into their designated ObjectList.58 * Remember if you do not want objects to be stored in Lists (less overhead),59 * do not attempt to call this function.60 */61 template<class T>62 inline void NewClassID::registerObject(T* object, NewObjectList<T>& objectList)63 {64 this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object)));65 }66 67 30 #endif /* _NEW_CLASS_ID_H */ -
branches/new_class_id/src/lib/lang/new_object_list.cc
r9681 r9685 27 27 */ 28 28 NewObjectListBase::NewObjectListBase(const std::string& className, int id) 29 : _name(className)30 29 { 31 30 if (NewObjectListBase::_classesByID == NULL) … … 37 36 assert(!NewObjectListBase::classNameExists(className) && "Classes should only be included once, and no two classes should have the same name (key value)"); 38 37 39 if (id != -1)38 if (id == -1) 40 39 { 41 this->_id = id; 42 } 43 else 44 { 45 this->_id = NewObjectListBase::_classesByID->size(); 40 id = NewObjectListBase::_classesByID->size(); 46 41 // searching for a free ID 47 while (NewObjectListBase::classIDExists( _id)) ++id;42 while (NewObjectListBase::classIDExists(id)) ++id; 48 43 } 49 44 assert(!NewObjectListBase::classIDExists(id) && "Classes should only be included once, and no two classes should have the same ID (key value)"); … … 52 47 //std::cout << "register new ObjectList " << className << " ID: " << this->_id << std::endl; 53 48 54 (*NewObjectListBase::_classesByID)[this->_id] = this; 55 (*NewObjectListBase::_classesByName)[this->_name] = this; 49 this->_identity = NewClassID(id, className); 50 (*NewObjectListBase::_classesByID)[this->_identity.id()] = this; 51 (*NewObjectListBase::_classesByName)[this->_identity.name()] = this; 56 52 } 57 53 … … 70 66 std::cout << "SIZE OF _classByName: " << NewObjectListBase::_classesByName->size() << std::endl; 71 67 */ 72 NewObjectListBase::_classesBy Name->erase(this->_name);73 NewObjectListBase::_classesBy ID->erase(this->_id);68 NewObjectListBase::_classesByID->erase(this->_identity.id()); 69 NewObjectListBase::_classesByName->erase(this->_identity.name()); 74 70 75 71 if (NewObjectListBase::_classesByID->empty()) -
branches/new_class_id/src/lib/lang/new_object_list.h
r9684 r9685 8 8 #define _NEW_OBJECT_LIST_H 9 9 10 #include " type_info.h"10 #include "new_class_id.h" 11 11 #include <map> 12 12 #include <list> … … 40 40 41 41 public: 42 inline int id() const { return _id ; };43 inline const std::string& name() const { return _ name; };44 bool operator==(int id) const { return _id == id; };45 bool operator==(const std::string& name) const { return _ name== name; };42 inline int id() const { return _identity.id(); }; 43 inline const std::string& name() const { return _identity.name(); }; 44 bool operator==(int id) const { return _identity == id; }; 45 bool operator==(const std::string& name) const { return _identity == name; }; 46 46 47 47 virtual void debug() const = 0; … … 69 69 typedef std::map<std::string, NewObjectListBase*> classNameMap;//!< The Generic Map. 70 70 71 int _id; //!< The ID of the class. 72 std::string _name; //!< The Name of the Class. 71 NewClassID _identity; //!< The Identity of the Class (ID and Name). 73 72 74 73 private: … … 114 113 inline const list& objects() const { return _objects; }; 115 114 115 inline iterator begin() { return _objects.begin(); }; 116 inline const_iterator begin() const { return _objects.begin(); }; 117 inline iterator end() { return _objects.end(); }; 118 inline const_iterator end() const { return _objects.end(); }; 119 120 inline bool empty() const { return _objects.empty(); }; 121 inline int size() const { return _objects.size(); }; 122 inline T* front() const { return _objects.front(); }; 123 inline T* back() const { return _objects.back(); }; 124 116 125 NewObjectListBase::IteratorBase* registerObject(T* object); 117 126 void unregisterObject(IteratorBase* iterator);
Note: See TracChangeset
for help on using the changeset viewer.