/*! * @file shell_command.h * Definition of a on-screen-shell */ #ifndef _SHELL_COMMAND_H #define _SHELL_COMMAND_H #include "base_object.h" #include #define MAX_SHELL_COMMAND_SIZE typedef enum ShellParameterType { ShellParameterNull, ShellParameterChar, ShellParameterString, ShellParameterInt, ShellParameterUInt, ShellParameterFloat, /* ... */ }; // FORWARD DECLARATION template class tList; template class tIterator; class ShellCommandBase : public BaseObject { public: static bool execute (const char* executionString); // virtual void execute (...); protected: ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters); ~ShellCommandBase(); static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters); protected: void* functionPointer; //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL ) unsigned int paramCount; //!< the count of parameters ShellParameterType* parameters; //!< Parameters private: char* commandName; //!< The name of the Command when executed long classID; //!< The ID of the Class asociated to this Command // STATIC MEMBERS static tList* commandList; //!< A list of availiable commands. }; //! keeps information about a ShellCommand template class ShellCommand : public ShellCommandBase { public: static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...); static void unregisterCommand(const char* commandNaame, ClassID classID); private: ShellCommand(const char* command, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters); public: T* objectPointer; //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL ) }; template ShellCommand::ShellCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters) : ShellCommandBase (commandName, classID, functionPointer, paramCount, parameters) { } template void ShellCommand::registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...) { va_list parameters; va_start(parameters, paramCount); if (isRegistered(commandName, classID, paramCount, parameters) == true) return; else { // ShellCommand* newCommand = new ShellCommand(commandName, classID, object, functionPointer, paramCount, parameters); } } #endif /* _SHELL_COMMAND_H */