Changeset 5166 in orxonox.OLD for trunk/src/lib/shell/shell_command.h
- Timestamp:
- Sep 6, 2005, 1:45:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command.h
r5165 r5166 15 15 #include <stdarg.h> 16 16 17 #define SHELL_COMMAND_MAX_SIZE17 #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command 18 18 19 19 … … 22 22 template<class T> class tList; 23 23 24 /** 25 * an easy to use Macro to create a Command 26 * @param command the name of the command (without "" around the string) 27 * @param class the name of the class to apply this command to (without the "" around the string) 28 * @param function the function to call 29 */ 24 30 #define SHELL_COMMAND(command, class, function) \ 25 31 ShellCommandBase* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function) … … 37 43 ShellCommandBase* describe(const char* description); 38 44 45 /** @returns the CommandList of the Shell */ 39 46 static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; }; 40 47 41 48 static void unregisterAllCommands(); 42 static void unregisterCommand(const char* commandNa ame, const char* className);49 static void unregisterCommand(const char* commandName, const char* className); 43 50 44 51 static void debug(); … … 54 61 55 62 private: 63 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ 56 64 virtual void executeCommand (BaseObject* object, const char* parameters) = NULL; 57 65 58 66 protected: 59 67 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) 60 unsigned int paramCount; //!< the count of parameters 61 unsigned int* parameters; //!< Parameters 62 char* defaultStrings[FUNCTOR_MAX_ARGUMENTS]; 63 int defaultInts[FUNCTOR_MAX_ARGUMENTS]; 64 float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; 65 bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; 68 unsigned int paramCount; //!< the count of parameters. 69 unsigned int* parameters; //!< Parameters the function of this Command takes. 70 char* defaultStrings[FUNCTOR_MAX_ARGUMENTS];//!< A list of default Strings stored. 71 int defaultInts[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Ints stored. 72 float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Floats stored. 73 bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Bools stored. 66 74 67 75 private: … … 69 77 const char* className; //!< The Name of the Class associated to this Command 70 78 71 const char* description; 79 const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); 72 80 73 81 // STATIC MEMBERS … … 81 89 // MACRO DEFINITIONS // 82 90 /////////////////////// 91 //! where to chek for default BOOL values 83 92 #define l_BOOL_DEFGRAB(i) this->defaultBools[i] 93 //! where to chek for default INT values 84 94 #define l_INT_DEFGRAB(i) this->defaultInts[i] 95 //! where to chek for default UINT values 85 96 #define l_UINT_DEFGRAB(i) (unsigned int)this->defaultInts[i] 97 //! where to chek for default LONG values 86 98 #define l_LONG_DEFGRAB(i) (long)this->defaultInts[i] 99 //! where to chek for default FLOAT values 87 100 #define l_FLOAT_DEFGRAB(i) this->defaultFloats[i] 101 //! where to chek for default STRING values 88 102 #define l_STRING_DEFGRAB(i) this->defaultStrings[i] 89 103 … … 91 105 // COMMAND REGISTRATION // 92 106 ////////////////////////// 93 // NO ARGUMENTS107 //! registers a command without any parameters 94 108 #define ShellCommandRegister0() \ 95 109 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)()) \ … … 100 114 } 101 115 116 //! registers a command with 1 parameter 102 117 #define ShellCommandRegister1(t1) \ 103 118 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \ … … 108 123 } 109 124 125 //! registers a command with 2 parameters 110 126 #define ShellCommandRegister2(t1,t2) \ 111 127 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \ … … 116 132 } 117 133 134 //! registers a command with 3 parameters 118 135 #define ShellCommandRegister3(t1,t2,t3) \ 119 136 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \ … … 124 141 } 125 142 143 //! registers a command with 4 parameters 126 144 #define ShellCommandRegister4(t1,t2,t3,t4) \ 127 145 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \ … … 132 150 } 133 151 152 //! registers a command with 5 parameters 134 153 #define ShellCommandRegister5(t1,t2,t3,t4,t5) \ 135 154 static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \ … … 143 162 // CONSTRUCTORS // 144 163 ///////////////// 164 //! creates a command that takes no parameters 145 165 #define ShellCommandConstructor0() \ 146 166 void (T::*functionPointer_0)(); \ … … 151 171 } 152 172 173 //! creates a command that takes one parameter 153 174 #define ShellCommandConstructor1(t1) \ 154 175 void (T::*functionPointer_1_##t1)(t1##_TYPE); \ … … 159 180 } 160 181 182 //! creates a command that takes two parameters 161 183 #define ShellCommandConstructor2(t1,t2) \ 162 184 void (T::*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \ … … 167 189 } 168 190 191 //! creates a command that takes three parameter 169 192 #define ShellCommandConstructor3(t1,t2,t3) \ 170 193 void (T::*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \ … … 175 198 } 176 199 200 //! creates a command that takes four parameter 177 201 #define ShellCommandConstructor4(t1,t2,t3,t4) \ 178 202 void (T::*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \ … … 183 207 } 184 208 209 //! creates a command that takes five parameter 185 210 #define ShellCommandConstructor5(t1,t2,t3,t4,t5) \ 186 211 void (T::*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \ … … 194 219 // EXECUTION // 195 220 /////////////// 221 //! execute-macro for functions with no parameters 196 222 #define ShellCommandExecute0() \ 197 223 if (this->paramCount == 0) \ 198 224 (dynamic_cast<T*>(object)->*functionPointer_0)() 199 225 226 //! execute-macro for functions with one parameter 200 227 #define ShellCommandExecute1(t1) \ 201 228 else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \ 202 229 (dynamic_cast<T*>(object)->*functionPointer_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0))) 203 230 231 //! execute-macro for functions with two parameters 204 232 #define ShellCommandExecute2(t1,t2) \ 205 233 else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \ 206 234 (dynamic_cast<T*>(object)->*functionPointer_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1))) 207 235 236 //! execute-macro for functions with three parameters 208 237 #define ShellCommandExecute3(t1,t2,t3) \ 209 238 else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \ 210 239 (dynamic_cast<T*>(object)->*functionPointer_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2))) 211 240 241 //! execute-macro for functions with four parameters 212 242 #define ShellCommandExecute4(t1,t2,t3,t4) \ 213 243 else if (this->paramCount == 4 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM) \ 214 244 (dynamic_cast<T*>(object)->*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3))) 215 245 246 //! execute-macro for functions with five parameters 216 247 #define ShellCommandExecute5(t1,t2,t3,t4,t5) \ 217 248 else if (this->paramCount == 5 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM && this->parameters[4] == t5##_PARAM) \ … … 228 259 #endif 229 260 261 //! FUNCTOR_LIST is the List of command-registerers 230 262 #define FUNCTOR_LIST(x) ShellCommandRegister ## x 231 263 #include "functor_list.h" … … 234 266 235 267 private: 268 //! FUNCTOR_LIST is the List of CommandConstructors 236 269 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x 237 270 #include "functor_list.h" … … 242 275 // if (parameters != NULL) 243 276 SubString sub(parameters); 277 //! FUNCTOR_LIST is the List of Executive Functions 244 278 #define FUNCTOR_LIST(x) ShellCommandExecute ## x 245 279 #include "functor_list.h"
Note: See TracChangeset
for help on using the changeset viewer.