[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[5068] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[5632] | 18 | #include "executor.h" |
---|
[1853] | 19 | |
---|
[5129] | 20 | #include "debug.h" |
---|
[5113] | 21 | #include "class_list.h" |
---|
| 22 | |
---|
| 23 | #include "key_names.h" |
---|
[5075] | 24 | #include <stdarg.h> |
---|
| 25 | #include <stdio.h> |
---|
[5174] | 26 | #include <string.h> |
---|
[5075] | 27 | |
---|
[1856] | 28 | using namespace std; |
---|
[1853] | 29 | |
---|
[5552] | 30 | //////////////////////// |
---|
| 31 | // SHELL COMMAND BASE // |
---|
| 32 | //////////////////////// |
---|
[5641] | 33 | // empty constructor |
---|
| 34 | Executor::Executor() |
---|
| 35 | { |
---|
| 36 | this->defaultValue = NULL; |
---|
| 37 | } |
---|
| 38 | |
---|
[5170] | 39 | /** |
---|
[5166] | 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 | */ |
---|
[5636] | 45 | Executor::Executor(unsigned int paramCount, ...) |
---|
[3365] | 46 | { |
---|
[5632] | 47 | this->setClassID(CL_EXECUTOR, "Executor"); |
---|
[5141] | 48 | |
---|
[5142] | 49 | if (paramCount > FUNCTOR_MAX_ARGUMENTS) |
---|
| 50 | paramCount = FUNCTOR_MAX_ARGUMENTS; |
---|
[5633] | 51 | // reading in Parameters. |
---|
[5130] | 52 | this->paramCount = paramCount; |
---|
[5552] | 53 | this->defaultValue = new MultiType[paramCount]; |
---|
[5130] | 54 | |
---|
[5148] | 55 | va_list parameterList; |
---|
| 56 | va_start(parameterList, paramCount); |
---|
| 57 | |
---|
[5552] | 58 | // What Parameters we have got |
---|
[5130] | 59 | for (unsigned int i = 0; i < paramCount; i++) |
---|
[5659] | 60 | { |
---|
| 61 | int type = va_arg(parameterList, int); |
---|
| 62 | this->defaultValue[i].setType(type); |
---|
| 63 | } |
---|
[5068] | 64 | } |
---|
[4320] | 65 | |
---|
[5166] | 66 | /** |
---|
[5632] | 67 | * deconstructs a Executor |
---|
[5166] | 68 | */ |
---|
[5632] | 69 | Executor::~Executor() |
---|
[5130] | 70 | { |
---|
[5552] | 71 | delete[] this->defaultValue; |
---|
[5130] | 72 | } |
---|
[1853] | 73 | |
---|
[5166] | 74 | /** |
---|
[5641] | 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++) |
---|
[5659] | 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 | } |
---|
[5641] | 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | /** |
---|
[5207] | 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 | */ |
---|
[5632] | 100 | Executor* Executor::defaultValues(unsigned int count, ...) |
---|
[5207] | 101 | { |
---|
[5635] | 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 | { |
---|
[5207] | 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 | { |
---|
[5633] | 120 | switch (this->defaultValue[i].getType()) |
---|
[5207] | 121 | { |
---|
[5633] | 122 | case MT_BOOL: |
---|
[5635] | 123 | this->defaultValue[i].setInt(va_arg(values, int)); |
---|
[5207] | 124 | break; |
---|
[5633] | 125 | case MT_CHAR: |
---|
[5635] | 126 | this->defaultValue[i].setChar((char)va_arg(values, int)); |
---|
[5207] | 127 | break; |
---|
[5633] | 128 | case MT_STRING: |
---|
[5635] | 129 | this->defaultValue[i].setString(va_arg(values, char*)); |
---|
[5207] | 130 | break; |
---|
[5633] | 131 | case MT_INT: |
---|
[5635] | 132 | this->defaultValue[i].setInt(va_arg(values, int)); |
---|
[5207] | 133 | break; |
---|
[5633] | 134 | /* case MT_UINT: |
---|
[5635] | 135 | this->defaultValue[i].setInt((int)va_arg(values, unsigned int)); |
---|
[5633] | 136 | break;*/ |
---|
| 137 | case MT_FLOAT: |
---|
[5635] | 138 | this->defaultValue[i].setFloat(va_arg(values, double)); |
---|
[5207] | 139 | break; |
---|
[5633] | 140 | /* case MT_LONG: |
---|
[5635] | 141 | this->defaultValue[i].setInt((int) va_arg(values, long)); |
---|
[5633] | 142 | break;*/ |
---|
[5207] | 143 | default: |
---|
| 144 | break; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | return this; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | /** |
---|
[5632] | 151 | * prints out nice information about the Executor |
---|
[5166] | 152 | */ |
---|
[5632] | 153 | void Executor::debug() |
---|
[5148] | 154 | { |
---|
[5632] | 155 | /* tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator(); |
---|
| 156 | ExecutorClass* elemCL = iteratorCL->firstElement(); |
---|
[5170] | 157 | while(elemCL != NULL) |
---|
[5148] | 158 | { |
---|
[5171] | 159 | PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize()); |
---|
[5632] | 160 | tIterator<Executor>* iterator = elemCL->commandList->getIterator(); |
---|
| 161 | const Executor* elem = iterator->firstElement(); |
---|
[5172] | 162 | while(elem != NULL) |
---|
[5170] | 163 | { |
---|
[5171] | 164 | PRINT(0)(" command:'%s' : params:%d: ", elem->getName(), elem->paramCount); |
---|
[5170] | 165 | for (unsigned int i = 0; i< elem->paramCount; i++) |
---|
[5632] | 166 | printf("%s ", Executor::paramToString(elem->parameters[i])); |
---|
[5170] | 167 | if (elem->description != NULL) |
---|
| 168 | printf("- %s", elem->description); |
---|
| 169 | printf("\n"); |
---|
[5148] | 170 | |
---|
[5170] | 171 | elem = iterator->nextElement(); |
---|
| 172 | } |
---|
| 173 | delete iterator; |
---|
| 174 | elemCL = iteratorCL->nextElement(); |
---|
[5148] | 175 | } |
---|
[5632] | 176 | delete iteratorCL;*/ |
---|
[5148] | 177 | } |
---|