/*! * @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 #include "functor_list.h" // FORWARD DECLARATION template class tList; template class tIterator; /////////////////////// // MACRO DEFINITIONS // /////////////////////// #define ShellCommand2(type1, type2) \ public: \ static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \ type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ { \ if (isRegistered(commandName, classID, 2, type1##_PARAM, type2##_PARAM) == true) \ return; \ else \ ShellCommand* newCommand = new ShellCommand(commandName, classID, object, function); \ } \ private: \ void (T::*functionPointer_##type1_##type2)(type1##_TYPE, type2##_TYPE); \ ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \ type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \ { \ this->functionPointer_##type1_##type2 = function; \ } //////////////// // BASE CLASS // //////////////// //! a baseClass for all possible ShellCommands class ShellCommandBase : public BaseObject { public: static bool execute (const char* executionString); virtual void executeCommand (const char* parameters) = NULL; protected: ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...); ~ShellCommandBase(); static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...); 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 ParameterType* 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. }; 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); static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)(), bool isSingleton = false) { if (isRegistered(commandName, classID, 0)== true) return; else { if (isSingleton == false) new ShellCommand(commandName, classID, functionPointer); else new ShellCommandSingleton(commandName, classID, functionPointer); } } private: void (T::*functionPointer_NULL)(); ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) : ShellCommandBase (commandName, classID, 0) { this->functionPointer_NULL = functionPointer; } virtual void executeCommand (const char* parameters) { /* if (this->paramCount == 0) (objectPointer->*functionPointer_NULL)();*/ } #define FUNCTOR_LIST(x) ShellCommand ## x //#include "functor_list.h" //ShellCommand2(l_INT, l_INT); #undef FUNCTOR_LIST private: // T* objectPointer; //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL ) }; #endif /* _SHELL_COMMAND_H */