/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: ... co-programmer: ... */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "class_list.h" #include "base_object.h" #include "compiler.h" #include "debug.h" #include #include using namespace std; /** \brief Creates a new ClassList */ ClassList::ClassList(const long& classID, const char* className) { this->objectCount = 0; this->next = NULL; this->className = className; this->classID = classID; ++ClassList::classCount; } /** \brief standard deconstructor */ ClassList::~ClassList () { --ClassList::classCount; } //! the first class that is registered ClassList* ClassList::first = NULL; //! the Count of classes unsigned int ClassList::classCount = 0; /** * Adds a new Object to the ClassList (and if necessary a new Class) * @param objectPointer Pointer to the Object at hand * @param classID ID of the Given ObjectType \see ClassID * @param className name of the Class to add */ void ClassList::addToClassList(BaseObject* objectPointer, const long& classID, const char* className) { ClassList* regClass; if(ClassList::first == NULL) ClassList::first = regClass = new ClassList(classID, className); else { ClassList* tmp = ClassList::first; while (likely(tmp != NULL)) { if (tmp->classID == classID) { regClass = tmp; break; } if (tmp->next == NULL) tmp->next = regClass = new ClassList(classID, className); tmp = tmp->next; } } ++regClass->objectCount; } /** * removes an Object from a the ClassList * @param objectPointer the Object to delete from the List */ void ClassList::removeFromClassList(BaseObject* objectPointer) { ClassList* tmp = ClassList::first; while (likely(tmp != NULL)) { if (objectPointer->isA(tmp->classID)) { --tmp->objectCount; } tmp = tmp->next; } } /** * Print out some very nice debug information */ void ClassList::debug() { PRINT(0)("=================\n"); PRINT(0)("= CLASS_LIST =\n"); PRINT(0)("=================\n"); PRINT(0)("has %d Elements\n\n", ClassList::classCount); ClassList* tmp = ClassList::first; char niceString[100]; unsigned int lenCount = 0; while (likely(tmp != NULL)) { lenCount = 1; while (pow(10,lenCount) <= tmp->objectCount) ++lenCount; for (int i=0; i < 30-strlen(tmp->className) - lenCount; i++) (niceString[i]) = ' '; niceString[30-strlen(tmp->className) - lenCount] = '\0'; PRINT(0)("CLASS %s:%s %d instances\n", tmp->className, niceString, tmp->objectCount); tmp = tmp->next; } PRINT(0)("==============CL=\n"); }