Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: flush

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