[4838] | 1 | /*! |
---|
[5129] | 2 | * @file shell_command.h |
---|
[5068] | 3 | * Definition of a on-screen-shell |
---|
[5243] | 4 | * |
---|
| 5 | * @todo also take Static functions |
---|
[3245] | 6 | */ |
---|
[1853] | 7 | |
---|
[5129] | 8 | #ifndef _SHELL_COMMAND_H |
---|
| 9 | #define _SHELL_COMMAND_H |
---|
[1853] | 10 | |
---|
[5129] | 11 | #include "base_object.h" |
---|
[1853] | 12 | |
---|
[5141] | 13 | #include "helper_functions.h" |
---|
[5155] | 14 | #include "substring.h" |
---|
[5143] | 15 | #include "functor_list.h" |
---|
[5141] | 16 | |
---|
[5068] | 17 | #include <stdarg.h> |
---|
| 18 | |
---|
[5166] | 19 | #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command |
---|
[5130] | 20 | |
---|
[5127] | 21 | |
---|
[5130] | 22 | |
---|
[4838] | 23 | // FORWARD DECLARATION |
---|
[5068] | 24 | template<class T> class tList; |
---|
[3543] | 25 | |
---|
[5166] | 26 | /** |
---|
| 27 | * an easy to use Macro to create a Command |
---|
| 28 | * @param command the name of the command (without "" around the string) |
---|
| 29 | * @param class the name of the class to apply this command to (without the "" around the string) |
---|
| 30 | * @param function the function to call |
---|
[5179] | 31 | * |
---|
| 32 | * MEANING: |
---|
| 33 | * ShellCommandBase* someUniqueVarName = |
---|
| 34 | * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); |
---|
| 35 | * |
---|
| 36 | * In the Shell you would call this Command using: |
---|
| 37 | * $ ClassName [ObjectName] commandNameInShell [parameters] |
---|
[5166] | 38 | */ |
---|
[5162] | 39 | #define SHELL_COMMAND(command, class, function) \ |
---|
[5164] | 40 | ShellCommandBase* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function) |
---|
[5329] | 41 | /** |
---|
| 42 | * an easy to use Macro to create a Command |
---|
| 43 | * @param command the name of the command (without "" around the string) |
---|
| 44 | * @param class the name of the class to apply this command to (without the "" around the string) |
---|
| 45 | * @param function the function to call |
---|
| 46 | * |
---|
| 47 | * MEANING: |
---|
| 48 | * ShellCommandBase* someUniqueVarName = |
---|
| 49 | * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall); |
---|
| 50 | * |
---|
| 51 | * In the Shell you would call this Command using: |
---|
| 52 | * $ ClassName [ObjectName] commandNameInShell [parameters] |
---|
| 53 | */ |
---|
| 54 | #define SHELL_COMMAND_STATIC(command, class, function) \ |
---|
| 55 | ShellCommandBase* shell_command_##class##_##command = ShellCommandStatic<class>::registerCommand(#command, #class, function) |
---|
[5135] | 56 | |
---|
[5162] | 57 | |
---|
[5328] | 58 | //! an enumerator for the definition of the Type. |
---|
| 59 | typedef enum { |
---|
| 60 | ShellCommand_Objective = 1, |
---|
| 61 | ShellCommand_Static = 2, |
---|
| 62 | } ShellCommand_Type; |
---|
| 63 | |
---|
[5161] | 64 | //////////////// |
---|
| 65 | // BASE CLASS // |
---|
| 66 | //////////////// |
---|
[5170] | 67 | class ShellCommandBase; |
---|
[5190] | 68 | class ShellCommandAlias; |
---|
[5170] | 69 | |
---|
| 70 | //! A class to hold all Classes that have (once) registered Commands. |
---|
| 71 | class ShellCommandClass : public BaseObject |
---|
| 72 | { |
---|
| 73 | friend class ShellCommandBase; |
---|
| 74 | |
---|
| 75 | public: |
---|
[5197] | 76 | /** @returns the CommandClassList */ |
---|
[5170] | 77 | static const tList<ShellCommandClass>* getCommandClassList() { return ShellCommandClass::commandClassList; }; |
---|
[5195] | 78 | static bool getCommandListOfClass(const char* className, tList<const char>* stringList); |
---|
| 79 | static bool getCommandListOfAlias(tList<const char>* aliasList); |
---|
[5190] | 80 | |
---|
[5170] | 81 | static ShellCommandClass* getCommandClass(const char* className); |
---|
[5171] | 82 | static void unregisterAllCommands(); |
---|
[5170] | 83 | |
---|
[5204] | 84 | static void help (const char* className); |
---|
| 85 | |
---|
[5170] | 86 | private: |
---|
| 87 | ShellCommandClass(const char* className); |
---|
| 88 | ~ShellCommandClass(); |
---|
| 89 | |
---|
| 90 | static const ShellCommandClass* isRegistered(const char* className); |
---|
| 91 | static void initCommandClassList(); |
---|
| 92 | |
---|
| 93 | private: |
---|
[5171] | 94 | const char* className; //!< The Name of the Class. This should match the ClassName of the Commands Class. |
---|
| 95 | long classID; //!< The classID of this Class |
---|
| 96 | tList<ShellCommandBase>* commandList; //!< A list of Commands from this Class |
---|
| 97 | static tList<ShellCommandClass>* commandClassList; //!< A list of Classes |
---|
[5195] | 98 | static tList<ShellCommandAlias>* aliasList; //!< An Alias to A Command. (only for classes with one Instance) |
---|
[5170] | 99 | }; |
---|
| 100 | |
---|
| 101 | |
---|
[5161] | 102 | //! a baseClass for all possible ShellCommands |
---|
| 103 | class ShellCommandBase : public BaseObject |
---|
| 104 | { |
---|
[5170] | 105 | friend class ShellCommandClass; |
---|
[5161] | 106 | public: |
---|
| 107 | static bool execute (const char* executionString); |
---|
| 108 | |
---|
[5164] | 109 | ShellCommandBase* describe(const char* description); |
---|
[5190] | 110 | ShellCommandBase* setAlias(const char* alias); |
---|
[5207] | 111 | ShellCommandBase* defaultValues(unsigned int count, ...); |
---|
[5164] | 112 | |
---|
[5166] | 113 | /** @returns the CommandList of the Shell */ |
---|
| 114 | static void unregisterCommand(const char* commandName, const char* className); |
---|
[5161] | 115 | |
---|
| 116 | static void debug(); |
---|
| 117 | |
---|
| 118 | protected: |
---|
| 119 | ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...); |
---|
| 120 | ~ShellCommandBase(); |
---|
| 121 | |
---|
[5328] | 122 | /** @returns the Type of this Function (either static or objective) */ |
---|
| 123 | inline ShellCommand_Type getType() { return this->functorType; }; |
---|
| 124 | |
---|
[5161] | 125 | static bool isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...); |
---|
| 126 | static const char* paramToString(long parameter); |
---|
| 127 | |
---|
| 128 | private: |
---|
[5166] | 129 | /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ |
---|
[5279] | 130 | virtual void executeCommand (BaseObject* object, const char* parameters) = 0; |
---|
[5161] | 131 | |
---|
| 132 | protected: |
---|
[5328] | 133 | ShellCommand_Type functorType; //!< The type of Function we've got (either static or objective). |
---|
[5163] | 134 | void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) |
---|
[5166] | 135 | unsigned int paramCount; //!< the count of parameters. |
---|
| 136 | unsigned int* parameters; //!< Parameters the function of this Command takes. |
---|
| 137 | char* defaultStrings[FUNCTOR_MAX_ARGUMENTS];//!< A list of default Strings stored. |
---|
| 138 | int defaultInts[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Ints stored. |
---|
| 139 | float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Floats stored. |
---|
| 140 | bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Bools stored. |
---|
[5161] | 141 | |
---|
[5328] | 142 | |
---|
[5161] | 143 | private: |
---|
[5170] | 144 | ShellCommandClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to. |
---|
[5196] | 145 | ShellCommandAlias* alias; //!< An Alias for the Class. |
---|
[5161] | 146 | |
---|
[5166] | 147 | const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla"); |
---|
[5161] | 148 | }; |
---|
| 149 | |
---|
| 150 | /////////////////////////////////////////////////// |
---|
| 151 | /////////////////////////////////////////////////// |
---|
| 152 | |
---|
[5326] | 153 | ///////////////////////////////// |
---|
| 154 | // MACRO DEFINITION EXTENSIONS // |
---|
| 155 | ///////////////////////////////// |
---|
[5166] | 156 | //! where to chek for default BOOL values |
---|
[5151] | 157 | #define l_BOOL_DEFGRAB(i) this->defaultBools[i] |
---|
[5166] | 158 | //! where to chek for default INT values |
---|
[5151] | 159 | #define l_INT_DEFGRAB(i) this->defaultInts[i] |
---|
[5166] | 160 | //! where to chek for default UINT values |
---|
[5151] | 161 | #define l_UINT_DEFGRAB(i) (unsigned int)this->defaultInts[i] |
---|
[5166] | 162 | //! where to chek for default LONG values |
---|
[5151] | 163 | #define l_LONG_DEFGRAB(i) (long)this->defaultInts[i] |
---|
[5166] | 164 | //! where to chek for default FLOAT values |
---|
[5151] | 165 | #define l_FLOAT_DEFGRAB(i) this->defaultFloats[i] |
---|
[5166] | 166 | //! where to chek for default STRING values |
---|
[5151] | 167 | #define l_STRING_DEFGRAB(i) this->defaultStrings[i] |
---|
[5135] | 168 | |
---|
[5153] | 169 | ////////////////////////// |
---|
| 170 | // COMMAND REGISTRATION // |
---|
| 171 | ////////////////////////// |
---|
[5326] | 172 | // SHELLCOMMAND can be redefined as ShellCommand or ShellCommandStatic |
---|
| 173 | // SHELLCOMMANDEXECUTER can be redefined too. |
---|
[5327] | 174 | // SHELLCOMMANDINCLASS |
---|
[5328] | 175 | // SHELLCOMMANDTYPE |
---|
[5166] | 176 | //! registers a command without any parameters |
---|
[5153] | 177 | #define ShellCommandRegister0() \ |
---|
[5327] | 178 | static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \ |
---|
[5142] | 179 | { \ |
---|
[5161] | 180 | if (isRegistered(commandName, className, 0)== true) \ |
---|
| 181 | return NULL; \ |
---|
[5327] | 182 | return new SHELLCOMMAND<T>(commandName, className, function); \ |
---|
[5142] | 183 | } |
---|
[5135] | 184 | |
---|
[5166] | 185 | //! registers a command with 1 parameter |
---|
[5145] | 186 | #define ShellCommandRegister1(t1) \ |
---|
[5327] | 187 | static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \ |
---|
[5135] | 188 | { \ |
---|
[5161] | 189 | if (isRegistered(commandName, className, 1, t1##_PARAM)== true) \ |
---|
| 190 | return NULL; \ |
---|
[5327] | 191 | return new SHELLCOMMAND<T>(commandName, className, function, d1); \ |
---|
[5142] | 192 | } |
---|
| 193 | |
---|
[5166] | 194 | //! registers a command with 2 parameters |
---|
[5153] | 195 | #define ShellCommandRegister2(t1,t2) \ |
---|
[5327] | 196 | static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \ |
---|
[5153] | 197 | { \ |
---|
[5161] | 198 | if (isRegistered(commandName, className, 2, t1##_PARAM, t2##_PARAM)== true) \ |
---|
| 199 | return NULL; \ |
---|
[5327] | 200 | return new SHELLCOMMAND<T>(commandName, className, function, d1, d2); \ |
---|
[5153] | 201 | } |
---|
| 202 | |
---|
[5166] | 203 | //! registers a command with 3 parameters |
---|
[5153] | 204 | #define ShellCommandRegister3(t1,t2,t3) \ |
---|
[5327] | 205 | static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \ |
---|
[5153] | 206 | { \ |
---|
[5161] | 207 | if (isRegistered(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \ |
---|
| 208 | return NULL; \ |
---|
[5327] | 209 | return new SHELLCOMMAND<T>(commandName, className, function, d1, d2, d3); \ |
---|
[5153] | 210 | } |
---|
| 211 | |
---|
[5166] | 212 | //! registers a command with 4 parameters |
---|
[5153] | 213 | #define ShellCommandRegister4(t1,t2,t3,t4) \ |
---|
[5327] | 214 | static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*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) \ |
---|
[5153] | 215 | { \ |
---|
[5161] | 216 | if (isRegistered(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \ |
---|
| 217 | return NULL; \ |
---|
[5327] | 218 | return new SHELLCOMMAND<T>(commandName, className, function, d1, d2, d3, d4); \ |
---|
[5153] | 219 | } |
---|
[5161] | 220 | |
---|
[5166] | 221 | //! registers a command with 5 parameters |
---|
[5153] | 222 | #define ShellCommandRegister5(t1,t2,t3,t4,t5) \ |
---|
[5327] | 223 | static SHELLCOMMAND<T>* registerCommand(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*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) \ |
---|
[5153] | 224 | { \ |
---|
[5161] | 225 | if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \ |
---|
| 226 | return NULL; \ |
---|
| 227 | return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4, d5); \ |
---|
[5153] | 228 | } |
---|
| 229 | |
---|
| 230 | ////////////////// |
---|
| 231 | // CONSTRUCTORS // |
---|
| 232 | ///////////////// |
---|
[5166] | 233 | //! creates a command that takes no parameters |
---|
[5153] | 234 | #define ShellCommandConstructor0() \ |
---|
[5327] | 235 | void SHELLCOMMANDINCLASS(*functionPointer_0)(); \ |
---|
| 236 | SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)()) \ |
---|
[5161] | 237 | : ShellCommandBase(commandName, className, 0) \ |
---|
[5142] | 238 | { \ |
---|
[5328] | 239 | this->functorType = SHELLCOMMANDTYPE; \ |
---|
[5145] | 240 | this->functionPointer_0 = function; \ |
---|
[5142] | 241 | } |
---|
| 242 | |
---|
[5166] | 243 | //! creates a command that takes one parameter |
---|
[5145] | 244 | #define ShellCommandConstructor1(t1) \ |
---|
[5327] | 245 | void SHELLCOMMANDINCLASS(*functionPointer_1_##t1)(t1##_TYPE); \ |
---|
| 246 | SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE), t1##_TYPE d1) \ |
---|
[5161] | 247 | : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \ |
---|
[5135] | 248 | { \ |
---|
[5328] | 249 | this->functorType = SHELLCOMMANDTYPE; \ |
---|
[5145] | 250 | this->functionPointer_1_##t1 = function; \ |
---|
[5135] | 251 | } |
---|
| 252 | |
---|
[5166] | 253 | //! creates a command that takes two parameters |
---|
[5153] | 254 | #define ShellCommandConstructor2(t1,t2) \ |
---|
[5327] | 255 | void SHELLCOMMANDINCLASS(*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \ |
---|
| 256 | SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \ |
---|
[5161] | 257 | : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \ |
---|
[5153] | 258 | { \ |
---|
[5328] | 259 | this->functorType = SHELLCOMMANDTYPE; \ |
---|
[5153] | 260 | this->functionPointer_2_##t1##_##t2 = function; \ |
---|
| 261 | } |
---|
[5135] | 262 | |
---|
[5166] | 263 | //! creates a command that takes three parameter |
---|
[5153] | 264 | #define ShellCommandConstructor3(t1,t2,t3) \ |
---|
[5327] | 265 | void SHELLCOMMANDINCLASS(*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \ |
---|
| 266 | SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \ |
---|
[5161] | 267 | : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \ |
---|
[5153] | 268 | { \ |
---|
[5328] | 269 | this->functorType = SHELLCOMMANDTYPE; \ |
---|
[5153] | 270 | this->functionPointer_3_##t1##_##t2##_##t3 = function; \ |
---|
| 271 | } |
---|
[5141] | 272 | |
---|
[5166] | 273 | //! creates a command that takes four parameter |
---|
[5153] | 274 | #define ShellCommandConstructor4(t1,t2,t3,t4) \ |
---|
[5327] | 275 | void SHELLCOMMANDINCLASS(*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \ |
---|
| 276 | SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \ |
---|
[5161] | 277 | : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \ |
---|
[5153] | 278 | { \ |
---|
[5328] | 279 | this->functorType = SHELLCOMMANDTYPE; \ |
---|
[5153] | 280 | this->functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \ |
---|
| 281 | } |
---|
| 282 | |
---|
[5166] | 283 | //! creates a command that takes five parameter |
---|
[5153] | 284 | #define ShellCommandConstructor5(t1,t2,t3,t4,t5) \ |
---|
[5327] | 285 | void SHELLCOMMANDINCLASS(*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \ |
---|
| 286 | SHELLCOMMAND(const char* commandName, const char* className, void SHELLCOMMANDINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \ |
---|
[5161] | 287 | : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \ |
---|
[5153] | 288 | { \ |
---|
[5328] | 289 | this->functorType = SHELLCOMMANDTYPE; \ |
---|
[5153] | 290 | this->functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \ |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | /////////////// |
---|
| 294 | // EXECUTION // |
---|
| 295 | /////////////// |
---|
[5166] | 296 | //! execute-macro for functions with no parameters |
---|
[5153] | 297 | #define ShellCommandExecute0() \ |
---|
[5145] | 298 | if (this->paramCount == 0) \ |
---|
[5326] | 299 | SHELLCOMMANDEXECUTER(_0)() |
---|
[5145] | 300 | |
---|
[5166] | 301 | //! execute-macro for functions with one parameter |
---|
[5145] | 302 | #define ShellCommandExecute1(t1) \ |
---|
[5146] | 303 | else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \ |
---|
[5326] | 304 | SHELLCOMMANDEXECUTER(_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0))) |
---|
[5145] | 305 | |
---|
[5166] | 306 | //! execute-macro for functions with two parameters |
---|
[5153] | 307 | #define ShellCommandExecute2(t1,t2) \ |
---|
| 308 | else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \ |
---|
[5326] | 309 | SHELLCOMMANDEXECUTER(_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1))) |
---|
[5145] | 310 | |
---|
[5166] | 311 | //! execute-macro for functions with three parameters |
---|
[5153] | 312 | #define ShellCommandExecute3(t1,t2,t3) \ |
---|
| 313 | else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \ |
---|
[5326] | 314 | SHELLCOMMANDEXECUTER(_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))) |
---|
[5153] | 315 | |
---|
[5166] | 316 | //! execute-macro for functions with four parameters |
---|
[5153] | 317 | #define ShellCommandExecute4(t1,t2,t3,t4) \ |
---|
| 318 | 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) \ |
---|
[5326] | 319 | SHELLCOMMANDEXECUTER(_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))) |
---|
[5153] | 320 | |
---|
[5166] | 321 | //! execute-macro for functions with five parameters |
---|
[5153] | 322 | #define ShellCommandExecute5(t1,t2,t3,t4,t5) \ |
---|
| 323 | 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) \ |
---|
[5326] | 324 | SHELLCOMMANDEXECUTER(_5_##t1##_##t2##_##t3##_##t4##_##t5)(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)), t5##_FUNC(sub.getString(4), t5##_DEFGRAB(4))) |
---|
[5153] | 325 | |
---|
| 326 | |
---|
[5129] | 327 | //! keeps information about a ShellCommand |
---|
| 328 | template<class T> class ShellCommand : public ShellCommandBase |
---|
| 329 | { |
---|
| 330 | public: |
---|
[5153] | 331 | #ifdef FUNCTOR_LIST |
---|
| 332 | #undef FUNCTOR_LIST |
---|
| 333 | #endif |
---|
[5326] | 334 | #ifdef SHELLCOMMAND |
---|
| 335 | #undef SHELLCOMMAND |
---|
| 336 | #endif |
---|
[5327] | 337 | #define SHELLCOMMAND ShellCommand |
---|
[5326] | 338 | #ifdef SHELLCOMMANDEXECUTER |
---|
| 339 | #undef SHELLCOMMANDEXECUTER |
---|
| 340 | #endif |
---|
[5327] | 341 | #define SHELLCOMMANDEXECUTER(nameExt) (dynamic_cast<T*>(object)->*functionPointer##nameExt) |
---|
| 342 | #ifdef SHELLCOMMANDINCLASS |
---|
| 343 | #undef SHELLCOMMANDINCLASS |
---|
| 344 | #endif |
---|
| 345 | #define SHELLCOMMANDINCLASS(FUNCTION) (T::FUNCTION) |
---|
[5328] | 346 | #ifdef SHELLCOMMANDTYPE |
---|
| 347 | #undef SHELLCOMMANDTYPE |
---|
| 348 | #endif |
---|
| 349 | #define SHELLCOMMANDTYPE ShellCommand_Objective |
---|
[5166] | 350 | //! FUNCTOR_LIST is the List of command-registerers |
---|
[5142] | 351 | #define FUNCTOR_LIST(x) ShellCommandRegister ## x |
---|
[5153] | 352 | #include "functor_list.h" |
---|
[5142] | 353 | #undef FUNCTOR_LIST |
---|
[5136] | 354 | |
---|
[5142] | 355 | |
---|
[5068] | 356 | private: |
---|
[5166] | 357 | //! FUNCTOR_LIST is the List of CommandConstructors |
---|
[5142] | 358 | #define FUNCTOR_LIST(x) ShellCommandConstructor ## x |
---|
[5153] | 359 | #include "functor_list.h" |
---|
[5142] | 360 | #undef FUNCTOR_LIST |
---|
| 361 | |
---|
| 362 | virtual void executeCommand (BaseObject* object, const char* parameters) |
---|
[5135] | 363 | { |
---|
[5204] | 364 | SubString sub(parameters, true); |
---|
[5166] | 365 | //! FUNCTOR_LIST is the List of Executive Functions |
---|
[5145] | 366 | #define FUNCTOR_LIST(x) ShellCommandExecute ## x |
---|
[5153] | 367 | #include "functor_list.h" |
---|
[5135] | 368 | #undef FUNCTOR_LIST |
---|
[5145] | 369 | } |
---|
[5129] | 370 | }; |
---|
[5113] | 371 | |
---|
[5327] | 372 | //! keeps information about a ShellCommand, that points to a Static Function |
---|
[5326] | 373 | template<class T> class ShellCommandStatic : public ShellCommandBase |
---|
| 374 | { |
---|
| 375 | public: |
---|
| 376 | #ifdef FUNCTOR_LIST |
---|
| 377 | #undef FUNCTOR_LIST |
---|
| 378 | #endif |
---|
| 379 | #ifdef SHELLCOMMAND |
---|
| 380 | #undef SHELLCOMMAND |
---|
| 381 | #endif |
---|
| 382 | #define SHELLCOMMAND ShellCommandStatic |
---|
| 383 | #ifdef SHELLCOMMANDEXECUTER |
---|
| 384 | #undef SHELLCOMMANDEXECUTER |
---|
| 385 | #endif |
---|
[5328] | 386 | #define SHELLCOMMANDEXECUTER(nameExt) functionPointer##nameExt |
---|
[5327] | 387 | #ifdef SHELLCOMMANDINCLASS |
---|
| 388 | #undef SHELLCOMMANDINCLASS |
---|
| 389 | #endif |
---|
| 390 | #define SHELLCOMMANDINCLASS(FUNCTION) (FUNCTION) |
---|
[5328] | 391 | #ifdef SHELLCOMMANDTYPE |
---|
| 392 | #undef SHELLCOMMANDTYPE |
---|
| 393 | #endif |
---|
| 394 | #define SHELLCOMMANDTYPE ShellCommand_Static |
---|
[5326] | 395 | |
---|
| 396 | //! FUNCTOR_LIST is the List of command-registerers |
---|
| 397 | #define FUNCTOR_LIST(x) ShellCommandRegister ## x |
---|
| 398 | #include "functor_list.h" |
---|
| 399 | #undef FUNCTOR_LIST |
---|
| 400 | |
---|
| 401 | private: |
---|
| 402 | //! FUNCTOR_LIST is the List of CommandConstructors |
---|
| 403 | #define FUNCTOR_LIST(x) ShellCommandConstructor ## x |
---|
| 404 | #include "functor_list.h" |
---|
| 405 | #undef FUNCTOR_LIST |
---|
| 406 | |
---|
| 407 | virtual void executeCommand (BaseObject* object, const char* parameters) |
---|
| 408 | { |
---|
| 409 | SubString sub(parameters, true); |
---|
| 410 | //! FUNCTOR_LIST is the List of Executive Functions |
---|
| 411 | #define FUNCTOR_LIST(x) ShellCommandExecute ## x |
---|
| 412 | #include "functor_list.h" |
---|
| 413 | #undef FUNCTOR_LIST |
---|
| 414 | } |
---|
| 415 | }; |
---|
| 416 | |
---|
[5197] | 417 | //! A Class, that handles aliases. |
---|
[5190] | 418 | class ShellCommandAlias |
---|
| 419 | { |
---|
[5196] | 420 | friend class ShellCommandBase; |
---|
[5190] | 421 | public: |
---|
[5197] | 422 | /** @returns the Name of the Alias. */ |
---|
[5195] | 423 | const char* getName() const { return this->aliasName; }; |
---|
[5197] | 424 | /** @returns the Command, this Alias is asociated with */ |
---|
[5195] | 425 | ShellCommandBase* getCommand() const { return this->command; }; |
---|
[5196] | 426 | |
---|
[5190] | 427 | private: |
---|
[5197] | 428 | /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */ |
---|
[5196] | 429 | ShellCommandAlias(const char* aliasName, ShellCommandBase* command) { this->aliasName = aliasName; this->command = command; }; |
---|
| 430 | |
---|
| 431 | private: |
---|
[5197] | 432 | const char* aliasName; //!< the name of the Alias |
---|
| 433 | ShellCommandBase* command; //!< a pointer to the command, this alias executes. |
---|
[5190] | 434 | }; |
---|
| 435 | |
---|
[5129] | 436 | #endif /* _SHELL_COMMAND_H */ |
---|