Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: registered 'quit' from GameLoader

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;
20
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
50class ShellCommandBase : public BaseObject
51{
52  public:
53    static bool execute (const char* executionString);
54
55    virtual void executeCommand (const char* parameters) = NULL;
56
57  protected:
58    ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...);
59    ~ShellCommandBase();
60
61    static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...);
62
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
66    ParameterType*                   parameters;          //!< Parameters
67
68  private:
69    char*                            commandName;         //!< The name of the Command when executed
70    long                             classID;             //!< The ID of the Class asociated to this Command
71
72    // STATIC MEMBERS
73    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
74};
75
76template<class T> class ShellCommand;
77
78template<class T> class ShellCommandSingleton : public ShellCommandBase
79{
80  friend class ShellCommand<T>;
81  private:
82    ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)())
83    : ShellCommandBase (commandName, classID, 0)
84    {
85      this->functionPointer_NULL = functionPointer;
86
87    }
88    void (T::*functionPointer_NULL)();
89    virtual void executeCommand (const char* parameters)
90    {
91      if (this->paramCount == 0)
92        (T::getInstance()->*functionPointer_NULL)();
93    }
94};
95
96
97//! keeps information about a ShellCommand
98template<class T> class ShellCommand : public ShellCommandBase
99{
100  public:
101    static void unregisterCommand(const char* commandNaame, ClassID classID);
102
103    static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
104    {
105      if (isRegistered(commandName, classID, 0)== true)
106        return;
107      else
108      {
109        if (classID & CL_MASK_SINGLETON == CL_MASK_SINGLETON)
110          new ShellCommandSingleton<T>(commandName, classID, functionPointer);
111        else
112          new ShellCommand<T>(commandName, classID, functionPointer);
113      }
114    }
115
116  private:
117    void (T::*functionPointer_NULL)();
118    ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)())
119      : ShellCommandBase (commandName, classID, 0)
120    {
121      this->functionPointer_NULL = functionPointer;
122    }
123    virtual void executeCommand (const char* parameters)
124    {
125/*      if (this->paramCount == 0)
126        (objectPointer->*functionPointer_NULL)();*/
127    }
128
129
130
131#define FUNCTOR_LIST(x) ShellCommand ## x
132//#include "functor_list.h"
133//ShellCommand2(l_INT, l_INT);
134#undef FUNCTOR_LIST
135
136  private:
137//    T*                   objectPointer;       //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
138};
139
140
141
142#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.