- Timestamp:
- Aug 27, 2005, 12:01:59 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/functor_list.h
r5137 r5142 28 28 #ifndef __FUNCTOR_PARAMETERS__ 29 29 #define __FUNCTOR_PARAMETERS__ 30 31 //! defines the maximum count of arguments function pointers might have 32 #define FUNCTOR_MAX_ARGUMENTS 5 30 33 31 34 typedef enum ParameterType -
trunk/src/util/shell_command.cc
r5141 r5142 45 45 46 46 // handling parameters, and storing them: 47 if (paramCount > FUNCTOR_MAX_ARGUMENTS) 48 paramCount = FUNCTOR_MAX_ARGUMENTS; 47 49 this->paramCount = paramCount; 48 50 this->parameters = new ParameterType[paramCount]; 49 51 50 52 for (unsigned int i = 0; i < paramCount; i++) 53 { 51 54 parameters[i] = va_arg(parameters, long); 55 56 switch (parameters[i]) 57 { 58 case ParameterBool: 59 this->defaultBools[i] = va_arg(parameters, int); 60 break; 61 case ParameterChar: 62 this->defaultStrings[i] = new char[2]; 63 sprintf(this->defaultStrings[0], "%c", va_arg(parameters, int)); 64 break; 65 case ParameterString: 66 this->defaultStrings[i] = va_arg(parameters, char*); 67 break; 68 case ParameterInt: 69 this->defaultInts[i] = va_arg(parameters, int); 70 break; 71 case ParameterUInt: 72 this->defaultInts[i] = va_arg(parameters, unsigned int); 73 break; 74 case ParameterFloat: 75 this->defaultFloats[i] = va_arg(parameters, double); 76 break; 77 case ParameterLong: 78 this->defaultInts[i] = va_arg(parameters, long); 79 break; 80 default: 81 break; 82 } 83 } 52 84 53 85 // adding this ShellCommand to the list of known Commands … … 65 97 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...) 66 98 { 67 68 99 va_list parameters; 69 100 va_start(parameters, paramCount); … … 97 128 return false; 98 129 99 const char* commandEnd = strchr(executionString, ' ');100 if (commandEnd == NULL)101 commandEnd = executionString + strlen(executionString);102 103 130 tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator(); 104 131 ShellCommandBase* elem = iterator->firstElement(); … … 106 133 { 107 134 printf("%s\n", elem->getName()); 108 if (!strncmp(executionString, elem->getName(), strlen(elem->getName()))) 135 if (!strncasecmp (executionString, elem->className, strlen(elem->className)) && 136 (*(executionString+strlen(elem->className)) == ' ' || 137 *(executionString+strlen(elem->className)) == ':' )) 109 138 { 110 elem->executeCommand(commandEnd); 139 const char* commandBegin = executionString + strlen(elem->className); 140 141 PRINTF(4)("Class %s matches\n", elem->className); 142 BaseObject* objectPointer = NULL; 143 if (elem->isSingleton) 144 { 145 while(*commandBegin == ' ') 146 commandBegin++; 147 if (strncmp (commandBegin, elem->getName(), strlen(elem->getName()))) 148 continue; 149 objectPointer = ClassList::getList(elem->classID)->firstElement(); 150 } 151 else 152 { 153 154 } 155 const char* commandEnd = strchr(commandBegin, ' '); 156 if (commandEnd == NULL) 157 commandEnd = executionString + strlen(executionString); 158 159 if (objectPointer != NULL) 160 elem->executeCommand(objectPointer, commandEnd); 111 161 delete iterator; 112 162 return true; -
trunk/src/util/shell_command.h
r5141 r5142 26 26 /////////////////////// 27 27 28 // COMMAND REGISTRATION 29 // NO ARGUMENTS 30 #define ShellCommandRegister0 \ 31 static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \ 32 { \ 33 if (isRegistered(commandName, classID, 0)== true) \ 34 return; \ 35 new ShellCommand<T>(commandName, classID, functionPointer); \ 36 } 28 37 29 #define ShellCommand2(type1, type2) \ 30 public: \ 31 static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \ 32 type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ 38 39 #define ShellCommandConstructor0 \ 40 void (T::*functionPointer_NULL)(); \ 41 ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \ 42 : ShellCommandBase (commandName, classID, 0) \ 33 43 { \ 34 if (isRegistered(commandName, classID, 2, type1##_PARAM, type2##_PARAM) == true) \ 44 this->functionPointer_NULL = functionPointer; \ 45 } 46 47 48 49 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) \ 35 55 return; \ 36 56 else \ 37 57 ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \ 38 } \39 private: \40 void (T::*functionPointer_##type1_##type2)(type1##_TYPE, type2##_TYPE); \41 ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \42 type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \43 { \44 this->functionPointer_##type1_##type2 = function; \45 58 } 46 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 47 70 48 71 … … 66 89 67 90 private: 68 virtual void executeCommand ( const char* parameters) = NULL;91 virtual void executeCommand (BaseObject* object, const char* parameters) = NULL; 69 92 70 93 protected: … … 78 101 const char* className; //!< The Name of the Class associated to this Command 79 102 103 char* defaultStrings[FUNCTOR_MAX_ARGUMENTS]; 104 int defaultInts[FUNCTOR_MAX_ARGUMENTS]; 105 float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; 106 bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; 107 108 80 109 // STATIC MEMBERS 81 110 static tList<ShellCommandBase>* commandList; //!< A list of availiable commands. … … 83 112 84 113 template<class T> class ShellCommand; 85 114 /* 86 115 template<class T> class ShellCommandSingleton : public ShellCommandBase 87 116 { … … 92 121 { 93 122 this->functionPointer_NULL = functionPointer; 94 95 123 } 96 124 void (T::*functionPointer_NULL)(); 125 97 126 virtual void executeCommand (const char* parameters) 98 127 { … … 100 129 (T::getInstance()->*functionPointer_NULL)(); 101 130 } 102 }; 131 };*/ 103 132 104 133 … … 109 138 static void unregisterCommand(const char* commandNaame, ClassID classID); 110 139 111 static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) 112 { 113 if (isRegistered(commandName, classID, 0)== true) 114 return; 115 else 116 { 117 if (classID & CL_MASK_SINGLETON == CL_MASK_SINGLETON) 118 new ShellCommandSingleton<T>(commandName, classID, functionPointer); 119 else 120 new ShellCommand<T>(commandName, classID, functionPointer); 121 } 122 } 140 #define FUNCTOR_LIST(x) ShellCommandRegister ## x 141 //#include "functor_list.h" 142 FUNCTOR_LIST(0); 143 #undef FUNCTOR_LIST 144 123 145 124 146 private: 125 void (T::*functionPointer_NULL)(); 126 ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) 127 : ShellCommandBase (commandName, classID, 0) 147 #define FUNCTOR_LIST(x) ShellCommandConstructor ## x 148 //#include "functor_list.h" 149 FUNCTOR_LIST(0); 150 #undef FUNCTOR_LIST 151 152 virtual void executeCommand (BaseObject* object, const char* parameters) 128 153 { 129 this->functionPointer_NULL = functionPointer; 130 } 131 virtual void executeCommand (const char* parameters) 132 { 133 printf("not implemented yet\n"); 134 /* if (this->paramCount == 0) 135 (objectPointer->*functionPointer_NULL)();*/ 154 printf("not implemented yet\n"); 155 if (this->paramCount == 0) 156 (dynamic_cast<T*>(object)->*functionPointer_NULL)(); 136 157 } 137 158
Note: See TracChangeset
for help on using the changeset viewer.