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