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