Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5138 was 5137, checked in by bensch, 20 years ago

orxonox/trunk: better macro-definition

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