Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7165 in orxonox.OLD for trunk/src/lib/lang


Ignore:
Timestamp:
Feb 18, 2006, 5:38:37 PM (19 years ago)
Author:
bensch
Message:

reverted the Vector usage, as it lead to a non-predicate segfault

Location:
trunk/src/lib/lang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/lang/class_list.cc

    r7164 r7165  
    5353
    5454//! a List of all known Classes.
    55 std::vector<ClassList>* ClassList::classList = NULL;
     55std::list<ClassList>* ClassList::classList = NULL;
    5656
    5757//! a List of all strings of all classes, that have registered so far.
     
    7070{
    7171  if (unlikely(classList == NULL))
    72     ClassList::classList = new std::vector<ClassList>();
     72    ClassList::classList = new list<ClassList>();
    7373
    7474  PRINTF(5)("subscribe a '%s'\n", className );
     
    9494void ClassList::removeFromClassList(BaseObject* objectPointer)
    9595{
    96   for(unsigned int cl= 0; cl < ClassList::classList->size(); cl++)
    97   {
    98     if (objectPointer->isA((*ClassList::classList)[cl].classID))
    99     {
    100       std::list<BaseObject*>::iterator bo =
    101           std::find ((*ClassList::classList)[cl].objectList.begin(),
    102                        (*ClassList::classList)[cl].objectList.end(),
    103                      objectPointer);
    104       if (bo != (*ClassList::classList)[cl].objectList.end())
    105         (*ClassList::classList)[cl].objectList.erase(bo);
     96  list<ClassList>::iterator cl;
     97  for(cl = ClassList::classList->begin(); cl != ClassList::classList->end(); cl++)
     98  {
     99    if (objectPointer->isA((*cl).classID))
     100    {
     101      std::list<BaseObject*>::iterator bo = std::find ((*cl).objectList.begin(), (*cl).objectList.end(), objectPointer);
     102      if (bo != (*cl).objectList.end())
     103          (*cl).objectList.erase(bo);
    106104    }
    107105  }
     
    121119      ClassList::classNames.clear();
    122120
    123       for (unsigned int cl = 0; cl < ClassList::classList->size(); cl++)
    124         ClassList::classNames.push_back((*ClassList::classList)[cl].className);
     121      list<ClassList>::const_iterator cl;
     122      for (cl = ClassList::classList->begin(); cl != ClassList::classList->end(); cl++)
     123        ClassList::classNames.push_back((*cl).className);
    125124  }
    126125
     
    178177 * !!PRIVATE!!
    179178 * @param classID the ClassID to search for
    180  * @returns the ClassList with classID as specifier, or NULL if not
     179 * @returns the ClassList with classID as specifyer, or NULL if not
    181180 */
    182181ClassList* ClassList::getClassList(ClassID classID)
    183182{
    184   std::vector<ClassList>::iterator classIT =
    185        std::find (ClassList::classList->begin(), ClassList::classList->end(), classID);
     183  std::list<ClassList>::iterator classIT = find (ClassList::classList->begin(), ClassList::classList->end(), classID);
    186184  return (likely(classIT != classList->end()))? &(*classIT) : NULL;
    187185}
     
    191189 * !!PRIVATE!!
    192190 * @param className the ClassName to search for
    193  * @returns the ClassList with className as specifier, or NULL if not
     191 * @returns the ClassList with className as specifyer, or NULL if not
    194192 */
    195193ClassList* ClassList::getClassList(const char* className)
     
    197195  if (className == NULL)
    198196    return NULL;
    199   std::vector<ClassList>::iterator classIT = find (ClassList::classList->begin(), ClassList::classList->end(), className);
     197  std::list<ClassList>::iterator classIT = find (classList->begin(), classList->end(), className);
    200198  return (likely(classIT != classList->end()))? &(*classIT) : NULL;
    201199}
     
    224222  else
    225223  {
    226     std::list<BaseObject*>::iterator bo;
    227     for (unsigned int cl = 0; cl < ClassList::classList->size(); cl++)
    228     {
    229       for (bo = (*ClassList::classList)[cl].objectList.begin(); bo != (*ClassList::classList)[cl].objectList.end(); bo++)
     224    list<ClassList>::iterator cl;
     225    for (cl = ClassList::classList->begin(); cl != ClassList::classList->end(); cl++)
     226    {
     227      std::list<BaseObject*>::iterator bo;
     228      for (bo = (*cl).objectList.begin(); bo != (*cl).objectList.end(); bo++)
    230229        if ((*bo)->getName() != NULL && !strcmp((*bo)->getName(), objectName))
    231230          return (*bo);
     
    256255  else
    257256  {
    258     for (unsigned int cl = 0; cl < ClassList::classList->size(); cl++)
    259     {
    260       std::list<BaseObject*>::const_iterator bo =
    261           find ((*ClassList::classList)[cl].objectList.begin(),
    262           (*ClassList::classList)[cl].objectList.end(), object);
    263       if (bo != (*ClassList::classList)[cl].objectList.end())
     257    list<ClassList>::iterator cl;
     258    for (cl = ClassList::classList->begin(); cl != ClassList::classList->end(); cl++)
     259    {
     260      std::list<BaseObject*>::const_iterator bo = find ((*cl).objectList.begin(), (*cl).objectList.end(), object);
     261      if (bo != (*cl).objectList.end())
    264262        return true;
    265263    }
     
    274272void ClassList::whatIs(const BaseObject* object)
    275273{
    276   for (unsigned int cl = 0; cl < ClassList::classList->size(); cl++)
    277     if (object->isA((*ClassList::classList)[cl].classID))
    278   {
    279     PRINT(0)("=%s::0x%.8X=-",
    280     (*ClassList::classList)[cl].className,
    281     (*ClassList::classList)[cl].classID);
     274  list<ClassList>::iterator cl;
     275  for (cl = ClassList::classList->begin(); cl != ClassList::classList->end(); cl++)
     276    if (object->isA((*cl).classID))
     277  {
     278    PRINT(0)("=%s::0x%.8X=-", (*cl).className, (*cl).classID);
    282279  }
    283280}
     
    336333  unsigned int lenCount = 0;
    337334
    338   for (unsigned int cl = 0; cl < ClassList::classList->size(); cl++)
    339   {
    340     if ((debugLevel >= 1 || (*ClassList::classList)[cl].objectList.size() > 0 ) &&
    341          (classID == CL_NULL || unlikely (classID == (*ClassList::classList)[cl].classID)))
     335  list<ClassList>::iterator cl;
     336  for (cl = ClassList::classList->begin(); cl != ClassList::classList->end(); cl++)
     337  {
     338    if ((debugLevel >= 1 || (*cl).objectList.size() > 0 ) &&
     339         (classID == CL_NULL || unlikely (classID == (*cl).classID)))
    342340    {
    343341      lenCount = 1;
    344       while (pow(10, lenCount) <= (*ClassList::classList)[cl].objectList.size())
     342      while (pow(10, lenCount) <= (*cl).objectList.size())
    345343        ++lenCount;
    346       for (int i=0; i < 30-strlen((*ClassList::classList)[cl].className) - lenCount; i++)
     344      for (int i=0; i < 30-strlen((*cl).className) - lenCount; i++)
    347345        (niceString[i]) = ' ';
    348       niceString[30-strlen((*ClassList::classList)[cl].className) - lenCount] = '\0';
    349 
    350       PRINT(0)("| CLASS %s::%s %d\n", (*ClassList::classList)[cl].className, niceString,
    351             (*ClassList::classList)[cl].objectList.size());
    352 
    353       if (debugLevel >=2 && (*ClassList::classList)[cl].objectList.size() > 0)
     346      niceString[30-strlen((*cl).className) - lenCount] = '\0';
     347
     348      PRINT(0)("| CLASS %s::%s %d\n", (*cl).className, niceString, (*cl).objectList.size());
     349
     350      if (debugLevel >=2 && (*cl).objectList.size() > 0)
    354351      {
    355352        PRINT(0)("|  Listing Instances:\n");
    356353        list<BaseObject*>::const_iterator bo;
    357         for (bo = (*ClassList::classList)[cl].objectList.begin(); bo != (*ClassList::classList)[cl].objectList.end(); bo++)
     354        for (bo = (*cl).objectList.begin(); bo != (*cl).objectList.end(); bo++)
    358355        {
    359356          PRINT(0)("|   %s::%s::(0x%.8X->%p ", (*bo)->getClassName(), (*bo)->getName(), (*bo)->getClassID(), (*bo));
  • trunk/src/lib/lang/class_list.h

    r7163 r7165  
    1010#include "class_id.h"
    1111#include <list>
    12 #include <vector>
    1312#ifndef NULL
    1413#define NULL     0    //!< NULL
     
    5958    inline bool                           operator==(ClassID classID) { return (this->classID == classID); };
    6059    bool                                  operator==(const char* className);
    61     bool                                  operator<(ClassID classID) { return this->classID < classID; };
    62 
    6360    inline ClassID                        getLeafClassID() const { return this->classID; };
    6461
     
    7673
    7774    // STATIC MEMBERS
    78     static std::vector<ClassList>*  classList;              //!< The list of ClassLists.
     75    static std::list<ClassList>*    classList;              //!< The first Class in the List
    7976    static std::list<const char*>   classNames;             //!< a List of all Names of all classes, that have registered so far.
    8077};
Note: See TracChangeset for help on using the changeset viewer.