Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: injected the ogg-player into orxonox

File size: 2.9 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: Benjamin Grauer
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#include <string.h>
24#include <math.h>
25
26using namespace std;
27
28
29/**
30   \brief Creates a new ClassList
31*/
32ClassList::ClassList(const long& classID, const char* className)
33{
34  this->objectCount = 0;
35  this->next = NULL;
36  this->className = className;
37  this->classID = classID;
38
39  ++ClassList::classCount;
40}
41
42
43/**
44   \brief standard deconstructor
45
46*/
47ClassList::~ClassList ()
48{
49  --ClassList::classCount;
50}
51
52//! the first class that is registered
53ClassList*  ClassList::first = NULL;
54
55//! the Count of classes
56unsigned int ClassList::classCount = 0;
57
58/**
59 * Adds a new Object to the ClassList (and if necessary a new Class)
60 * @param objectPointer Pointer to the Object at hand
61 * @param classID ID of the Given ObjectType \see ClassID
62 * @param className name of the Class to add
63 */
64void ClassList::addToClassList(BaseObject* objectPointer, const long& classID, const char* className)
65{
66  ClassList* regClass;
67
68  if(ClassList::first == NULL)
69    ClassList::first = regClass = new ClassList(classID, className);
70  else
71  {
72    ClassList* tmp = ClassList::first;
73    while (likely(tmp != NULL))
74    {
75      if (tmp->classID == classID)
76      {
77        regClass = tmp;
78        break;
79      }
80
81      if (tmp->next == NULL)
82        tmp->next = regClass = new ClassList(classID, className);
83      tmp = tmp->next;
84    }
85  }
86
87  ++regClass->objectCount;
88}
89
90/**
91 * removes an Object from a the ClassList
92 * @param objectPointer the Object to delete from the List
93 */
94void ClassList::removeFromClassList(BaseObject* objectPointer)
95{
96  ClassList* tmp = ClassList::first;
97  while (likely(tmp != NULL))
98  {
99    if (objectPointer->isA(tmp->classID))
100    {
101      --tmp->objectCount;
102    }
103
104    tmp = tmp->next;
105  }
106}
107
108/**
109 * Print out some very nice debug information
110 */
111void ClassList::debug()
112{
113  PRINT(0)("=================\n");
114  PRINT(0)("=  CLASS_LIST   =\n");
115  PRINT(0)("=================\n");
116  PRINT(0)("has %d Elements\n\n", ClassList::classCount);
117  ClassList* tmp = ClassList::first;
118  char niceString[100];
119  unsigned int lenCount = 0;
120
121  while (likely(tmp != NULL))
122  {
123    lenCount = 1;
124    while (pow(10,lenCount) <= tmp->objectCount)
125      ++lenCount;
126    for (int i=0; i < 30-strlen(tmp->className) - lenCount; i++)
127      (niceString[i]) = ' ';
128    niceString[30-strlen(tmp->className) - lenCount] = '\0';
129
130    PRINT(0)("CLASS %s:%s %d instances\n", tmp->className, niceString, tmp->objectCount);
131
132    tmp = tmp->next;
133  }
134  PRINT(0)("==============CL=\n");
135}
Note: See TracBrowser for help on using the repository browser.