/* 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 "shell_command.h" #include "list.h" #include "debug.h" #include "class_list.h" #include "key_names.h" #include #include using namespace std; ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters) { this->classID = classID; this->functionPointer = functionPointer; this->commandName = new char[strlen(commandName)+1]; strcpy(this->commandName, commandName); // handling parameters, and storing them: this->paramCount = paramCount; this->parameters = new ShellParameterType[paramCount]; for (unsigned int i = 0; i < paramCount; i++) parameters[i] = va_arg(parameters, long); // adding this ShellCommand to the list of known Commands ShellCommandBase::commandList->add(this); } ShellCommandBase::~ShellCommandBase() { delete[] this->commandName; delete[] this->parameters; } tList* ShellCommandBase::commandList = NULL; bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters) { if (ShellCommandBase::commandList == NULL) { ShellCommandBase::commandList = new tList; return false; } tIterator* iterator = ShellCommandBase::commandList->getIterator(); ShellCommandBase* elem = iterator->firstElement(); while(elem != NULL) { if (classID == elem->classID && !strcmp(commandName, elem->commandName)) { // PRINTF(2)("Command already registered\n"); delete iterator; return true; } elem = iterator->nextElement(); } delete iterator; return true; }