Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/shell_command.h @ 5140

Last change on this file since 5140 was 5140, checked in by bensch, 19 years ago

orxonox/trunk: now all new commands get subscribed

File size: 4.4 KB
RevLine 
[4838]1/*!
[5129]2 * @file shell_command.h
[5068]3 * Definition of a on-screen-shell
[3245]4*/
[1853]5
[5129]6#ifndef _SHELL_COMMAND_H
7#define _SHELL_COMMAND_H
[1853]8
[5129]9#include "base_object.h"
[1853]10
[5068]11#include <stdarg.h>
12
[5130]13#define MAX_SHELL_COMMAND_SIZE
14
[5135]15#include "functor_list.h"
[5127]16
[5130]17
[4838]18// FORWARD DECLARATION
[5068]19template<class T> class tList;
[3543]20
[5135]21
22///////////////////////
23// MACRO DEFINITIONS //
24///////////////////////
25
26
27#define ShellCommand2(type1, type2) \
28 public: \
29  static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \
30                              type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \
31  { \
32     if (isRegistered(commandName, classID, 2, type1##_PARAM, type2##_PARAM) == true) \
33       return; \
34     else \
35       ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \
36  } \
37 private: \
38  void (T::*functionPointer_##type1_##type2)(type1##_TYPE, type2##_TYPE); \
39  ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \
40                              type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \
41  { \
42    this->functionPointer_##type1_##type2 = function; \
43  }
44
45
46////////////////
47// BASE CLASS //
48////////////////
49//! a baseClass for all possible ShellCommands
[5130]50class ShellCommandBase : public BaseObject
[5129]51{
[5068]52  public:
[5129]53    static bool execute (const char* executionString);
[2036]54
[5135]55    virtual void executeCommand (const char* parameters) = NULL;
[5130]56
[5129]57  protected:
[5135]58    ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...);
[5130]59    ~ShellCommandBase();
[1853]60
[5135]61    static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...);
[1853]62
[5130]63  protected:
64    void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
65    unsigned int                     paramCount;          //!< the count of parameters
[5135]66    ParameterType*                   parameters;          //!< Parameters
[5140]67    bool                             isSingleton;         //!< if the Class is Singleton @todo autocheck
[5130]68
[5129]69  private:
70    char*                            commandName;         //!< The name of the Command when executed
71    long                             classID;             //!< The ID of the Class asociated to this Command
[3245]72
[5130]73    // STATIC MEMBERS
[5129]74    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
75};
[5068]76
[5136]77template<class T> class ShellCommand;
[5135]78
[5136]79template<class T> class ShellCommandSingleton : public ShellCommandBase
80{
81  friend class ShellCommand<T>;
82  private:
83    ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)())
84    : ShellCommandBase (commandName, classID, 0)
85    {
86      this->functionPointer_NULL = functionPointer;
[5135]87
[5136]88    }
89    void (T::*functionPointer_NULL)();
90    virtual void executeCommand (const char* parameters)
91    {
92      if (this->paramCount == 0)
93        (T::getInstance()->*functionPointer_NULL)();
94    }
95};
[5135]96
[5136]97
[5129]98//! keeps information about a ShellCommand
99template<class T> class ShellCommand : public ShellCommandBase
100{
101  public:
102    static void unregisterCommand(const char* commandNaame, ClassID classID);
[5068]103
[5137]104    static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
[5135]105    {
106      if (isRegistered(commandName, classID, 0)== true)
107        return;
108      else
[5136]109      {
[5137]110        if (classID & CL_MASK_SINGLETON == CL_MASK_SINGLETON)
111          new ShellCommandSingleton<T>(commandName, classID, functionPointer);
112        else
[5136]113          new ShellCommand<T>(commandName, classID, functionPointer);
114      }
[5135]115    }
[5136]116
[5068]117  private:
[5135]118    void (T::*functionPointer_NULL)();
[5136]119    ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
[5135]120      : ShellCommandBase (commandName, classID, 0)
121    {
122      this->functionPointer_NULL = functionPointer;
123    }
124    virtual void executeCommand (const char* parameters)
125    {
[5140]126      printf("not implemented yet\n");
[5136]127/*      if (this->paramCount == 0)
128        (objectPointer->*functionPointer_NULL)();*/
[5135]129    }
[5068]130
131
[5135]132
133#define FUNCTOR_LIST(x) ShellCommand ## x
134//#include "functor_list.h"
135//ShellCommand2(l_INT, l_INT);
136#undef FUNCTOR_LIST
137
138  private:
[5136]139//    T*                   objectPointer;       //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
[5129]140};
[5113]141
142
[5120]143
[5129]144#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.