Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more elaborate version
now the command Structure is
SingletonClass function [parameters]

File size: 4.9 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 "helper_functions.h"
12
13#include <stdarg.h>
14
15#define MAX_SHELL_COMMAND_SIZE
16
17#include "functor_list.h"
18
19
20// FORWARD DECLARATION
21template<class T> class tList;
22
23
24///////////////////////
25// MACRO DEFINITIONS //
26///////////////////////
27
28// COMMAND REGISTRATION
29// NO ARGUMENTS
30#define ShellCommandRegister0 \
31  static void registerCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \
32  { \
33    if (isRegistered(commandName, classID, 0)== true) \
34      return; \
35    new ShellCommand<T>(commandName, classID, functionPointer); \
36  }
37
38
39#define ShellCommandConstructor0 \
40  void (T::*functionPointer_NULL)(); \
41  ShellCommand(const char* commandName, ClassID classID, void (T::*functionPointer)()) \
42  : ShellCommandBase (commandName, classID, 0) \
43  { \
44    this->functionPointer_NULL = functionPointer; \
45  }
46
47
48
49
50#define ShellCommandRegister2(t1, t2) \
51  static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \
52                              t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \
53  { \
54     if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM) == true) \
55       return; \
56     else \
57       ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \
58  }
59
60// CONSTRUCTORS AND POINTERS
61#define ShellCommandConstructor2(t1, t2) \
62  void (T::*functionPointer_##t1_##t2)(t1##_TYPE, t2##_TYPE); \
63  ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(t1##_TYPE, t2##_TYPE) \
64                              t1##_TYPE default1 = t1##_DEFAULT, t2##_TYPE default2 = t2##_DEFAULT) \
65  { \
66    this->functionPointer_##t1_##t2 = function; \
67  }
68
69//#define ShellCommand
70
71
72////////////////
73// BASE CLASS //
74////////////////
75//! a baseClass for all possible ShellCommands
76class ShellCommandBase : public BaseObject
77{
78  public:
79    static bool execute (const char* executionString);
80
81    static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };
82
83
84  protected:
85    ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...);
86    ~ShellCommandBase();
87
88    static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...);
89
90  private:
91    virtual void executeCommand (BaseObject* object, const char* parameters) = NULL;
92
93  protected:
94    void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
95    unsigned int                     paramCount;          //!< the count of parameters
96    ParameterType*                   parameters;          //!< Parameters
97    bool                             isSingleton;         //!< if the Class is Singleton @todo autocheck
98
99  private:
100    long                             classID;             //!< The ID of the Class associated to this Command
101    const char*                      className;           //!< The Name of the Class associated to this Command
102
103    char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];
104    int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];
105    float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS];
106    bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];
107
108
109    // STATIC MEMBERS
110    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
111};
112
113template<class T> class ShellCommand;
114/*
115template<class T> class ShellCommandSingleton : public ShellCommandBase
116{
117  friend class ShellCommand<T>;
118  private:
119    ShellCommandSingleton(const char* commandName, ClassID classID, void (T::*functionPointer)())
120    : ShellCommandBase (commandName, classID, 0)
121    {
122      this->functionPointer_NULL = functionPointer;
123    }
124    void (T::*functionPointer_NULL)();
125
126    virtual void executeCommand (const char* parameters)
127    {
128      if (this->paramCount == 0)
129        (T::getInstance()->*functionPointer_NULL)();
130    }
131};*/
132
133
134//! keeps information about a ShellCommand
135template<class T> class ShellCommand : public ShellCommandBase
136{
137  public:
138    static void unregisterCommand(const char* commandNaame, ClassID classID);
139
140#define FUNCTOR_LIST(x) ShellCommandRegister ## x
141//#include "functor_list.h"
142FUNCTOR_LIST(0);
143#undef FUNCTOR_LIST
144
145
146  private:
147#define FUNCTOR_LIST(x) ShellCommandConstructor ## x
148//#include "functor_list.h"
149  FUNCTOR_LIST(0);
150#undef FUNCTOR_LIST
151
152    virtual void executeCommand (BaseObject* object, const char* parameters)
153    {
154     printf("not implemented yet\n");
155     if (this->paramCount == 0)
156       (dynamic_cast<T*>(object)->*functionPointer_NULL)();
157    }
158
159
160
161#define FUNCTOR_LIST(x) ShellCommand ## x
162//#include "functor_list.h"
163//FUNCTOR_LIST(2)(l_INT, l_INT);
164#undef FUNCTOR_LIST
165
166};
167
168
169
170#endif /* _SHELL_COMMAND_H */
Note: See TracBrowser for help on using the repository browser.