Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Sep 6, 2005, 1:45:46 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: doxygen-tags

File:
1 edited

Legend:

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

    r5165 r5166  
    1515#include <stdarg.h>
    1616
    17 #define SHELL_COMMAND_MAX_SIZE
     17#define     SHELL_COMMAND_MAX_SIZE      //!< The maximum size of a Shell Command
    1818
    1919
     
    2222template<class T> class tList;
    2323
     24/**
     25 * an easy to use Macro to create a Command
     26 * @param command the name of the command (without "" around the string)
     27 * @param class the name of the class to apply this command to (without the "" around the string)
     28 * @param function the function to call
     29 */
    2430#define SHELL_COMMAND(command, class, function) \
    2531        ShellCommandBase* shell_command_##class##_##command = ShellCommand<class>::registerCommand(#command, #class, &class::function)
     
    3743    ShellCommandBase* describe(const char* description);
    3844
     45    /** @returns the CommandList of the Shell */
    3946    static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };
    4047
    4148    static void unregisterAllCommands();
    42     static void unregisterCommand(const char* commandNaame, const char* className);
     49    static void unregisterCommand(const char* commandName, const char* className);
    4350
    4451    static void debug();
     
    5461
    5562  private:
     63    /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
    5664    virtual void executeCommand (BaseObject* object, const char* parameters) = NULL;
    5765
    5866  protected:
    5967    void*                            functionPointer;                      //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    60     unsigned int                     paramCount;                           //!< the count of parameters
    61     unsigned int*                    parameters;                           //!< Parameters
    62     char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];
    63     int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];
    64     float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS];
    65     bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];
     68    unsigned int                     paramCount;                           //!< the count of parameters.
     69    unsigned int*                    parameters;                           //!< Parameters the function of this Command takes.
     70    char*                            defaultStrings[FUNCTOR_MAX_ARGUMENTS];//!< A list of default Strings stored.
     71    int                              defaultInts[FUNCTOR_MAX_ARGUMENTS];   //!< A list of default Ints stored.
     72    float                            defaultFloats[FUNCTOR_MAX_ARGUMENTS]; //!< A list of default Floats stored.
     73    bool                             defaultBools[FUNCTOR_MAX_ARGUMENTS];  //!< A list of default Bools stored.
    6674
    6775  private:
     
    6977    const char*                      className;                            //!< The Name of the Class associated to this Command
    7078
    71     const char*                      description;
     79    const char*                      description;                          //!< A description for this commnand. (initially NULL). Assigned with (create)->describe("blablabla");
    7280
    7381    // STATIC MEMBERS
     
    8189// MACRO DEFINITIONS //
    8290///////////////////////
     91//! where to chek for default BOOL values
    8392#define   l_BOOL_DEFGRAB(i)         this->defaultBools[i]
     93//! where to chek for default INT values
    8494#define   l_INT_DEFGRAB(i)          this->defaultInts[i]
     95//! where to chek for default UINT values
    8596#define   l_UINT_DEFGRAB(i)         (unsigned int)this->defaultInts[i]
     97//! where to chek for default LONG values
    8698#define   l_LONG_DEFGRAB(i)         (long)this->defaultInts[i]
     99//! where to chek for default FLOAT values
    87100#define   l_FLOAT_DEFGRAB(i)        this->defaultFloats[i]
     101//! where to chek for default STRING values
    88102#define   l_STRING_DEFGRAB(i)       this->defaultStrings[i]
    89103
     
    91105// COMMAND REGISTRATION //
    92106//////////////////////////
    93 // NO ARGUMENTS
     107//! registers a command without any parameters
    94108#define ShellCommandRegister0() \
    95109  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)()) \
     
    100114  }
    101115
     116//! registers a command with 1 parameter
    102117#define ShellCommandRegister1(t1) \
    103118  static ShellCommand<T>* registerCommand(const char* commandName, const char* className, void (T::*function)(t1##_TYPE), t1##_TYPE d1 = t1##_DEFAULT) \
     
    108123  }
    109124
     125//! registers a command with 2 parameters
    110126#define ShellCommandRegister2(t1,t2) \
    111127  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) \
     
    116132  }
    117133
     134//! registers a command with 3 parameters
    118135#define ShellCommandRegister3(t1,t2,t3) \
    119136  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) \
     
    124141  }
    125142
     143//! registers a command with 4 parameters
    126144#define ShellCommandRegister4(t1,t2,t3,t4) \
    127145  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) \
     
    132150  }
    133151
     152//! registers a command with 5 parameters
    134153#define ShellCommandRegister5(t1,t2,t3,t4,t5) \
    135154  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) \
     
    143162// CONSTRUCTORS //
    144163/////////////////
     164//! creates a command that takes no parameters
    145165#define ShellCommandConstructor0() \
    146166  void (T::*functionPointer_0)(); \
     
    151171  }
    152172
     173//! creates a command that takes one parameter
    153174#define ShellCommandConstructor1(t1) \
    154175  void (T::*functionPointer_1_##t1)(t1##_TYPE); \
     
    159180  }
    160181
     182//! creates a command that takes two parameters
    161183#define ShellCommandConstructor2(t1,t2) \
    162184  void (T::*functionPointer_2_##t1##_##t2)(t1##_TYPE, t2##_TYPE); \
     
    167189  }
    168190
     191//! creates a command that takes three parameter
    169192#define ShellCommandConstructor3(t1,t2,t3) \
    170193  void (T::*functionPointer_3_##t1##_##t2##_##t3)(t1##_TYPE, t2##_TYPE, t3##_TYPE); \
     
    175198  }
    176199
     200//! creates a command that takes four parameter
    177201#define ShellCommandConstructor4(t1,t2,t3,t4) \
    178202  void (T::*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE); \
     
    183207  }
    184208
     209//! creates a command that takes five parameter
    185210#define ShellCommandConstructor5(t1,t2,t3,t4,t5) \
    186211  void (T::*functionPointer_5_##t1##_##t2##_##t3##_##t4##_##t5)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE); \
     
    194219// EXECUTION //
    195220///////////////
     221//! execute-macro for functions with no parameters
    196222#define ShellCommandExecute0() \
    197223  if (this->paramCount == 0) \
    198224    (dynamic_cast<T*>(object)->*functionPointer_0)()
    199225
     226//! execute-macro for functions with one parameter
    200227#define ShellCommandExecute1(t1) \
    201228   else if (this->paramCount == 1 && this->parameters[0] == t1##_PARAM) \
    202229    (dynamic_cast<T*>(object)->*functionPointer_1_##t1)(t1##_FUNC(parameters, t1##_DEFGRAB(0)))
    203230
     231//! execute-macro for functions with two parameters
    204232#define ShellCommandExecute2(t1,t2) \
    205233   else if (this->paramCount == 2 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM) \
    206234    (dynamic_cast<T*>(object)->*functionPointer_2_##t1##_##t2)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)))
    207235
     236//! execute-macro for functions with three parameters
    208237#define ShellCommandExecute3(t1,t2,t3) \
    209238   else if (this->paramCount == 3 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM) \
    210239    (dynamic_cast<T*>(object)->*functionPointer_3_##t1##_##t2##_##t3)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)))
    211240
     241//! execute-macro for functions with four parameters
    212242#define ShellCommandExecute4(t1,t2,t3,t4) \
    213243   else if (this->paramCount == 4 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM) \
    214244    (dynamic_cast<T*>(object)->*functionPointer_4_##t1##_##t2##_##t3##_##t4)(t1##_FUNC(sub.getString(0), t1##_DEFGRAB(0)), t2##_FUNC(sub.getString(1), t2##_DEFGRAB(1)), t3##_FUNC(sub.getString(2), t3##_DEFGRAB(2)), t4##_FUNC(sub.getString(3), t4##_DEFGRAB(3)))
    215245
     246//! execute-macro for functions with five parameters
    216247#define ShellCommandExecute5(t1,t2,t3,t4,t5) \
    217248   else if (this->paramCount == 5 && this->parameters[0] == t1##_PARAM && this->parameters[1] == t2##_PARAM && this->parameters[2] == t3##_PARAM && this->parameters[3] == t4##_PARAM && this->parameters[4] == t5##_PARAM) \
     
    228259#endif
    229260
     261//! FUNCTOR_LIST is the List of command-registerers
    230262#define FUNCTOR_LIST(x) ShellCommandRegister ## x
    231263#include "functor_list.h"
     
    234266
    235267  private:
     268//! FUNCTOR_LIST is the List of CommandConstructors
    236269#define FUNCTOR_LIST(x) ShellCommandConstructor ## x
    237270#include "functor_list.h"
     
    242275//      if (parameters != NULL)
    243276      SubString sub(parameters);
     277//! FUNCTOR_LIST is the List of Executive Functions
    244278#define FUNCTOR_LIST(x) ShellCommandExecute ## x
    245279#include "functor_list.h"
Note: See TracChangeset for help on using the changeset viewer.