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