/* 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: Christian Meyer co-programmer: ... */ #include "load_param.h" #include "list.h" #include "base_object.h" #include BaseLoadParam::BaseLoadParam(BaseObject* object, const char* paramName, int paramCount, ...) { this->paramDesc = NULL; if (LoadClassDescription::parametersDescription) { // locating the class this->classDesc = LoadClassDescription::addClass(object->getClassName()); this->paramDesc = this->classDesc->addParam(paramName); this->paramDesc->types = new char*[paramCount]; this->paramDesc->paramCount = paramCount; va_list types; va_start (types, paramCount); for(int i = 0; i < paramCount; i++) { const char* tmpTypeName = va_arg (types, const char*); this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1]; strcpy(this->paramDesc->types[i], tmpTypeName); } va_end(types); int argCount = 0; } } void BaseLoadParam::describe(const char* descriptionText) { if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription()) { this->paramDesc->setDescription(descriptionText); } } LoadParamDescription::LoadParamDescription(const char* paramName) { this->types = NULL; this->description = NULL; this->paramName = new char[strlen(paramName)+1]; strcpy(this->paramName, paramName); } LoadParamDescription::~LoadParamDescription(void) { for(int i = 0; i < this->paramCount; i++) { delete this->types[i]; } delete []this->types; delete []this->paramName; } void LoadParamDescription::setDescription(const char* descriptionText) { this->description = descriptionText; } void LoadParamDescription::print(void) const { PRINT(3)(" <%s>", this->paramName); for (int i = 0; i < this->paramCount; i++) { if (i > 0) PRINT(3)(","); PRINT(3)("%s", this->types[i]); } PRINT(3)("", this->paramName); if (this->description) PRINT(3)(" -- %s", this->description); PRINT(3)("\n"); } tList* LoadClassDescription::classList = new tList; /** \brief if the description of Parameters should be executed */ bool LoadClassDescription::parametersDescription = true; LoadClassDescription::LoadClassDescription(const char* className) { this->className = new char[strlen(className)+1]; strcpy(this->className, className); classList->add(this); this->paramList = new tList; } LoadClassDescription::~LoadClassDescription(void) { delete []this->className; tIterator* iterator = this->paramList->getIterator(); LoadParamDescription* enumParamDesc = iterator->nextElement(); while (enumParamDesc) { delete enumParamDesc; enumParamDesc = iterator->nextElement(); } delete iterator; } LoadClassDescription* LoadClassDescription::addClass(const char* className) { tIterator* iterator = LoadClassDescription::classList->getIterator(); LoadClassDescription* enumClassDesc = iterator->nextElement(); while (enumClassDesc) { if (!strcmp(enumClassDesc->className, className)) { delete iterator; return enumClassDesc; } enumClassDesc = iterator->nextElement(); } delete iterator; return new LoadClassDescription(className); } LoadParamDescription* LoadClassDescription::addParam(const char* paramName) { tIterator* iterator = this->paramList->getIterator(); LoadParamDescription* enumParamDesc = iterator->nextElement(); while (enumParamDesc) { if (!strcmp(enumParamDesc->paramName, paramName)) { delete iterator; return enumParamDesc; } enumParamDesc = iterator->nextElement(); } delete iterator; this->paramList->add(new LoadParamDescription(paramName)); return paramList->lastElement(); } void LoadClassDescription::printAll(void) { PRINT(3)("==============================================================\n"); PRINT(3)(" Listing all the Loadable Options (loaded since Game started.\n\n"); tIterator* classIT = LoadClassDescription::classList->getIterator(); LoadClassDescription* enumClassDesc = classIT->nextElement(); while (enumClassDesc) { PRINT(3)("<%s>\n", enumClassDesc->className); tIterator* paramIT = enumClassDesc->paramList->getIterator(); LoadParamDescription* enumParamDesc = paramIT->nextElement(); while (enumParamDesc) { enumParamDesc->print(); enumParamDesc = paramIT->nextElement(); } delete paramIT; PRINT(3)("\n\n", enumClassDesc->className); enumClassDesc = classIT->nextElement(); } delete classIT; }