Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/lang/class_list.cc @ 4747

Last change on this file since 4747 was 4747, checked in by bensch, 19 years ago

orxonox/trunk: classList now counts the count of classes

File size: 2.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: ...
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "class_list.h"
19#include "base_object.h"
20
21#include "compiler.h"
22#include "debug.h"
23
24using namespace std;
25
26
27/**
28   \brief standard constructor
29   \todo this constructor is not jet implemented - do it
30*/
31ClassList::ClassList(const long& classID, const char* className)
32{
33  this->objectCount = 0;
34  this->next = NULL;
35  this->className = className;
36  this->classID = classID;
37}
38
39
40/**
41   \brief standard deconstructor
42
43*/
44ClassList::~ClassList ()
45{
46  // delete what has to be deleted here
47}
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 TracBrowser for help on using the repository browser.