Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5135 in orxonox.OLD


Ignore:
Timestamp:
Aug 26, 2005, 12:51:27 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: it is now possible to execute Commands registered to the ShellCommandBase with no arguments

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/functor_list.h

    r5133 r5135  
    1616*/
    1717
     18/**
     19   useable FunctionParameters are:
     20   l_INT:       int
     21   l_LONG:      long
     22   l_SHORT:     short
     23   l_FLOAT:     float
     24   l_STRING:    const char*
     25   l_XML_ELEM:  TiXmlElement*
     26 */
    1827
    19   //! makes functions with one string loadable
     28#ifndef __FUNCTOR_PARAMETERS__
     29#define __FUNCTOR_PARAMETERS__
     30
     31typedef enum ParameterType
     32{
     33  ParameterNull,
     34  ParameterBool,
     35  ParameterChar,
     36  ParameterString,
     37  ParameterInt,
     38  ParameterUInt,
     39  ParameterFloat,
     40  ParameterLong,
     41  /* ... */
     42};
     43
     44
     45#define l_BOOL_TYPE        bool                 //!< The type of an BOOL
     46#define l_BOOL_FUNC        isBool               //!< The function to call to parse BOOL
     47#define l_BOOL_NAME        "bool"               //!< The name of an BOOL
     48#define l_BOOL_PARAM       ParameterBool        //!< the type of the parameter BOOL
     49#define l_BOOL_DEFAULT     false                //!< a default Value for an BOOL
     50
     51
     52#define l_INT_TYPE         int                  //!< The type of an INT
     53#define l_INT_FUNC         isInt                //!< The function to call to parse INT
     54#define l_INT_NAME         "int"                //!< The name of an INT
     55#define l_INT_PARAM        ParameterInt         //!< the type of the parameter INT
     56#define l_INT_DEFAULT      0                    //!< a default Value for an INT
     57
     58#define l_UINT_TYPE        unsigned int         //!< The type of an UINT
     59#define l_UINT_FUNC        isInt                //!< The function to call to parse UINT
     60#define l_UINT_NAME        "unsigned int"       //!< The name of an UINT
     61#define l_UINT_PARAM        ParameterUInt       //!< the type of the parameter UINT
     62#define l_UINT_DEFAULT     0                    //!< a default Value for an UINT
     63
     64#define l_LONG_TYPE        long                 //!< The type of a LONG
     65#define l_LONG_FUNC        isInt                //!< The function to parse a LONG
     66#define l_LONG_NAME        "long"               //!< The name of a LONG
     67#define l_LONG_PARAM       ParameterLong        //!< the type of the parameter LONG
     68#define l_LONG_DEFAULT     0                    //!< a default Value for a LONG
     69
     70// #define l_SHORT_TYPE       short                //!< The type of a SHORT
     71// #define l_SHORT_FUNC       atoi                 //!< The function to parse a SHORT
     72// #define l_SHORT_NAME       "short"              //!< The name of a SHORT
     73//#define l_SHORT_PARAM       ParameterShort       //!< the type of the parameter SHORT
     74// #define l_SHORT_DEFAULT    0                    //!< a default Value for a SHORT
     75
     76#define l_FLOAT_TYPE       float                //!< The type of a FLOAT
     77#define l_FLOAT_FUNC       isFloat              //!< The function to parse a FLOAT
     78#define l_FLOAT_NAME       "float"              //!< The name of a FLOAT
     79#define l_FLOAT_PARAM      ParameterFloat       //!< the type of the parameter FLOAT
     80#define l_FLOAT_DEFAULT    0.0                  //!< a default Value for a FLOAT
     81
     82//#define l_VECTOR_TYPE      const Vector&        //!< The type of a VECTOR
     83//#define l_VECTOR_FUNC      isVector             //!< The function to parse a VECTOR
     84//#define l_VECTOR_NAME      "Vector[x/y/z]"      //!< The name of a VECTOR
     85//#define l_VECTOR_DEFAULT   Vector(0,0,0)        //!< Default value for a VECTOR
     86
     87#define l_STRING_TYPE      const char*          //!< The type of a STRING
     88#define l_STRING_FUNC      isString             //!< The function to parse a STRING
     89#define l_STRING_NAME      "string"             //!< The name of a STRING
     90#define l_STRING_PARAM     ParameterString      //!< the type of the parameter STRING
     91#define l_STRING_DEFAULT   ""                   //!< a default Value for an STRING
     92
     93#define l_XML_ELEM_TYPE    const TiXmlElement*  //!< The type of an XML_ELEM
     94#define l_XML_ELEM_FUNC                         //!< The function to parse an XML_ELEM
     95#define l_XML_ELEM_NAME    "XML"                //!< The name of an XML_ELEM
     96//#define l_XML_ELEM_PARAM   Parameter        //!< the type of the parameter XML_ELEM
     97#define l_XML_ELEM_DEFAULT NULL                 //!< The dafault Value for an XML_ELEM
     98
     99#endif /* __FUNCTOR_PARAMETERS__ */
     100
     101
     102#ifdef FUNCTOR_LIST
     103  //! makes functions with one string
    20104  FUNCTOR_LIST(1)(l_STRING);
    21   //! makes functions with two strings loadable
     105  //! makes functions with two strings
    22106  FUNCTOR_LIST(2)(l_STRING, l_STRING);
    23   //! makes functions with three strings loadable
     107  //! makes functions with three strings
    24108  FUNCTOR_LIST(3)(l_STRING, l_STRING, l_STRING);
    25   //! makes functions with four strings loadable
     109  //! makes functions with four strings
    26110  FUNCTOR_LIST(4)(l_STRING, l_STRING, l_STRING, l_STRING);
    27111
    28   //! makes functions with one bool loadeable
     112  //! makes functions with one bool
    29113  FUNCTOR_LIST(1)(l_BOOL);
    30114
    31   //! makes functions with one int loadable
     115  //! makes functions with one int
    32116  FUNCTOR_LIST(1)(l_INT);
    33   //! makes functions with two ints loadable
     117  //! makes functions with two ints
    34118  FUNCTOR_LIST(2)(l_INT, l_INT);
    35   //! makes functions with three ints loadable
     119  //! makes functions with three ints
    36120  FUNCTOR_LIST(3)(l_INT, l_INT, l_INT);
    37   //! makes functions with four ints loadable
     121  //! makes functions with four ints
    38122  FUNCTOR_LIST(4)(l_INT, l_INT, l_INT, l_INT);
    39123
    40124
    41   //! makes functions with one unsigned int loadable
     125  //! makes functions with one unsigned int
    42126  FUNCTOR_LIST(1)(l_UINT);
    43   //! makes functions with two unsigned ints loadable
     127  //! makes functions with two unsigned ints
    44128  FUNCTOR_LIST(2)(l_UINT, l_UINT);
    45   //! makes functions with three unsigned ints loadable
     129  //! makes functions with three unsigned ints
    46130  FUNCTOR_LIST(3)(l_UINT, l_UINT, l_UINT);
    47   //! makes functions with four unsigned ints loadable
     131  //! makes functions with four unsigned ints
    48132  FUNCTOR_LIST(4)(l_UINT, l_UINT, l_UINT, l_UINT);
    49133
    50   //! makes functions with one float loadable
     134  //! makes functions with one float
    51135  FUNCTOR_LIST(1)(l_FLOAT);
    52   //! makes functions with two floats loadable
     136  //! makes functions with two floats
    53137  FUNCTOR_LIST(2)(l_FLOAT, l_FLOAT);
    54   //! makes functions with three floats loadable
     138  //! makes functions with three floats
    55139  FUNCTOR_LIST(3)(l_FLOAT, l_FLOAT, l_FLOAT);
    56   //! makes functions with four floats loadable
     140  //! makes functions with four floats
    57141  FUNCTOR_LIST(4)(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);
    58   //! makes functions with four floats loadable
     142  //! makes functions with four floats
    59143  FUNCTOR_LIST(5)(l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);
    60144
    61145  //! mixed values:
    62146  FUNCTOR_LIST(2)(l_STRING, l_FLOAT);
     147#endif /* FUNCTOR_LIST */
    63148
    64 
  • trunk/src/util/loading/load_param.h

    r5133 r5135  
    5757#define LOAD_PARAM_END_CYCLE        element = element->NextSiblingElement(); \
    5858                                  }
    59 
    60 
    61 
    62 /**
    63    useable FunctionParameters are:
    64    l_INT:       int
    65    l_LONG:      long
    66    l_SHORT:     short
    67    l_FLOAT:     float
    68    l_STRING:    const char*
    69    l_XML_ELEM:  TiXmlElement*
    70 */
    71 
    72 #define l_BOOL_TYPE        bool                 //!< The type of an BOOL
    73 #define l_BOOL_FUNC        isBool               //!< The function to call to parse BOOL
    74 #define l_BOOL_NAME        "bool"               //!< The name of an BOOL
    75 #define l_BOOL_DEFAULT     false                //!< a default Value for an BOOL
    76 
    77 
    78 #define l_INT_TYPE         int                  //!< The type of an INT
    79 #define l_INT_FUNC         isInt                //!< The function to call to parse INT
    80 #define l_INT_NAME         "int"                //!< The name of an INT
    81 #define l_INT_DEFAULT      0                    //!< a default Value for an INT
    82 
    83 #define l_UINT_TYPE        unsigned int         //!< The type of an UINT
    84 #define l_UINT_FUNC        isInt                //!< The function to call to parse UINT
    85 #define l_UINT_NAME        "unsigned int"       //!< The name of an UINT
    86 #define l_UINT_DEFAULT     0                    //!< a default Value for an UINT
    87 
    88 #define l_LONG_TYPE        long                 //!< The type of a LONG
    89 #define l_LONG_FUNC        isInt                //!< The function to parse a LONG
    90 #define l_LONG_NAME        "long"               //!< The name of a LONG
    91 #define l_LONG_DEFAULT     0                    //!< a default Value for a LONG
    92 
    93 // #define l_SHORT_TYPE       short                //!< The type of a SHORT
    94 // #define l_SHORT_FUNC       atoi                 //!< The function to parse a SHORT
    95 // #define l_SHORT_NAME       "short"              //!< The name of a SHORT
    96 // #define l_SHORT_DEFAULT    0                    //!< a default Value for a SHORT
    97 
    98 #define l_FLOAT_TYPE       float                //!< The type of a FLOAT
    99 #define l_FLOAT_FUNC       isFloat              //!< The function to parse a FLOAT
    100 #define l_FLOAT_NAME       "float"              //!< The name of a FLOAT
    101 #define l_FLOAT_DEFAULT    0.0                  //!< a default Value for a FLOAT
    102 
    103 //#define l_VECTOR_TYPE      const Vector&        //!< The type of a VECTOR
    104 //#define l_VECTOR_FUNC      isVector             //!< The function to parse a VECTOR
    105 //#define l_VECTOR_NAME      "Vector[x/y/z]"      //!< The name of a VECTOR
    106 //#define l_VECTOR_DEFAULT   Vector(0,0,0)        //!< Default value for a VECTOR
    107 
    108 #define l_STRING_TYPE      const char*          //!< The type of a STRING
    109 #define l_STRING_FUNC      isString             //!< The function to parse a STRING
    110 #define l_STRING_NAME      "string"             //!< The name of a STRING
    111 #define l_STRING_DEFAULT   ""                   //!< a default Value for an STRING
    112 
    113 #define l_XML_ELEM_TYPE    const TiXmlElement*  //!< The type of an XML_ELEM
    114 #define l_XML_ELEM_FUNC                         //!< The function to parse an XML_ELEM
    115 #define l_XML_ELEM_NAME    "XML"                //!< The name of an XML_ELEM
    116 #define l_XML_ELEM_DEFAULT NULL                 //!< The dafault Value for an XML_ELEM
    11759
    11860
  • trunk/src/util/shell.cc

    r5130 r5135  
    7878  //void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, ...)
    7979
    80   ShellCommand<Shell>::registerCommand("clear", CL_NULL, this, &Shell::clear, 0, 1);
     80  ShellCommand<Shell>::registerCommand("clear", CL_NULL, this, &Shell::clear);
    8181}
    8282
     
    457457  this->inputHistory->add(newCommand);
    458458
    459   if (!strcmp(this->inputLine, "clear"))
    460   {
    461     this->clear();
    462   }
     459  ShellCommandBase::execute(this->inputLine);
     460//  if (!strcmp(this->inputLine, "clear"))
     461//  {
     462//    this->clear();
     463//  }
    463464
    464465  this->flushInputLine();
  • trunk/src/util/shell_command.cc

    r5130 r5135  
    2828using namespace std;
    2929
    30 ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters)
     30ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...)
    3131{
     32  va_list parameters;
     33  va_start(parameters, paramCount);
     34
    3235  this->classID = classID;
    33   this->functionPointer = functionPointer;
    3436  this->commandName = new char[strlen(commandName)+1];
    3537  strcpy(this->commandName, commandName);
     
    3739  // handling parameters, and storing them:
    3840  this->paramCount = paramCount;
    39   this->parameters = new ShellParameterType[paramCount];
     41  this->parameters = new ParameterType[paramCount];
    4042
    4143  for (unsigned int i = 0; i < paramCount; i++)
     
    5557tList<ShellCommandBase>* ShellCommandBase::commandList = NULL;
    5658
    57 bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters)
     59bool ShellCommandBase::isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...)
    5860{
     61
     62  va_list parameters;
     63  va_start(parameters, paramCount);
     64
    5965  if (ShellCommandBase::commandList == NULL)
    6066  {
     
    8086
    8187
     88bool ShellCommandBase::execute(const char* executionString)
     89{
     90  if (ShellCommandBase::commandList == NULL)
     91    return false;
     92
     93  const char* commandEnd = strchr(executionString, ' ');
     94  if (commandEnd == NULL)
     95    commandEnd = executionString + strlen(executionString);
     96
     97  tIterator<ShellCommandBase>* iterator = ShellCommandBase::commandList->getIterator();
     98  ShellCommandBase* elem = iterator->firstElement();
     99  while(elem != NULL)
     100  {
     101    if (!strncmp(executionString, elem->commandName, commandEnd - executionString))
     102    {
     103      elem->executeCommand(commandEnd);
     104      delete iterator;
     105      return true;
     106    }
     107    elem = iterator->nextElement();
     108  }
     109  delete iterator;
     110  return true;
     111}
     112
  • trunk/src/util/shell_command.h

    r5130 r5135  
    1313#define MAX_SHELL_COMMAND_SIZE
    1414
    15 typedef enum ShellParameterType
    16 {
    17   ShellParameterNull,
    18   ShellParameterChar,
    19   ShellParameterString,
    20   ShellParameterInt,
    21   ShellParameterUInt,
    22   ShellParameterFloat,
    23   /* ... */
    24 };
     15#include "functor_list.h"
    2516
    2617
     
    2920template<class T> class tIterator;
    3021
     22
     23///////////////////////
     24// MACRO DEFINITIONS //
     25///////////////////////
     26
     27
     28#define ShellCommand2(type1, type2) \
     29 public: \
     30  static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \
     31                              type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \
     32  { \
     33     if (isRegistered(commandName, classID, 2, type1##_PARAM, type2##_PARAM) == true) \
     34       return; \
     35     else \
     36       ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, function); \
     37  } \
     38 private: \
     39  void (T::*functionPointer_##type1_##type2)(type1##_TYPE, type2##_TYPE); \
     40  ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*function)(type1##_TYPE, type2##_TYPE) \
     41                              type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT) \
     42  { \
     43    this->functionPointer_##type1_##type2 = function; \
     44  }
     45
     46
     47////////////////
     48// BASE CLASS //
     49////////////////
     50//! a baseClass for all possible ShellCommands
    3151class ShellCommandBase : public BaseObject
    3252{
     
    3454    static bool execute (const char* executionString);
    3555
    36 //    virtual void execute (...);
     56    virtual void executeCommand (const char* parameters) = NULL;
    3757
    3858  protected:
    39     ShellCommandBase(const char* commandName, ClassID classID, void* functionPointer, unsigned int paramCount, va_list parameters);
     59    ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...);
    4060    ~ShellCommandBase();
    4161
    42     static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, va_list parameters);
     62    static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...);
    4363
    4464
     
    4666    void*                            functionPointer;     //!< The pointeer to the function of the Class (or static pointer if ClassID == CL_NULL )
    4767    unsigned int                     paramCount;          //!< the count of parameters
    48     ShellParameterType*              parameters;          //!< Parameters
     68    ParameterType*                   parameters;          //!< Parameters
    4969
    5070  private:
     
    5676};
    5777
     78
     79
     80
    5881//! keeps information about a ShellCommand
    5982template<class T> class ShellCommand : public ShellCommandBase
    6083{
    6184  public:
    62     static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...);
    63 
    6485    static void unregisterCommand(const char* commandNaame, ClassID classID);
    6586
     87    static void registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)())
     88    {
     89      if (isRegistered(commandName, classID, 0)== true)
     90        return;
     91      else
     92        ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, functionPointer);
     93    }
    6694  private:
    67     ShellCommand(const char* command, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters);
     95    void (T::*functionPointer_NULL)();
     96    ShellCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)())
     97      : ShellCommandBase (commandName, classID, 0)
     98    {
     99      this->functionPointer_NULL = functionPointer;
     100      this->objectPointer = object;
     101    }
     102    virtual void executeCommand (const char* parameters)
     103    {
     104      if (this->paramCount == 0)
     105        (objectPointer->*functionPointer_NULL)();
     106    }
     107
     108
     109
     110#define FUNCTOR_LIST(x) ShellCommand ## x
     111//#include "functor_list.h"
     112//ShellCommand2(l_INT, l_INT);
     113#undef FUNCTOR_LIST
     114
     115  private:
    68116
    69117
     
    72120};
    73121
    74 template<class T>
    75     ShellCommand<T>::ShellCommand(const char* commandName, ClassID classID, T* object, void* functionPointer, unsigned int paramCount, va_list parameters)
    76   : ShellCommandBase (commandName, classID, functionPointer, paramCount, parameters)
    77 {
    78122
    79 }
    80 
    81 template<class T>
    82     void ShellCommand<T>::registerCommand(const char* commandName, ClassID classID, T* object, void (T::*functionPointer)(), unsigned int paramCount, ...)
    83 {
    84   va_list parameters;
    85   va_start(parameters, paramCount);
    86 
    87   if (isRegistered(commandName, classID, paramCount, parameters) == true)
    88     return;
    89   else
    90   {
    91 
    92 //    ShellCommand<T>* newCommand = new ShellCommand<T>(commandName, classID, object, functionPointer, paramCount, parameters);
    93   }
    94 }
    95123
    96124#endif /* _SHELL_COMMAND_H */
Note: See TracChangeset for help on using the changeset viewer.