Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: registering singleton-Classes now

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
65  protected:
66    void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
67    unsigned int                     paramCount;          //!< the count of parameters
68    ParameterType*                   parameters;          //!< Parameters
69
70  private:
71    char*                            commandName;         //!< The name of the Command when executed
72    long                             classID;             //!< The ID of the Class asociated to this Command
73
74    // STATIC MEMBERS
75    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
76};
77
78template<class T> class ShellCommand;
79
80template<class T> class ShellCommandSingleton : public ShellCommandBase
81{
82  friend class ShellCommand<T>;
83  private:
84    ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)())
85    : ShellCommandBase (commandName, classID, 0)
86    {
87      this->functionPointer_NULL = functionPointer;
88
89    }
90    void (T::*functionPointer_NULL)();
91    virtual void executeCommand (const char* parameters)
92    {
93      if (this->paramCount == 0)
94        (T::getInstance()->*functionPointer_NULL)();
95    }
96};
97
98
99//! keeps information about a ShellCommand
100template<class T> class ShellCommand : public ShellCommandBase
101{
102  public:
103    static void unregisterCommand(const char* commandNaame, ClassID classID);
104
105    static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)(), bool isSingleton = false)
106    {
107      if (isRegistered(commandName, classID, 0)== true)
108        return;
109      else
110      {
111        if (isSingleton == false)
112          new ShellCommand<T>(commandName, classID, functionPointer);
113        else
114          new ShellCommandSingleton<T>(commandName, classID, functionPointer);
115      }
116    }
117
118  private:
119    void (T::*functionPointer_NULL)();
120    ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
121      : ShellCommandBase (commandName, classID, 0)
122    {
123      this->functionPointer_NULL = functionPointer;
124    }
125    virtual void executeCommand (const char* parameters)
126    {
127/*      if (this->paramCount == 0)
128        (objectPointer->*functionPointer_NULL)();*/
129    }
130
131
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:
139//    T*                   objectPointer;       //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
140};
141
142
143
144#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.