Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4747 in orxonox.OLD for orxonox/trunk/src/lib/lang/class_list.cc


Ignore:
Timestamp:
Jul 1, 2005, 4:10:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: classList now counts the count of classes

File:
1 edited

Legend:

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

    r4744 r4747  
    1717
    1818#include "class_list.h"
     19#include "base_object.h"
     20
     21#include "compiler.h"
     22#include "debug.h"
    1923
    2024using namespace std;
     
    2529   \todo this constructor is not jet implemented - do it
    2630*/
    27 ClassList::ClassList ()
     31ClassList::ClassList(const long& classID, const char* className)
    2832{
    29    /* If you make a new class, what is most probably the case when you write this file
    30       don't forget to:
    31        1. Add the new file new_class.cc to the ./src/Makefile.am
    32        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    33 
    34       Advanced Topics:
    35       - if you want to let your object be managed via the ObjectManager make sure to read
    36         the object_manager.h header comments. You will use this most certanly only if you
    37         make many objects of your class, like a weapon bullet.
    38    */
     33  this->objectCount = 0;
     34  this->next = NULL;
     35  this->className = className;
     36  this->classID = classID;
    3937}
    4038
     
    4846  // delete what has to be deleted here
    4947}
     48
     49ClassList*  ClassList::first = NULL;
     50unsigned int ClassList::classCount = 0;
     51
     52
     53
     54void ClassList::addToClassList(BaseObject* objectPointer, const long& classID, const char* className)
     55{
     56  ClassList* regClass;
     57
     58  if(ClassList::first == NULL)
     59    ClassList::first = regClass = new ClassList(classID, className);
     60  else
     61  {
     62    ClassList* tmp = ClassList::first;
     63    while (likely(tmp != NULL))
     64    {
     65      if (tmp->classID == classID)
     66      {
     67        regClass = tmp;
     68        break;
     69      }
     70
     71      if (tmp->next == NULL)
     72        tmp->next = regClass = new ClassList(classID, className);
     73      tmp = tmp->next;
     74    }
     75  }
     76
     77  ++regClass->objectCount;
     78}
     79
     80void ClassList::removeFromClassList(BaseObject* objectPointer)
     81{
     82  ClassList* tmp = ClassList::first;
     83  while (likely(tmp != NULL))
     84  {
     85    if (objectPointer->isA(tmp->classID))
     86    {
     87      --tmp->objectCount;
     88    }
     89
     90    tmp = tmp->next;
     91  }
     92}
     93
     94
     95void ClassList::debug()
     96{
     97  PRINT(0)("=================\n");
     98  PRINT(0)("=  CLASS_LIST   =\n");
     99  PRINT(0)("=================\n");
     100  ClassList* tmp = ClassList::first;
     101  while (likely(tmp != NULL))
     102  {
     103    PRINT(0)("CLASS %s has %d instances\n", tmp->className, tmp->objectCount);
     104
     105    tmp = tmp->next;
     106  }
     107  PRINT(0)("==============CL=\n");
     108
     109}
Note: See TracChangeset for help on using the changeset viewer.