Changeset 9675 in orxonox.OLD for trunk/src/lib/lang
- Timestamp:
- Aug 21, 2006, 10:57:35 PM (18 years ago)
- Location:
- trunk/src/lib/lang
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/lang/new_object_list.cc
r9671 r9675 23 23 : _id(-1), _name(className) 24 24 { 25 if (NewObjectListBase::_classes == NULL) 26 NewObjectListBase::_classes = new cSet; 25 if (NewObjectListBase::_classesByID == NULL) 26 { 27 NewObjectListBase::_classesByID = new classIDMap; 28 assert (NewObjectListBase::_classesByName == NULL); 29 NewObjectListBase::_classesByName = new classNameMap; 30 } 31 assert(!NewObjectListBase::classNameExists(className) && "Classes should only be included once, and no two classes should have the same name/ID (key value)"); 27 32 28 29 assert(!NewObjectListBase::classNameExists(className) && "Classes should not be included once, and no two classes should have the same name (key value)");30 33 31 34 this->_id = NewObjectListBase::_idCounter++; 32 35 36 (*NewObjectListBase::_classesByID)[this->_id] = this; 37 (*NewObjectListBase::_classesByName)[this->_name] = this; 33 38 } 34 39 35 40 NewObjectListBase::~NewObjectListBase() 36 41 { 42 NewObjectListBase::_classesByName->erase(this->_name); 43 NewObjectListBase::_classesByID->erase(this->_id); 37 44 45 if (NewObjectListBase::_classesByID->empty()) 46 { 47 delete NewObjectListBase::_classesByID; 48 NewObjectListBase::_classesByID = NULL; 49 assert(NewObjectListBase::_classesByName != NULL); 50 delete NewObjectListBase::_classesByName; 51 NewObjectListBase::_classesByName = NULL; 52 } 38 53 } 39 54 40 55 int NewObjectListBase::_idCounter = 0; 41 NewObjectListBase::cSet* NewObjectListBase::_classes = NULL; 56 NewObjectListBase::classIDMap* NewObjectListBase::_classesByID = NULL; 57 NewObjectListBase::classNameMap* NewObjectListBase::_classesByName = NULL; 42 58 43 59 … … 50 66 bool NewObjectListBase::classNameExists(const std::string& name) 51 67 { 52 cSet::iterator it; 53 for (it = NewObjectListBase::_classes->begin(); it != NewObjectListBase::_classes->end(); it++) 54 if(*it != NULL && (*it)->name() != name) 55 return true; 56 return false; 68 return (NewObjectListBase::_classesByName->find(name) != NewObjectListBase::_classesByName->end()); 69 // classNameMap::iterator it; 70 // for (it = NewObjectListBase::_classesByID->begin(); it != NewObjectListBase::_classesByID->end(); it++) 71 // if(*it != NULL && (*it)->name() != name) 72 // return true; 73 // return false; 57 74 } 75 76 77 /** 78 * @brief Converts an ID into a ClassName String. 79 * @param classID The ID to convert. 80 * @return The ClassName or an empty string if the ID was not found. 81 */ 82 const std::string& NewObjectListBase::IDToString(int classID) 83 { 84 assert (NewObjectListBase::_classesByID != NULL); 85 NewObjectListBase::classIDMap::iterator it = NewObjectListBase::_classesByID->find(classID); 86 if (it != NewObjectListBase::_classesByID->end()) 87 return (*it).second->name(); 88 else 89 { 90 static std::string empty; 91 return empty; 92 } 93 } 94 95 96 /** 97 * @brief Converts a String into an ID 98 * @param className the Name of the Class to search for 99 * @return The Classes ID if found, -1 otherwise. 100 */ 101 int NewObjectListBase::StringToID(const std::string& className) 102 { 103 assert (NewObjectListBase::_classesByName != NULL); 104 NewObjectListBase::classNameMap::iterator it = NewObjectListBase::_classesByName->find(className); 105 if (it != NewObjectListBase::_classesByName->end()) 106 return (*it).second->id(); 107 else 108 return -1; 109 } 110 -
trunk/src/lib/lang/new_object_list.h
r9674 r9675 9 9 10 10 #include "type_info.h" 11 #include < set>11 #include <map> 12 12 #include <list> 13 #include <vector>14 13 #include <string> 15 14 … … 33 32 34 33 public: 35 in t id() const { return _id; };36 const std::string& name() const { return _name; };34 inline int id() const { return _id; }; 35 inline const std::string& name() const { return _name; }; 37 36 bool operator==(int id) const { return _id == id; }; 38 37 bool operator==(const std::string& name) const { return _name == name; }; … … 40 39 41 40 /// Comparing operators. 42 bool compareName(const NewObjectListBase& more) const { return this->_name < more.name(); }; 43 bool compareID(const NewObjectListBase& more) const { return this->_id < more.id(); }; 41 // struct CompareID { 42 // bool operator()(const NewObjectListBase* less, const NewObjectListBase* more) { return less->id() < more->id(); }; 43 // }; 44 // struct CompareName{ 45 // bool operator()(const NewObjectListBase* less, const NewObjectListBase* more) { return less->name() < more->name(); }; 46 // }; 44 47 45 48 virtual void debug() const = 0; … … 63 66 64 67 protected: 65 typedef std:: set<NewObjectListBase*> cSet; //!< The Generic Set.66 typedef std:: vector<NewObjectListBase*> cVector; //!< The68 typedef std::map<int, NewObjectListBase*> classIDMap; //!< The Generic Map. 69 typedef std::map<std::string, NewObjectListBase*> classNameMap;//!< The Generic Map. 67 70 68 71 int _id; //!< The ID of the class. 69 72 std::string _name; //!< The Name of the Class. 70 73 71 cVector _typeOfList; //!< A List of all classes this class is derived of, and the class itself, ordered by age of addition.72 cSet _typeOfSet; //!< A Set of all classes this is derived from and the class itself (for isA).73 74 private: 74 75 75 76 static int _idCounter; //!< A counter, that gives all classes a Unique ClassID. Access to this Variable is to be Thread-Safe. 76 static cSet* _classes; //!< A Set of all the classes in existance. 77 static classIDMap* _classesByID; //!< A Map of all the classes in existance. 78 static classNameMap* _classesByName; //!< A Map of all the classes in existance. 77 79 static std::list<std::string> _classNames; //!< A list of all the registered ClassNames. 78 80 }; -
trunk/src/lib/lang/test_object_list.cc
r9674 r9675 8 8 { 9 9 public: 10 void setName(const std::string& name) { this->_objectName = name; };11 const std::string& getName() const { return _objectName; };12 bool operator==(const std::string& name) const { return _objectName == name; };10 // void setName(const std::string& name) { this->_objectName = name; }; 11 const std::string& getName() const { return _objectName; }; 12 // bool operator==(const std::string& name) const { return _objectName == name; }; 13 13 14 NewObjectListDeclaration(NewBaseObject);14 // NewObjectListDeclaration(NewBaseObject); 15 15 16 16 protected: 17 17 NewBaseObject(const std::string& objectName = "") : _objectName(objectName) 18 18 { 19 this->registerObject(this, objectList);19 // this->registerObject(this, objectList); 20 20 }; 21 21 template<class T> … … 27 27 28 28 }; 29 NewObjectListDefinition(NewBaseObject);29 //NewObjectListDefinition(NewBaseObject); 30 30 31 31 32 class Test : public NewBaseObject 32 class Test : 33 public NewBaseObject 34 // , 35 // public BaseObject 33 36 { 34 37 public: … … 44 47 Test::Test() 45 48 { 49 this->registerObject(this, Test::objectList); 46 50 // this->setClassID(CL_PARENT_NODE, "Test"); 47 this->registerObject(this, Test::objectList);48 51 // std::cout << "Test()\n"; 49 52 }; … … 58 61 Bone() 59 62 { 60 // this->registerObject(this, Bone::objectList);63 // this->registerObject(this, Bone::objectList); 61 64 //std::cout << "Bone()\n"; 62 65 }; … … 75 78 std::cout<< i << std::endl; 76 79 Test* test = new Test[10000]; 77 delete[]test;80 // delete[]test; 78 81 } 79 82 // char tmp[100];
Note: See TracChangeset
for help on using the changeset viewer.