/*! * @file shell_command.h * Definition of a on-screen-shell */ #ifndef _SHELL_COMMAND_H #define _SHELL_COMMAND_H #include "base_object.h" #include "helper_functions.h" #include "functor_list.h" #include #define MAX_SHELL_COMMAND_SIZE // FORWARD DECLARATION template class tList; /////////////////////// // MACRO DEFINITIONS // /////////////////////// // COMMAND REGISTRATION // NO ARGUMENTS #define ShellCommandRegister0 \ static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \ { \ if (isRegistered(commandName, classID, 0)== true) \ return; \ new ShellCommand(commandName, classID, functionPointer); \ } #define ShellCommandConstructor0 \ void (T::*functionPointer_NULL)(); \ ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \ : ShellCommandBase (commandName, classID, 0) \ { \ this->functionPointer_NULL = functionPointer; \ } #define ShellCommandRegister2(t1, t2) \ static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \ t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \ { \ if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM) == true) \ return; \ else \ ShellCommand* newCommand = new ShellCommand(commandName, classID, object, function); \ } // CONSTRUCTORS AND POINTERS #define ShellCommandConstructor2(t1, t2) \ void (T::*functionPointer_##t1_##t2)(t1##_TYPE, t2##_TYPE); \ ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \ t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \ { \ this->functionPointer_##t1_##t2 = function; \ } //#define ShellCommand //////////////// // BASE CLASS // //////////////// //! a baseClass for all possible ShellCommands class ShellCommandBase : public BaseObject { public: static bool execute (const char* executionString); static const tList* getCommandList() { return ShellCommandBase::commandList; }; protected: ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...); ~ShellCommandBase(); static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...); private: virtual void executeCommand (BaseObject* object, const char* parameters) = NULL; 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 long* parameters; //!< Parameters bool isSingleton; //!< if the Class is Singleton @todo autocheck private: long classID; //!< The ID of the Class associated to this Command const char* className; //!< The Name of the Class associated to this Command char* defaultStrings[FUNCTOR_MAX_ARGUMENTS]; int defaultInts[FUNCTOR_MAX_ARGUMENTS]; float defaultFloats[FUNCTOR_MAX_ARGUMENTS]; bool defaultBools[FUNCTOR_MAX_ARGUMENTS]; // STATIC MEMBERS static tList* commandList; //!< A list of availiable commands. }; template class ShellCommand; /* template class ShellCommandSingleton : public ShellCommandBase { friend class ShellCommand; private: ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)()) : ShellCommandBase (commandName, classID, 0) { this->functionPointer_NULL = functionPointer; } void (T::*functionPointer_NULL)(); virtual void executeCommand (const char* parameters) { if (this->paramCount == 0) (T::getInstance()->*functionPointer_NULL)(); } };*/ //! keeps information about a ShellCommand template class ShellCommand : public ShellCommandBase { public: static void unregisterCommand(const char* commandNaame, ClassID classID); #define FUNCTOR_LIST(x) ShellCommandRegister ## x //#include "functor_list.h" FUNCTOR_LIST(0); #undef FUNCTOR_LIST private: #define FUNCTOR_LIST(x) ShellCommandConstructor ## x //#include "functor_list.h" FUNCTOR_LIST(0); #undef FUNCTOR_LIST virtual void executeCommand (BaseObject* object, const char* parameters) { printf("not implemented yet\n"); if (this->paramCount == 0) (dynamic_cast(object)->*functionPointer_NULL)(); } #define FUNCTOR_LIST(x) ShellCommand ## x //#include "functor_list.h" //FUNCTOR_LIST(2)(l_INT, l_INT); #undef FUNCTOR_LIST }; #endif /* _SHELL_COMMAND_H */