Changeset 5639 in orxonox.OLD for trunk/src/lib/shell/shell_command_class.h
- Timestamp:
- Nov 18, 2005, 7:21:32 PM (19 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_command_class.h
r5637 r5639 1 1 /*! 2 * @file shell_command .h2 * @file shell_command_class.h 3 3 * Definition of a on-screen-shell 4 4 */ 5 5 6 #ifndef _SHELL_COMMAND_ H7 #define _SHELL_COMMAND_ H6 #ifndef _SHELL_COMMAND_CLASS_H 7 #define _SHELL_COMMAND_CLASS_H 8 8 9 9 #include "base_object.h" 10 11 #include "helper_functions.h"12 #include "multi_type.h"13 #include "substring.h"14 #include "functor_list.h"15 #include "executor/executor.h"16 #include <stdarg.h>17 18 #define SHELL_COMMAND_MAX_SIZE //!< The maximum size of a Shell Command19 20 10 21 11 22 12 // FORWARD DECLARATION 23 13 template<class T> class tList; 24 25 /**26 * an easy to use Macro to create a Command27 * @param command the name of the command (without "" around the string)28 * @param class the name of the class to apply this command to (without the "" around the string)29 * @param function the function to call30 *31 * MEANING:32 * ShellCommand* someUniqueVarName =33 * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);34 *35 * In the Shell you would call this Command using:36 * $ ClassName [ObjectName] commandNameInShell [parameters]37 */38 //#define SHELL_COMMAND(command, class, function) \39 // ShellCommand* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)40 #define SHELL_COMMAND(command, class, function) \41 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorObjective<class>(&class::function))42 43 /**44 * an easy to use Macro to create a Command45 * @param command the name of the command (without "" around the string)46 * @param class the name of the class to apply this command to (without the "" around the string)47 * @param function the function to call48 *49 * MEANING:50 * ShellCommand* someUniqueVarName =51 * ShellCommand<ClassName>::registerCommand("commandNameInShell", "ClassName", &ClassName::FunctionToCall);52 *53 * In the Shell you would call this Command using:54 * $ ClassName [ObjectName] commandNameInShell [parameters]55 */56 #define SHELL_COMMAND_STATIC(command, class, function) \57 ShellCommand* shell_command_##class##_##command = ShellCommand::registerCommand(#command, #class, new ExecutorStatic<class>(function))58 59 60 //! an enumerator for the definition of the Type.61 typedef enum {62 ShellCommand_Objective = 1,63 ShellCommand_Static = 2,64 } ShellCommand_Type;65 14 66 15 //////////////// … … 96 45 const char* className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 97 46 long classID; //!< The classID of this Class 98 tList<ShellCommand>* commandList; //!< A list of Commands from this Class47 tList<ShellCommand>* commandList; //!< A list of Commands from this Class 99 48 static tList<ShellCommandClass>* commandClassList; //!< A list of Classes 100 49 static tList<ShellCommandAlias>* aliasList; //!< An Alias to A Command. (only for classes with one Instance) 101 50 }; 102 51 103 104 //! a baseClass for all possible ShellCommands105 class ShellCommand : public BaseObject106 {107 friend class ShellCommandClass;108 public:109 static bool execute (const char* executionString);110 111 ShellCommand* describe(const char* description);112 ShellCommand* setAlias(const char* alias);113 ShellCommand* defaultValues(unsigned int count, ...);114 115 static ShellCommand* registerCommand(const char* commandName, const char* className, Executor* executor);116 117 static void unregisterCommand(const char* commandName, const char* className);118 119 static void debug();120 121 protected:122 ShellCommand(const char* commandName, const char* className, Executor* executor);123 ~ShellCommand();124 125 /** @returns the Type of this Function (either static or objective) */126 inline ShellCommand_Type getType() { return this->functorType; };127 128 static bool isRegistered(const char* commandName, const char* className, Executor* executor);129 static const char* paramToString(long parameter);130 131 protected:132 ShellCommand_Type functorType; //!< The type of Function we've got (either static or objective).133 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )134 unsigned int paramCount; //!< the count of parameters.135 unsigned int* parameters; //!< Parameters the function of this Command takes.136 MultiType* defaultValue; //!< Default Values.137 138 private:139 ShellCommandClass* shellClass; //!< A Pointer to the Shell-Class this Command belongs to.140 ShellCommandAlias* alias; //!< An Alias for the Class.141 142 const char* description; //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");143 Executor* executor;144 145 };146 147 //! A Class, that handles aliases.148 class ShellCommandAlias149 {150 friend class ShellCommand;151 public:152 /** @returns the Name of the Alias. */153 const char* getName() const { return this->aliasName; };154 /** @returns the Command, this Alias is asociated with */155 ShellCommand* getCommand() const { return this->command; };156 157 private:158 /** @param aliasName the name of the Alias @param command the Command, to associate this alias with */159 ShellCommandAlias(const char* aliasName, ShellCommand* command) { this->aliasName = aliasName; this->command = command; };160 161 private:162 const char* aliasName; //!< the name of the Alias163 ShellCommand* command; //!< a pointer to the command, this alias executes.164 };165 166 52 #endif /* _SHELL_COMMAND_H */
Note: See TracChangeset
for help on using the changeset viewer.