/* 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: Benjamin Grauer co-programmer: ... */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "class_list.h" #include "base_object.h" #include "list.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->next = NULL; this->className = className; this->classID = classID; this->objectList = new tList; ++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->objectList->add(objectPointer); } /** * 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->objectList->remove(objectPointer); } tmp = tmp->next; } } /** * Print out some very nice debug information */ void ClassList::debug(unsigned int debugLevel) { if (debugLevel > 2) debugLevel = 2; PRINT(0)("==========================\n"); PRINT(0)("= CLASS_LIST (level %d) =\n", debugLevel); 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)) { if (debugLevel >= 1 || tmp->objectList->getSize() > 0) { lenCount = 1; while (pow(10,lenCount) <= tmp->objectList->getSize()) ++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->objectList->getSize()); if (debugLevel >=2 && tmp->objectList->getSize() > 0) { PRINT(0)(" Listing Instances:\n"); tIterator* iterator = tmp->objectList->getIterator(); BaseObject* enumBO = iterator->nextElement(); while (enumBO) { PRINT(0)(" (class %s): NAME(%s)->%p\n", enumBO->getClassName(), enumBO->getName(), enumBO); enumBO = iterator->nextElement(); } delete iterator; } } tmp = tmp->next; } PRINT(0)("==============CL=\n"); }