Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 26, 2005, 2:20:58 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: ClassList is now in std::list style
ShellCommand is now in std::list style

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

Legend:

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

    r5770 r5779  
    4040  this->className = className;
    4141  this->classID = classID;
    42   this->objectList = new tList<BaseObject>;
    4342
    4443  ++ClassList::classCount;
     
    5049ClassList::~ClassList ()
    5150{
    52   delete this->objectList;
    53   if(ClassList::classList != NULL)
    54   {
    55     delete ClassList::classList;
    56     ClassList::classList = NULL;
    57   }
     51  /// FIXME
     52//   if(ClassList::classList != NULL)
     53//   {
     54//     delete ClassList::classList;
     55//     ClassList::classList = NULL;
     56//   }
    5857  --ClassList::classCount;
    5958}
     
    6665
    6766//! a List of all strings of all classes, that have registered so far.
    68 tList<const char>* ClassList::classList = NULL;
     67std::list<const char*> ClassList::classList;
    6968
    7069/**
     
    10099    }
    101100  }
    102   regClass->objectList->add(objectPointer);
     101  regClass->objectList.push_back(objectPointer);
    103102}
    104103
     
    114113    if (objectPointer->isA(tmp->classID))
    115114    {
    116       tmp->objectList->remove(objectPointer);
     115      tmp->objectList.remove(objectPointer);
    117116    }
    118117    tmp = tmp->next;
     
    127126 * befor it changes anything.
    128127 */
    129 const tList<const char>* ClassList::getClassList()
    130 {
    131   if (unlikely(ClassList::classList != NULL && ClassList::classList->getSize() != ClassList::classCount))
    132   {
    133     delete ClassList::classList;
    134     ClassList::classList = NULL;
    135   }
    136   if (unlikely(ClassList::classList == NULL))
    137     ClassList::classList = new tList<const char>;
     128const std::list<const char*>* ClassList::getClassList()
     129{
     130  if (ClassList::classList.size() != ClassList::classCount)
     131    ClassList::classList.erase(ClassList::classList.begin(), ClassList::classList.end());
    138132
    139133  if(likely(ClassList::first != NULL))
     
    142136    while (likely(tmpCL != NULL))
    143137    {
    144       ClassList::classList->add(tmpCL->className);
    145       tmpCL = tmpCL->next;
    146     }
    147   }
    148   return ClassList::classList;
     138      ClassList::classList.push_back(tmpCL->className);
     139      tmpCL = tmpCL->next;
     140    }
     141  }
     142  return &ClassList::classList;
    149143}
    150144
     
    154148 * @return the List accessed by classID, or NULL if not found
    155149 */
    156 tList<BaseObject>* ClassList::getList(long classID)
     150std::list<BaseObject*>* ClassList::getList(long classID)
    157151{
    158152  if(unlikely(ClassList::first == NULL))
     
    164158    {
    165159      if (unlikely(tmpCL->classID == classID))
    166         return tmpCL->objectList;
     160        return &tmpCL->objectList;
    167161      tmpCL = tmpCL->next;
    168162    }
     
    175169 * @param className the name of the class to get the list from
    176170 * @return the List accessed by classID, or NULL if not found
    177  */tList<BaseObject>* ClassList::getList(const char* className)
     171 */
     172std::list<BaseObject*>* ClassList::getList(const char* className)
    178173{
    179174  if(unlikely(ClassList::first == NULL))
     
    185180    {
    186181      if (unlikely(!strcmp(tmpCL->className, className)))
    187         return tmpCL->objectList;
     182        return &tmpCL->objectList;
    188183      tmpCL = tmpCL->next;
    189184    }
     
    210205      if (tmp->classID == classID || classID == CL_NULL)
    211206      {
    212         tIterator<BaseObject>* iterator = tmp->objectList->getIterator();
    213         BaseObject* enumBO = iterator->firstElement();
    214         const char* tmpName;
    215         while (enumBO != NULL)
    216         {
    217           tmpName = enumBO->getName();
    218           if (tmpName && !strcmp(tmpName, name))
    219           {
    220             delete iterator;
    221             return enumBO;
    222           }
    223           enumBO = iterator->nextElement();
    224         }
    225         delete iterator;
     207        list<BaseObject*>::iterator bo;
     208        for (bo = tmp->objectList.begin(); bo != tmp->objectList.end(); bo++)
     209          if ((*bo)->getName() && !strcmp((*bo)->getName(), name))
     210            return (*bo);
    226211        break;
    227212      }
     
    251236      if (tmp->classID == classID || classID == CL_NULL)
    252237      {
    253         tIterator<BaseObject>* iterator = tmp->objectList->getIterator();
    254         const BaseObject* enumBO = iterator->firstElement();
    255         while (enumBO != NULL)
    256         {
    257           if (enumBO == object)
    258           {
    259             delete iterator;
     238        list<BaseObject*>::iterator bo;
     239        for (bo = tmp->objectList.begin(); bo != tmp->objectList.end(); bo++)
     240          if ((*bo) == object)
    260241            return true;
    261           }
    262           enumBO = iterator->nextElement();
    263         }
    264242        if (likely(tmp->classID == classID))
    265         {
    266           delete iterator;
    267243          break;
    268         }
    269244      }
    270245      tmp = tmp->next;
     
    354329  while (likely(tmp != NULL))
    355330  {
    356     if ((debugLevel >= 1 || tmp->objectList->getSize() > 0 ) &&
     331    if ((debugLevel >= 1 || tmp->objectList.size() > 0 ) &&
    357332         (classID == CL_NULL || unlikely (classID == tmp->classID)))
    358333    {
    359334      lenCount = 1;
    360       while (pow(10,lenCount) <= tmp->objectList->getSize())
     335      while (pow(10, lenCount) <= tmp->objectList.size())
    361336        ++lenCount;
    362337      for (int i=0; i < 30-strlen(tmp->className) - lenCount; i++)
     
    364339      niceString[30-strlen(tmp->className) - lenCount] = '\0';
    365340
    366       PRINT(0)("| CLASS %s:%s %d\n", tmp->className, niceString, tmp->objectList->getSize());
    367 
    368       if (debugLevel >=2 && tmp->objectList->getSize() > 0)
     341      PRINT(0)("| CLASS %s:%s %d\n", tmp->className, niceString, tmp->objectList.size());
     342
     343      if (debugLevel >=2 && tmp->objectList.size() > 0)
    369344      {
    370345        PRINT(0)("|  Listing Instances:\n");
    371         tIterator<BaseObject>* iterator = tmp->objectList->getIterator();
    372         BaseObject* enumBO = iterator->firstElement();
    373         while (enumBO)
     346        list<BaseObject*>::const_iterator bo;
     347        for (bo = tmp->objectList.begin(); bo != tmp->objectList.end(); bo++)
    374348        {
    375           PRINT(0)("|   (class %s): NAME(%s)->%p ", enumBO->getClassName(), enumBO->getName(), enumBO);
     349          PRINT(0)("|   (class %s): NAME(%s)->%p ", (*bo)->getClassName(), (*bo)->getName(), (*bo));
    376350          if (debugLevel == 3)
    377             ClassList::whatIs(enumBO);
     351            ClassList::whatIs(*bo);
    378352          PRINT(0)("\n");
    379           enumBO = iterator->nextElement();
    380353        }
    381         delete iterator;
    382354      }
    383355    }
  • trunk/src/lib/lang/class_list.h

    r5405 r5779  
    99
    1010#include "class_id.h"
     11#include <list>
    1112
    1213// FORWARD DECLARATION
    1314class BaseObject;
    14 template<class T> class tList;
    15 
    1615
    1716//! A class that handles Pointers to Objects of all type.
     
    3534
    3635    // STATIC FUNCTIONS
    37     static void                     addToClassList(BaseObject* objectPointer, const long& classID, const char* className);
    38     static void                     removeFromClassList(BaseObject* objectPointer);
     36    static void                          addToClassList(BaseObject* objectPointer, const long& classID, const char* className);
     37    static void                          removeFromClassList(BaseObject* objectPointer);
    3938
    40     static tList<BaseObject>*       getList(long classID = CL_NULL);
    41     static tList<BaseObject>*       getList(const char* className);
    42     static const tList<const char>* getClassList();
    43     static BaseObject*              getObject(const char* name, long classID = CL_NULL);
    44     static bool                     exists(const BaseObject* object, long classID = CL_NULL);
     39    static std::list<BaseObject*>*       getList(long classID = CL_NULL);
     40    static std::list<BaseObject*>*       getList(const char* className);
     41    static const std::list<const char*>* getClassList();
     42    static BaseObject*                   getObject(const char* name, long classID = CL_NULL);
     43    static bool                          exists(const BaseObject* object, long classID = CL_NULL);
    4544
    46     static void                     whatIs(const BaseObject* object);
     45    static void                          whatIs(const BaseObject* object);
    4746
    48     static const char*              IDToString(long classID = CL_NULL);
    49     static long                     StringToID(const char* className);
    50     static void                     debug(unsigned int debugLevel = 0, long classID = CL_NULL);
    51     static void                     debugS(const char* className = 0x0, unsigned int debugLevel = 0);
     47    static const char*                   IDToString(long classID = CL_NULL);
     48    static long                          StringToID(const char* className);
     49    static void                          debug(unsigned int debugLevel = 0, long classID = CL_NULL);
     50    static void                          debugS(const char* className = 0x0, unsigned int debugLevel = 0);
     51
    5252
    5353
    5454  private:
    55     tList<BaseObject>*              objectList;             //!< A list of Objects belonging to this Class
     55    std::list<BaseObject*>          objectList;             //!< A list of Objects belonging to this Class
    5656
    5757    long                            classID;                //!< ClassID stored in this ClassList \see ClassID
     
    6262    // STATIC MEMBERS
    6363    static ClassList*               first;                  //!< The first Class in the List
    64     static tList<const char>*       classList;              //!< a List of all Names of all classes, that have registered so far.
     64    static std::list<const char*>   classList;              //!< a List of all Names of all classes, that have registered so far.
    6565    static unsigned int             classCount;             //!< The Count of classes that have been registered (should match the lower description)
    6666};
Note: See TracChangeset for help on using the changeset viewer.