Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7216 in orxonox.OLD for branches/std/src/lib/lang/class_list.cc


Ignore:
Timestamp:
Mar 12, 2006, 8:54:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/std:: compile and run again, with many more std::strings….

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/std/src/lib/lang/class_list.cc

    r7199 r7216  
    3737 *  Creates a new ClassList
    3838*/
    39 ClassList::ClassList(ClassID classID, unsigned long classIDFull, const char* className)
    40 {
    41   this->className = className;
     39ClassList::ClassList(ClassID classID, unsigned long classIDFull, const std::string& className)
     40  : className(className)
     41{
    4242  this->classID = classID;
    4343  this->classIDFull = classIDFull;
     
    5656
    5757//! a List of all strings of all classes, that have registered so far.
    58 std::list<const char*> ClassList::classNames;
     58std::list<std::string> ClassList::classNames;
    5959
    6060/**
     
    6767 * !! Before unsing the ClassList, as it creates the ClassLits
    6868 */
    69 ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const char* className)
     69ClassList* ClassList::addToClassList(BaseObject* objectPointer, ClassID classID, unsigned long classIDFull, const std::string& className)
    7070{
    7171  if (unlikely(classList == NULL))
    7272    ClassList::classList = new list<ClassList>();
    7373
    74   PRINTF(5)("subscribe a '%s'\n", className );
     74  PRINTF(5)("subscribe a '%s'\n", className.c_str() );
    7575
    7676  ClassList* regClass = ClassList::getClassList(classID);
     
    113113 * befor it changes anything.
    114114 */
    115 const std::list<const char*>* ClassList::getClassNames()
     115const std::list<std::string>* ClassList::getClassNames()
    116116{
    117117  if (ClassList::classNames.size() != ClassList::classList->size())
     
    155155 * @return the List accessed by classID, or NULL if not found
    156156 */
    157 const std::list<BaseObject*>* ClassList::getList(const char* className)
     157const std::list<BaseObject*>* ClassList::getList(const std::string& className)
    158158{
    159159  ClassList* fl;
     
    191191 * @returns the ClassList with className as specifyer, or NULL if not
    192192 */
    193 ClassList* ClassList::getClassList(const char* className)
    194 {
    195   if (className == NULL)
     193ClassList* ClassList::getClassList(const std::string& className)
     194{
     195  if (className.empty())
    196196    return NULL;
    197197  std::list<ClassList>::iterator classIT = find (classList->begin(), classList->end(), className);
     
    207207 * @todo: speed this up!!
    208208 */
    209 BaseObject* ClassList::getObject(const char* objectName, ClassID classID)
     209BaseObject* ClassList::getObject(const std::string& objectName, ClassID classID)
    210210{
    211211  if (classID != CL_NULL)
     
    216216      std::list<BaseObject*>::iterator bo;
    217217      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())
    219219          return (*bo);
    220220    }
     
    227227      std::list<BaseObject*>::iterator bo;
    228228      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())
    230230          return (*bo);
    231231    }
     
    276276    if (object->isA((*cl).classID))
    277277  {
    278     PRINT(0)("=%s::0x%.8X=-", (*cl).className, (*cl).classID);
     278    PRINT(0)("=%s::0x%.8X=-", (*cl).className.c_str(), (*cl).classID);
    279279  }
    280280}
     
    285285 * @return a String containing the name of the Class, NULL if the Class was not found
    286286 */
    287 const char* ClassList::IDToString(ClassID classID)
    288 {
     287const std::string& ClassList::IDToString(ClassID classID)
     288{
     289  static const std::string empty("");
     290
    289291  ClassList* cl = ClassList::getClassList(classID);
    290   return (cl != NULL) ? cl->className : NULL;
     292  return (cl != NULL) ? cl->className : empty;
    291293}
    292294
     
    296298 * @return the ClassID. CL_NULL, if the class was not found.
    297299 */
    298 ClassID ClassList::StringToID(const char* className)
     300ClassID ClassList::StringToID(const std::string& className)
    299301{
    300302  ClassList* cl = ClassList::getClassList(className);
     
    307309 * @returns true on match, false otherwise
    308310 */
    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;
     311bool ClassList::operator==(const std::string& className)
     312{
     313  return (this->className == className);
    315314}
    316315
     
    342341      while (pow(10, lenCount) <= (*cl).objectList.size())
    343342        ++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++)
    345344        (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());
    349348
    350349      if (debugLevel >=2 && (*cl).objectList.size() > 0)
     
    371370 * @see ClassList::debug
    372371 */
    373 void ClassList::debugS(const char* className, unsigned int debugLevel)
     372void ClassList::debugS(const std::string& className, unsigned int debugLevel)
    374373{
    375374  ClassList::debug(debugLevel, ClassList::StringToID(className));
Note: See TracChangeset for help on using the changeset viewer.