Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5161 in orxonox.OLD for trunk/src/lib/shell/shell_command.h


Ignore:
Timestamp:
Sep 5, 2005, 10:19:44 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: better method to register Shell-Commands (now via the Factory-algorithm proposed)

BUT!! NOW ONLY SINGLETON IS SUPPORTED → fixing!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_command.h

    r5160 r5161  
    2222template<class T> class tList;
    2323
     24
     25////////////////
     26// BASE CLASS //
     27////////////////
     28//! a baseClass for all possible ShellCommands
     29class ShellCommandBase : public BaseObject
     30{
     31  public:
     32    static bool execute (const char* executionString);
     33
     34    static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };
     35
     36//    static void unregisterCommand(const char* commandNaame, const char* className);
     37
     38    static void debug();
     39
     40  protected:
     41    ShellCommandBase(const char* commandName, const char* className, unsigned int paramCount, ...);
     42    ~ShellCommandBase();
     43
     44    static bool isRegistered(const char* commandName, const char* className, unsigned int paramCount, ...);
     45    static const char* paramToString(long parameter);
     46
     47    void debugDyn();
     48
     49  private:
     50    virtual void executeCommand (BaseObject* object, const char* parameters) = NULL;
     51
     52  protected:
     53    void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
     54    unsigned int                     paramCount;          //!< the count of parameters
     55    unsigned int*                    parameters;          //!< Parameters
     56    bool                             isSingleton;         //!< if the Class is Singleton @todo autocheck
     57    char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];
     58    int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];
     59    float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS];
     60    bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];
     61
     62  private:
     63//    long                             classID;             //!< The ID of the Class associated to this Command
     64    const char*                      className;           //!< The Name of the Class associated to this Command
     65
     66    // STATIC MEMBERS
     67    static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
     68};
     69
     70///////////////////////////////////////////////////
     71///////////////////////////////////////////////////
    2472
    2573///////////////////////
     
    3886// NO ARGUMENTS
    3987#define ShellCommandRegister0() \
    40   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)()) \
    41   { \
    42     if (isRegistered(commandName, classID, 0)== true) \
    43       return; \
    44     new ShellCommand<T>(commandName, classID, function); \
     88  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)()) \
     89  { \
     90    if (isRegistered(commandName, className, 0)== true) \
     91      return NULL; \
     92    return new ShellCommand<T>(commandName, className, function); \
    4593  }
    4694
    4795#define ShellCommandRegister1(t1) \
    48   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
    49   { \
    50     if (isRegistered(commandName, classID, 1, t1##_PARAM)== true) \
    51       return; \
    52     new ShellCommand<T>(commandName, classID, function, d1); \
     96  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
     97  { \
     98    if (isRegistered(commandName, className, 1, t1##_PARAM)== true) \
     99      return NULL; \
     100    return new ShellCommand<T>(commandName, className, function, d1); \
    53101  }
    54102
    55103#define ShellCommandRegister2(t1,t2) \
    56   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \
    57   { \
    58     if (isRegistered(commandName, classID, 2, t1##_PARAM, t2##_PARAM)== true) \
    59       return; \
    60     new ShellCommand<T>(commandName, classID, function, d1, d2); \
     104  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT) \
     105  { \
     106    if (isRegistered(commandName, className, 2, t1##_PARAM, t2##_PARAM)== true) \
     107      return NULL; \
     108    return new ShellCommand<T>(commandName, className, function, d1, d2); \
    61109  }
    62110
    63111#define ShellCommandRegister3(t1,t2,t3) \
    64   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \
    65   { \
    66     if (isRegistered(commandName, classID, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \
    67       return; \
    68     new ShellCommand<T>(commandName, classID, function, d1, d2, d3); \
     112  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT) \
     113  { \
     114    if (isRegistered(commandName, className, 3, t1##_PARAM, t2##_PARAM, t3##_PARAM)== true) \
     115      return NULL; \
     116    return new ShellCommand<T>(commandName, className, function, d1, d2, d3); \
    69117  }
    70118
    71119#define ShellCommandRegister4(t1,t2,t3,t4) \
    72   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \
    73   { \
    74     if (isRegistered(commandName, classID, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \
    75       return; \
    76     new ShellCommand<T>(commandName, classID, function, d1, d2, d3, d4); \
    77   }
     120  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT) \
     121  { \
     122    if (isRegistered(commandName, className, 4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM)== true) \
     123      return NULL; \
     124    return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4); \
     125  }
     126
    78127#define ShellCommandRegister5(t1,t2,t3,t4,t5) \
    79   static void registerCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \
    80   { \
    81     if (isRegistered(commandName, classID, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
    82       return; \
    83     new ShellCommand<T>(commandName, classID, function, d1, d2, d3, d4, d5); \
     128  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1 = t1##_DEFAULT, t2##_TYPE d2 = t2##_DEFAULT, t3##_TYPE d3 = t3##_DEFAULT, t4##_TYPE d4 = t4##_DEFAULT, t5##_TYPE d5 = t5##_DEFAULT) \
     129  { \
     130    if (isRegistered(commandName, className, 5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM)== true) \
     131      return NULL; \
     132    return new ShellCommand<T>(commandName, className, function, d1, d2, d3, d4, d5); \
    84133  }
    85134
     
    89138#define ShellCommandConstructor0() \
    90139  void (T::*functionPointer_0)(); \
    91   ShellCommand(const char* commandName, ClassID classID, void (T::*function)()) \
    92   : ShellCommandBase(commandName, classID, 0) \
     140  ShellCommand(const char* commandName, const char* className, void (T::*function)()) \
     141  : ShellCommandBase(commandName, className, 0) \
    93142  { \
    94143    this->functionPointer_0 = function; \
     
    97146#define ShellCommandConstructor1(t1) \
    98147  void (T::*functionPointer_1_##t1)(t1##_TYPE); \
    99   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE), t1##_TYPE d1) \
    100   : ShellCommandBase(commandName, classID, 1, t1##_PARAM, d1) \
     148  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE), t1##_TYPE d1) \
     149  : ShellCommandBase(commandName, className, 1, t1##_PARAM, d1) \
    101150  { \
    102151    this->functionPointer_1_##t1 = function; \
     
    105154#define ShellCommandConstructor2(t1,t2) \
    106155  void (T::*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \
    107   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
    108   : ShellCommandBase(commandName, classID, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
     156  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE), t1##_TYPE d1, t2##_TYPE d2) \
     157  : ShellCommandBase(commandName, className, 2, t1##_PARAM, d1, t2##_PARAM, d2) \
    109158  { \
    110159    this->functionPointer_2_##t1##_##t2 = function; \
     
    113162#define ShellCommandConstructor3(t1,t2,t3) \
    114163  void (T::*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \
    115   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \
    116   : ShellCommandBase(commandName, classID, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
     164  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3) \
     165  : ShellCommandBase(commandName, className, 3, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3) \
    117166  { \
    118167    this->functionPointer_3_##t1##_##t2##_##t3 = function; \
     
    121170#define ShellCommandConstructor4(t1,t2,t3,t4) \
    122171  void (T::*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \
    123   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \
    124   : ShellCommandBase(commandName, classID, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
     172  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4) \
     173  : ShellCommandBase(commandName, className, 4, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4) \
    125174  { \
    126175    this->functionPointer_4_##t1##_##t2##_##t3##_##t4 = function; \
     
    129178#define ShellCommandConstructor5(t1,t2,t3,t4,t5) \
    130179  void (T::*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \
    131   ShellCommand(const char* commandName, ClassID classID, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \
    132   : ShellCommandBase(commandName, classID, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
     180  ShellCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE), t1##_TYPE d1, t2##_TYPE d2, t3##_TYPE d3, t4##_TYPE d4, t5##_TYPE d5) \
     181  : ShellCommandBase(commandName, className, 5, t1##_PARAM, d1, t2##_PARAM, d2, t3##_PARAM, d3, t4##_PARAM, d4, t5##_PARAM, d5) \
    133182  { \
    134183    this->functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5 = function; \
     
    163212
    164213
    165 
    166 ////////////////
    167 // BASE CLASS //
    168 ////////////////
    169 //! a baseClass for all possible ShellCommands
    170 class ShellCommandBase : public BaseObject
    171 {
    172   public:
    173     static bool execute (const char* executionString);
    174 
    175     static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };
    176 
    177 
    178   protected:
    179     ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...);
    180     ~ShellCommandBase();
    181 
    182     static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...);
    183     static const char* paramToString(long parameter);
    184 
    185     void debug();
    186   private:
    187     virtual void executeCommand (BaseObject* object, const char* parameters) = NULL;
    188 
    189   protected:
    190     void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    191     unsigned int                     paramCount;          //!< the count of parameters
    192     unsigned int*                    parameters;          //!< Parameters
    193     bool                             isSingleton;         //!< if the Class is Singleton @todo autocheck
    194     char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];
    195     int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];
    196     float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS];
    197     bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];
    198 
    199   private:
    200     long                             classID;             //!< The ID of the Class associated to this Command
    201     const char*                      className;           //!< The Name of the Class associated to this Command
    202 
    203     // STATIC MEMBERS
    204     static tList<ShellCommandBase>*  commandList;         //!< A list of availiable commands.
    205 };
    206 
    207214//! keeps information about a ShellCommand
    208215template<class T> class ShellCommand : public ShellCommandBase
    209216{
    210217  public:
    211     static void unregisterCommand(const char* commandNaame, ClassID classID);
    212218
    213219#ifdef FUNCTOR_LIST
Note: See TracChangeset for help on using the changeset viewer.