| 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 "executor.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "debug.h" | 
|---|
| 21 | #include "class_list.h" | 
|---|
| 22 |  | 
|---|
| 23 | #include "key_names.h" | 
|---|
| 24 | #include <stdarg.h> | 
|---|
| 25 | #include <stdio.h> | 
|---|
| 26 | #include <string.h> | 
|---|
| 27 |  | 
|---|
| 28 | using namespace std; | 
|---|
| 29 |  | 
|---|
| 30 | //////////////////////// | 
|---|
| 31 | // SHELL COMMAND BASE // | 
|---|
| 32 | //////////////////////// | 
|---|
| 33 | // empty constructor | 
|---|
| 34 | Executor::Executor() | 
|---|
| 35 | { | 
|---|
| 36 |   this->defaultValue = NULL; | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | /** | 
|---|
| 40 |  * constructs and registers a new Command | 
|---|
| 41 |  * @param commandName the name of the Command | 
|---|
| 42 |  * @param className the name of the class to apply this command to | 
|---|
| 43 |  * @param paramCount the count of parameters this command takes | 
|---|
| 44 |  */ | 
|---|
| 45 | Executor::Executor(unsigned int paramCount, ...) | 
|---|
| 46 | { | 
|---|
| 47 |   this->setClassID(CL_EXECUTOR, "Executor"); | 
|---|
| 48 |  | 
|---|
| 49 |   if (paramCount > FUNCTOR_MAX_ARGUMENTS) | 
|---|
| 50 |     paramCount = FUNCTOR_MAX_ARGUMENTS; | 
|---|
| 51 |   // reading in Parameters. | 
|---|
| 52 |   this->paramCount = paramCount; | 
|---|
| 53 |   this->defaultValue = new MultiType[paramCount]; | 
|---|
| 54 |  | 
|---|
| 55 |   va_list parameterList; | 
|---|
| 56 |   va_start(parameterList, paramCount); | 
|---|
| 57 |  | 
|---|
| 58 |   // What Parameters we have got | 
|---|
| 59 |   for (unsigned int i = 0; i < paramCount; i++) | 
|---|
| 60 |   { | 
|---|
| 61 |     int type = va_arg(parameterList, int); | 
|---|
| 62 |     this->defaultValue[i].setType((MT_Type)type); | 
|---|
| 63 |   } | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | /** | 
|---|
| 67 |  * deconstructs a Executor | 
|---|
| 68 |  */ | 
|---|
| 69 | Executor::~Executor() | 
|---|
| 70 | { | 
|---|
| 71 |   delete[] this->defaultValue; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | /** | 
|---|
| 75 |  * clones this element into executor. | 
|---|
| 76 |  */ | 
|---|
| 77 | void Executor::cloning(Executor* executor) const | 
|---|
| 78 | { | 
|---|
| 79 |   executor->functorType  = this->functorType; | 
|---|
| 80 |   executor->paramCount   = this->paramCount; | 
|---|
| 81 |   executor->defaultValue = new MultiType[this->paramCount]; | 
|---|
| 82 |   for (unsigned int i = 0; i < this->paramCount; i++) | 
|---|
| 83 |   { | 
|---|
| 84 |     executor->defaultValue[i] =  this->defaultValue[i]; | 
|---|
| 85 | //    printf("1: %s 2: %s\n", MultiType::MultiTypeToString(this->defaultValue[i].getType()),  MultiType::MultiTypeToString(executor->defaultValue[i].getType())); | 
|---|
| 86 |   } | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 |  | 
|---|
| 90 |  | 
|---|
| 91 | /** | 
|---|
| 92 |  * sets default Values of the Commands | 
|---|
| 93 |  * @param count how many default Values to set. | 
|---|
| 94 |  * @param ... the default Values in order. They will be cast to the right type | 
|---|
| 95 |  * @returns itself | 
|---|
| 96 |  * | 
|---|
| 97 |  * Be aware, that when you use this Function, you !!MUST!! match the input as | 
|---|
| 98 |  * count, [EXACTLY THE SAME AS IF YOU WOULD CALL THE FUNCTION UP TO count ARGUMENTS] | 
|---|
| 99 |  */ | 
|---|
| 100 | Executor* Executor::defaultValues(unsigned int count, ...) | 
|---|
| 101 | { | 
|---|
| 102 |   va_list values; | 
|---|
| 103 |   va_start(values, count); | 
|---|
| 104 |  | 
|---|
| 105 |   this->defaultValues(count, values); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | Executor* Executor::defaultValues(unsigned int count, va_list values) | 
|---|
| 109 | { | 
|---|
| 110 |   if (this == NULL) | 
|---|
| 111 |     return NULL; | 
|---|
| 112 |   if (count == 0) | 
|---|
| 113 |     return this; | 
|---|
| 114 |   if (count > this->paramCount) | 
|---|
| 115 |     count = this->paramCount; | 
|---|
| 116 |  | 
|---|
| 117 |  | 
|---|
| 118 |   for (unsigned int i = 0; i < count; i++) | 
|---|
| 119 |   { | 
|---|
| 120 |     switch (this->defaultValue[i].getType()) | 
|---|
| 121 |     { | 
|---|
| 122 |       case MT_BOOL: | 
|---|
| 123 |         this->defaultValue[i].setInt(va_arg(values, int)); | 
|---|
| 124 |         break; | 
|---|
| 125 |       case MT_CHAR: | 
|---|
| 126 |         this->defaultValue[i].setChar((char)va_arg(values, int)); | 
|---|
| 127 |         break; | 
|---|
| 128 |       case MT_STRING: | 
|---|
| 129 |         this->defaultValue[i].setString(va_arg(values, char*)); | 
|---|
| 130 |         break; | 
|---|
| 131 |       case MT_INT: | 
|---|
| 132 |         this->defaultValue[i].setInt(va_arg(values, int)); | 
|---|
| 133 |         break; | 
|---|
| 134 | /*      case MT_UINT: | 
|---|
| 135 |         this->defaultValue[i].setInt((int)va_arg(values, unsigned int)); | 
|---|
| 136 |         break;*/ | 
|---|
| 137 |       case MT_FLOAT: | 
|---|
| 138 |         this->defaultValue[i].setFloat(va_arg(values, double)); | 
|---|
| 139 |         break; | 
|---|
| 140 | /*      case MT_LONG: | 
|---|
| 141 |         this->defaultValue[i].setInt((int) va_arg(values, long)); | 
|---|
| 142 |         break;*/ | 
|---|
| 143 |       default: | 
|---|
| 144 |         break; | 
|---|
| 145 |     } | 
|---|
| 146 |   } | 
|---|
| 147 |   return this; | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 | /** | 
|---|
| 151 |  * prints out nice information about the Executor | 
|---|
| 152 |  */ | 
|---|
| 153 | void Executor::debug() | 
|---|
| 154 | { | 
|---|
| 155 | /*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator(); | 
|---|
| 156 |   ExecutorClass* elemCL = iteratorCL->firstElement(); | 
|---|
| 157 |   while(elemCL != NULL) | 
|---|
| 158 |   { | 
|---|
| 159 |     PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); | 
|---|
| 160 |     tIterator<Executor>* iterator = elemCL->commandList->getIterator(); | 
|---|
| 161 |     const Executor* elem = iterator->firstElement(); | 
|---|
| 162 |     while(elem != NULL) | 
|---|
| 163 |     { | 
|---|
| 164 |       PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount); | 
|---|
| 165 |       for (unsigned int i = 0; i< elem->paramCount; i++) | 
|---|
| 166 |        printf("%s ", Executor::paramToString(elem->parameters[i])); | 
|---|
| 167 |       if (elem->description != NULL) | 
|---|
| 168 |        printf("- %s", elem->description); | 
|---|
| 169 |       printf("\n"); | 
|---|
| 170 |  | 
|---|
| 171 |       elem = iterator->nextElement(); | 
|---|
| 172 |     } | 
|---|
| 173 |     delete iterator; | 
|---|
| 174 |     elemCL = iteratorCL->nextElement(); | 
|---|
| 175 |   } | 
|---|
| 176 |   delete iteratorCL;*/ | 
|---|
| 177 | } | 
|---|