Changeset 7216 in orxonox.OLD for branches/std/src/lib/lang/class_list.cc
- Timestamp:
- Mar 12, 2006, 8:54:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/lib/lang/class_list.cc
r7199 r7216 37 37 * Creates a new ClassList 38 38 */ 39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const char*className)40 { 41 this->className = className; 39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const std::string& className) 40 : className(className) 41 { 42 42 this->classID = classID; 43 43 this->classIDFull = classIDFull; … … 56 56 57 57 //! a List of all strings of all classes, that have registered so far. 58 std::list< const char*> ClassList::classNames;58 std::list<std::string> ClassList::classNames; 59 59 60 60 /** … … 67 67 * !! Before unsing the ClassList, as it creates the ClassLits 68 68 */ 69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char*className)69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className) 70 70 { 71 71 if (unlikely(classList == NULL)) 72 72 ClassList::classList = new list<ClassList>(); 73 73 74 PRINTF(5)("subscribe a '%s'\n", className );74 PRINTF(5)("subscribe a '%s'\n", className.c_str() ); 75 75 76 76 ClassList* regClass = ClassList::getClassList(classID); … … 113 113 * befor it changes anything. 114 114 */ 115 const std::list< const char*>* ClassList::getClassNames()115 const std::list<std::string>* ClassList::getClassNames() 116 116 { 117 117 if (ClassList::classNames.size() != ClassList::classList->size()) … … 155 155 * @return the List accessed by classID, or NULL if not found 156 156 */ 157 const std::list<BaseObject*>* ClassList::getList(const char*className)157 const std::list<BaseObject*>* ClassList::getList(const std::string& className) 158 158 { 159 159 ClassList* fl; … … 191 191 * @returns the ClassList with className as specifyer, or NULL if not 192 192 */ 193 ClassList* ClassList::getClassList(const char*className)194 { 195 if (className == NULL)193 ClassList* ClassList::getClassList(const std::string& className) 194 { 195 if (className.empty()) 196 196 return NULL; 197 197 std::list<ClassList>::iterator classIT = find (classList->begin(), classList->end(), className); … … 207 207 * @todo: speed this up!! 208 208 */ 209 BaseObject* ClassList::getObject(const char*objectName, ClassID classID)209 BaseObject* ClassList::getObject(const std::string& objectName, ClassID classID) 210 210 { 211 211 if (classID != CL_NULL) … … 216 216 std::list<BaseObject*>::iterator bo; 217 217 for (bo = cl->objectList.begin(); bo != cl->objectList.end(); bo++) 218 if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))218 if ((*bo)->getName() != NULL && objectName == (*bo)->getName()) 219 219 return (*bo); 220 220 } … … 227 227 std::list<BaseObject*>::iterator bo; 228 228 for (bo = (*cl).objectList.begin(); bo != (*cl).objectList.end(); bo++) 229 if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))229 if ((*bo)->getName() != NULL && objectName == (*bo)->getName()) 230 230 return (*bo); 231 231 } … … 276 276 if (object->isA((*cl).classID)) 277 277 { 278 PRINT(0)("=%s::0x%.8X=-", (*cl).className , (*cl).classID);278 PRINT(0)("=%s::0x%.8X=-", (*cl).className.c_str(), (*cl).classID); 279 279 } 280 280 } … … 285 285 * @return a String containing the name of the Class, NULL if the Class was not found 286 286 */ 287 const char* ClassList::IDToString(ClassID classID) 288 { 287 const std::string& ClassList::IDToString(ClassID classID) 288 { 289 static const std::string empty(""); 290 289 291 ClassList* cl = ClassList::getClassList(classID); 290 return (cl != NULL) ? cl->className : NULL;292 return (cl != NULL) ? cl->className : empty; 291 293 } 292 294 … … 296 298 * @return the ClassID. CL_NULL, if the class was not found. 297 299 */ 298 ClassID ClassList::StringToID(const char*className)300 ClassID ClassList::StringToID(const std::string& className) 299 301 { 300 302 ClassList* cl = ClassList::getClassList(className); … … 307 309 * @returns true on match, false otherwise 308 310 */ 309 bool ClassList::operator==(const char* className) 310 { 311 if (likely( className != NULL && this->className != NULL)) 312 return (!strcmp(this->className, className)); 313 else 314 return false; 311 bool ClassList::operator==(const std::string& className) 312 { 313 return (this->className == className); 315 314 } 316 315 … … 342 341 while (pow(10, lenCount) <= (*cl).objectList.size()) 343 342 ++lenCount; 344 for (int i=0; i < 30- strlen((*cl).className) - lenCount; i++)343 for (int i=0; i < 30-(*cl).className.size() - lenCount; i++) 345 344 (niceString[i]) = ' '; 346 niceString[30- strlen((*cl).className) - lenCount] = '\0';347 348 PRINT(0)("| CLASS %s::%s %d\n", (*cl).className , niceString, (*cl).objectList.size());345 niceString[30-(*cl).className.size() - lenCount] = '\0'; 346 347 PRINT(0)("| CLASS %s::%s %d\n", (*cl).className.c_str(), niceString, (*cl).objectList.size()); 349 348 350 349 if (debugLevel >=2 && (*cl).objectList.size() > 0) … … 371 370 * @see ClassList::debug 372 371 */ 373 void ClassList::debugS(const char*className, unsigned int debugLevel)372 void ClassList::debugS(const std::string& className, unsigned int debugLevel) 374 373 { 375 374 ClassList::debug(debugLevel, ClassList::StringToID(className));
Note: See TracChangeset
for help on using the changeset viewer.