Changeset 5145 in orxonox.OLD for trunk/src/util
- Timestamp:
- Aug 27, 2005, 2:15:44 AM (19 years ago)
- Location:
- trunk/src/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/shell.cc
r5141 r5145 79 79 80 80 ShellCommand<Shell>::registerCommand("clear", CL_SHELL, &Shell::clear); 81 } 81 ShellCommand<Shell>::registerCommand("testI", CL_SHELL, &Shell::testI); 82 ShellCommand<Shell>::registerCommand("testS", CL_SHELL, &Shell::testS); 83 } 84 85 86 void Shell::testI (int i) 87 { 88 printf("This is the Test for one Int '%d'\n", i); 89 } 90 91 void Shell::testS (const char* s) 92 { 93 printf("This is the Test for one String '%s'\n", s); 94 95 } 96 82 97 83 98 Shell* Shell::singletonRef = NULL; -
trunk/src/util/shell.h
r5141 r5145 38 38 /** @returns a Pointer to the only object of this Class */ 39 39 inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; 40 41 void testI (int i); 42 void testS (const char* s); 40 43 41 44 void activate(); -
trunk/src/util/shell_command.cc
r5144 r5145 123 123 124 124 125 /** 126 * executes commands 127 * @param executionString the string containing the following input 128 * <ClassName> [<ObjectName>] <functionName> [parameter1[,parameter2[,...]]] 129 * @return true on success, false otherwise. 130 */ 125 131 bool ShellCommandBase::execute(const char* executionString) 126 132 { … … 139 145 const char* commandBegin = executionString + strlen(elem->className); 140 146 141 PRINTF( 4)("Class %s matches\n", elem->className);147 PRINTF(5)("Class %s matches\n", elem->className); 142 148 BaseObject* objectPointer = NULL; 143 149 if (elem->isSingleton) … … 151 157 } 152 158 // getting singleton-reference 153 objectPointer = ClassList::getList(elem->classID)->firstElement(); 159 tList<BaseObject>* list = ClassList::getList(elem->classID); 160 if (list) 161 objectPointer = list->firstElement(); 154 162 } 155 163 else … … 158 166 while(*commandBegin == ' ') 159 167 commandBegin++; 160 tIterator<BaseObject>* iterBO = ClassList::getList(elem->classID)->getIterator(); 168 tList<BaseObject>* list = ClassList::getList(elem->classID); 169 if (list == NULL) 170 break; 171 tIterator<BaseObject>* iterBO = list->getIterator(); 161 172 BaseObject* enumBO = iterBO->firstElement(); 162 173 while(enumBO != NULL) … … 164 175 if(!strncmp(commandBegin, enumBO->getName(), strlen(enumBO->getName()))) 165 176 { 166 PRINTF( 4)("Object %s matches\n", enumBO->getName());177 PRINTF(5)("Object %s matches\n", enumBO->getName()); 167 178 objectPointer = enumBO; 168 179 break; … … 184 195 continue; 185 196 } 186 PRINTF( 3)("Function '%s' found\n", commandBegin);197 PRINTF(5)("Function '%s' found\n", commandBegin); 187 198 } 188 199 const char* paramBegin = strchr(commandBegin, ' '); -
trunk/src/util/shell_command.h
r5143 r5145 11 11 #include "helper_functions.h" 12 12 #include "functor_list.h" 13 #include "substring.h" 13 14 14 15 #include <stdarg.h> 15 16 16 #define MAX_SHELL_COMMAND_SIZE17 #define SHELL_COMMAND_MAX_SIZE 17 18 18 19 … … 29 30 // NO ARGUMENTS 30 31 #define ShellCommandRegister0 \ 31 static void registerCommand(const char* commandName, ClassID classID, void (T::*function Pointer)()) \32 static void registerCommand(const char* commandName, ClassID classID, void (T::*function)()) \ 32 33 { \ 33 34 if (isRegistered(commandName, classID, 0)== true) \ 34 35 return; \ 35 new ShellCommand<T>(commandName, classID, functionPointer); \ 36 new ShellCommand<T>(commandName, classID, function); \ 37 } 38 39 #define ShellCommandRegister1(t1) \ 40 static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \ 41 { \ 42 if (isRegistered(commandName, classID, 1, t1##_PARAM)== true) \ 43 return; \ 44 new ShellCommand<T>(commandName, classID, function, d1); \ 36 45 } 37 46 38 47 39 48 #define ShellCommandConstructor0 \ 40 void (T::*functionPointer_ NULL)(); \41 ShellCommand(const char* commandName, ClassID classID, void (T::*function Pointer)()) \42 : ShellCommandBase 49 void (T::*functionPointer_0)(); \ 50 ShellCommand(const char* commandName, ClassID classID, void (T::*function)()) \ 51 : ShellCommandBase(commandName, classID, 0) \ 43 52 { \ 44 this->functionPointer_NULL = functionPointer; \ 53 this->functionPointer_0 = function; \ 54 } 55 56 #define ShellCommandConstructor1(t1) \ 57 void (T::*functionPointer_1_##t1)(t1##_TYPE); \ 58 ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1) \ 59 : ShellCommandBase(commandName, classID, 1, t1##_PARAM, d1) \ 60 { \ 61 this->functionPointer_1_##t1 = function; \ 45 62 } 46 63 47 64 48 65 66 #define ShellCommandExecute0 \ 67 if (this->paramCount == 0) \ 68 (dynamic_cast<T*>(object)->*functionPointer_0)() 49 69 50 #define ShellCommandRegister2(t1, t2) \ 51 static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \ 52 t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \ 53 { \ 54 if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM) == true) \ 55 return; \ 56 else \ 57 ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \ 58 } 59 60 // CONSTRUCTORS AND POINTERS 61 #define ShellCommandConstructor2(t1, t2) \ 62 void (T::*functionPointer_##t1_##t2)(t1##_TYPE, t2##_TYPE); \ 63 ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \ 64 t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \ 65 { \ 66 this->functionPointer_##t1_##t2 = function; \ 67 } 68 69 //#define ShellCommand 70 #define ShellCommandExecute1(t1) \ 71 else if (this->paramCount == 1 && this->parameters[0] & t1##_PARAM) \ 72 (dynamic_cast<T*>(object)->*functionPointer_1_##t1)(0)//t1##_FUNC(parameters, 0)) 70 73 71 74 … … 141 144 //#include "functor_list.h" 142 145 FUNCTOR_LIST(0); 146 FUNCTOR_LIST(1)(l_INT); 147 FUNCTOR_LIST(1)(l_STRING); 143 148 #undef FUNCTOR_LIST 144 149 … … 148 153 //#include "functor_list.h" 149 154 FUNCTOR_LIST(0); 155 FUNCTOR_LIST(1)(l_INT); 156 FUNCTOR_LIST(1)(l_STRING); 150 157 #undef FUNCTOR_LIST 151 158 152 159 virtual void executeCommand (BaseObject* object, const char* parameters) 153 160 { 154 printf("not implemented yet\n"); 155 if (this->paramCount == 0) 156 (dynamic_cast<T*>(object)->*functionPointer_NULL)(); 161 SubString params(parameters, ','); 162 #define FUNCTOR_LIST(x) ShellCommandExecute ## x 163 //#include "functor_list.h" 164 FUNCTOR_LIST(0); 165 FUNCTOR_LIST(1)(l_INT); 166 FUNCTOR_LIST(1)(l_STRING); 167 #undef FUNCTOR_LIST 157 168 } 158 159 160 161 #define FUNCTOR_LIST(x) ShellCommand ## x162 //#include "functor_list.h"163 //FUNCTOR_LIST(2)(l_INT, l_INT);164 #undef FUNCTOR_LIST165 166 169 }; 167 170 168 169 170 171 #endif /* _SHELL_COMMAND_H */
Note: See TracChangeset
for help on using the changeset viewer.