[4838] | 1 | /*! |
---|
[5129] | 2 | * @file shell_command.h |
---|
[5068] | 3 | * Definition of a on-screen-shell |
---|
[3245] | 4 | */ |
---|
[1853] | 5 | |
---|
[5129] | 6 | #ifndef _SHELL_COMMAND_H |
---|
| 7 | #define _SHELL_COMMAND_H |
---|
[1853] | 8 | |
---|
[5129] | 9 | #include "base_object.h" |
---|
[1853] | 10 | |
---|
[5068] | 11 | #include <stdarg.h> |
---|
| 12 | |
---|
[5130] | 13 | #define MAX_SHELL_COMMAND_SIZE |
---|
| 14 | |
---|
[5135] | 15 | #include "functor_list.h" |
---|
[5127] | 16 | |
---|
[5130] | 17 | |
---|
[4838] | 18 | // FORWARD DECLARATION |
---|
[5068] | 19 | template<class T> class tList; |
---|
[5118] | 20 | template<class T> class tIterator; |
---|
[3543] | 21 | |
---|
[5135] | 22 | |
---|
| 23 | /////////////////////// |
---|
| 24 | // MACRO DEFINITIONS // |
---|
| 25 | /////////////////////// |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | #define ShellCommand2(type1, type2) \ |
---|
| 29 | public: \ |
---|
| 30 | static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \ |
---|
| 31 | type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ |
---|
| 32 | { \ |
---|
| 33 | if (isRegistered(commandName, classID, 2, type1##_PARAM, type2##_PARAM) == true) \ |
---|
| 34 | return; \ |
---|
| 35 | else \ |
---|
| 36 | ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \ |
---|
| 37 | } \ |
---|
| 38 | private: \ |
---|
| 39 | void (T::*functionPointer_##type1_##type2)(type1##_TYPE, type2##_TYPE); \ |
---|
| 40 | ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \ |
---|
| 41 | type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ |
---|
| 42 | { \ |
---|
| 43 | this->functionPointer_##type1_##type2 = function; \ |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | //////////////// |
---|
| 48 | // BASE CLASS // |
---|
| 49 | //////////////// |
---|
| 50 | //! a baseClass for all possible ShellCommands |
---|
[5130] | 51 | class ShellCommandBase : public BaseObject |
---|
[5129] | 52 | { |
---|
[5068] | 53 | public: |
---|
[5129] | 54 | static bool execute (const char* executionString); |
---|
[2036] | 55 | |
---|
[5135] | 56 | virtual void executeCommand (const char* parameters) = NULL; |
---|
[5130] | 57 | |
---|
[5129] | 58 | protected: |
---|
[5135] | 59 | ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...); |
---|
[5130] | 60 | ~ShellCommandBase(); |
---|
[1853] | 61 | |
---|
[5135] | 62 | static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...); |
---|
[1853] | 63 | |
---|
[3245] | 64 | |
---|
[5130] | 65 | protected: |
---|
| 66 | void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) |
---|
| 67 | unsigned int paramCount; //!< the count of parameters |
---|
[5135] | 68 | ParameterType* parameters; //!< Parameters |
---|
[5130] | 69 | |
---|
[5129] | 70 | private: |
---|
| 71 | char* commandName; //!< The name of the Command when executed |
---|
| 72 | long classID; //!< The ID of the Class asociated to this Command |
---|
[3245] | 73 | |
---|
[5130] | 74 | // STATIC MEMBERS |
---|
[5129] | 75 | static tList<ShellCommandBase>* commandList; //!< A list of availiable commands. |
---|
| 76 | }; |
---|
[5068] | 77 | |
---|
[5136] | 78 | template<class T> class ShellCommand; |
---|
[5135] | 79 | |
---|
[5136] | 80 | template<class T> class ShellCommandSingleton : public ShellCommandBase |
---|
| 81 | { |
---|
| 82 | friend class ShellCommand<T>; |
---|
| 83 | private: |
---|
| 84 | ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)()) |
---|
| 85 | : ShellCommandBase (commandName, classID, 0) |
---|
| 86 | { |
---|
| 87 | this->functionPointer_NULL = functionPointer; |
---|
[5135] | 88 | |
---|
[5136] | 89 | } |
---|
| 90 | void (T::*functionPointer_NULL)(); |
---|
| 91 | virtual void executeCommand (const char* parameters) |
---|
| 92 | { |
---|
| 93 | if (this->paramCount == 0) |
---|
| 94 | (T::getInstance()->*functionPointer_NULL)(); |
---|
| 95 | } |
---|
| 96 | }; |
---|
[5135] | 97 | |
---|
[5136] | 98 | |
---|
[5129] | 99 | //! keeps information about a ShellCommand |
---|
| 100 | template<class T> class ShellCommand : public ShellCommandBase |
---|
| 101 | { |
---|
| 102 | public: |
---|
| 103 | static void unregisterCommand(const char* commandNaame, ClassID classID); |
---|
[5068] | 104 | |
---|
[5136] | 105 | static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)(), bool isSingleton = false) |
---|
[5135] | 106 | { |
---|
| 107 | if (isRegistered(commandName, classID, 0)== true) |
---|
| 108 | return; |
---|
| 109 | else |
---|
[5136] | 110 | { |
---|
| 111 | if (isSingleton == false) |
---|
| 112 | new ShellCommand<T>(commandName, classID, functionPointer); |
---|
| 113 | else |
---|
| 114 | new ShellCommandSingleton<T>(commandName, classID, functionPointer); |
---|
| 115 | } |
---|
[5135] | 116 | } |
---|
[5136] | 117 | |
---|
[5068] | 118 | private: |
---|
[5135] | 119 | void (T::*functionPointer_NULL)(); |
---|
[5136] | 120 | ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) |
---|
[5135] | 121 | : ShellCommandBase (commandName, classID, 0) |
---|
| 122 | { |
---|
| 123 | this->functionPointer_NULL = functionPointer; |
---|
| 124 | } |
---|
| 125 | virtual void executeCommand (const char* parameters) |
---|
| 126 | { |
---|
[5136] | 127 | /* if (this->paramCount == 0) |
---|
| 128 | (objectPointer->*functionPointer_NULL)();*/ |
---|
[5135] | 129 | } |
---|
[5068] | 130 | |
---|
| 131 | |
---|
[5135] | 132 | |
---|
| 133 | #define FUNCTOR_LIST(x) ShellCommand ## x |
---|
| 134 | //#include "functor_list.h" |
---|
| 135 | //ShellCommand2(l_INT, l_INT); |
---|
| 136 | #undef FUNCTOR_LIST |
---|
| 137 | |
---|
| 138 | private: |
---|
[5136] | 139 | // T* objectPointer; //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL ) |
---|
[5129] | 140 | }; |
---|
[5113] | 141 | |
---|
| 142 | |
---|
[5120] | 143 | |
---|
[5129] | 144 | #endif /* _SHELL_COMMAND_H */ |
---|