Changeset 5130 in orxonox.OLD for trunk/src/util
- Timestamp:
- Aug 26, 2005, 12:04:43 AM (19 years ago)
- Location:
- trunk/src/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/shell.cc
r5129 r5130 76 76 evh->subscribe(this, ES_SHELL, i); 77 77 78 79 // this->registerCommand("clear", Shell::) 78 //void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, ...) 79 80 ShellCommand<Shell>::registerCommand("clear", CL_NULL, this, &Shell::clear, 0, 1); 80 81 } 81 82 … … 458 459 if (!strcmp(this->inputLine, "clear")) 459 460 { 460 this->flushBuffers(); 461 this->addBufferLine("orxonox - shell\n ==================== \n", NULL); 461 this->clear(); 462 462 } 463 463 … … 465 465 466 466 return false; 467 } 468 469 void Shell::clear() 470 { 471 this->flushBuffers(); 472 this->addBufferLine("orxonox - shell\n ==================== \n", NULL); 467 473 } 468 474 -
trunk/src/util/shell.h
r5129 r5130 61 61 bool executeCommand(); 62 62 63 void clear(); 64 63 65 void setRepeatDelay(float repeatDelay, float repeatRate); 64 66 -
trunk/src/util/shell_command.cc
r5129 r5130 28 28 using namespace std; 29 29 30 ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID )30 ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters) 31 31 { 32 32 this->classID = classID; 33 this->functionPointer = functionPointer; 33 34 this->commandName = new char[strlen(commandName)+1]; 34 35 strcpy(this->commandName, commandName); 35 36 37 // handling parameters, and storing them: 38 this->paramCount = paramCount; 39 this->parameters = new ShellParameterType[paramCount]; 40 41 for (unsigned int i = 0; i < paramCount; i++) 42 parameters[i] = va_arg(parameters, long); 43 44 // adding this ShellCommand to the list of known Commands 36 45 ShellCommandBase::commandList->add(this); 37 46 } 38 47 48 ShellCommandBase::~ShellCommandBase() 49 { 50 delete[] this->commandName; 51 delete[] this->parameters; 52 } 39 53 40 54 41 55 tList<ShellCommandBase>* ShellCommandBase::commandList = NULL; 42 56 43 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID )57 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters) 44 58 { 45 59 if (ShellCommandBase::commandList == NULL) -
trunk/src/util/shell_command.h
r5129 r5130 11 11 #include <stdarg.h> 12 12 13 #define MAX_SHELL_COMMAND_SIZE 14 13 15 typedef enum ShellParameterType 14 16 { … … 22 24 }; 23 25 26 24 27 // FORWARD DECLARATION 25 28 template<class T> class tList; 26 29 template<class T> class tIterator; 27 #define MAX_SHELL_COMMAND_SIZE28 30 29 class ShellCommandBase 31 class ShellCommandBase : public BaseObject 30 32 { 31 33 public: 32 34 static bool execute (const char* executionString); 33 35 36 // virtual void execute (...); 37 34 38 protected: 35 ShellCommandBase(const char* commandName, ClassID classID); 39 ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters); 40 ~ShellCommandBase(); 36 41 37 static bool isRegistered(const char* commandName, ClassID classID );42 static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters); 38 43 44 45 protected: 46 void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) 47 unsigned int paramCount; //!< the count of parameters 48 ShellParameterType* parameters; //!< Parameters 39 49 40 50 private: … … 42 52 long classID; //!< The ID of the Class asociated to this Command 43 53 44 54 // STATIC MEMBERS 45 55 static tList<ShellCommandBase>* commandList; //!< A list of availiable commands. 46 56 }; … … 50 60 { 51 61 public: 52 static void registerCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object = NULL);62 static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...); 53 63 54 64 static void unregisterCommand(const char* commandNaame, ClassID classID); 55 65 56 66 private: 57 ShellCommand(const char* command, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object = NULL);67 ShellCommand(const char* command, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters); 58 68 59 69 60 70 public: 61 void* functionPointer; //!< The pointer to the function of the Class (or static pointer if ClassID == CL_NULL ) 62 T* Object; //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL ) 71 T* objectPointer; //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL ) 63 72 }; 64 73 65 74 template<class T> 66 ShellCommand<T>::ShellCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object)67 : ShellCommandBase (command , classID)75 ShellCommand<T>::ShellCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters) 76 : ShellCommandBase (commandName, classID, functionPointer, paramCount, parameters) 68 77 { 69 78 … … 71 80 72 81 template<class T> 73 void ShellCommand<T>::registerCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object)82 void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...) 74 83 { 75 if (isRegistered() == true) 84 va_list parameters; 85 va_start(parameters, paramCount); 86 87 if (isRegistered(commandName, classID, paramCount, parameters) == true) 76 88 return; 77 89 else 78 90 { 79 ShellCommand<T>* newCommand = new ShellCommand<T>(command);80 elem->functionPointer = pointerToFunction;81 elem->parameter1 = param1Type;82 elem->Object = Object;83 91 84 92 // ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, functionPointer, paramCount, parameters); 85 93 } 86 94 }
Note: See TracChangeset
for help on using the changeset viewer.