Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7197 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Mar 8, 2006, 2:02:58 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Executor now uses MultiType instead of va_arg

Location:
trunk/src/lib/util
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/executor/executor.cc

    r6645 r7197  
    3131// SHELL COMMAND BASE //
    3232////////////////////////
    33 // empty constructor
    34 Executor::Executor()
    35 {
    36   this->defaultValue = NULL;
    37 }
    38 
    3933/**
    4034 * constructs and registers a new Command
     
    4337 * @param paramCount the count of parameters this command takes
    4438 */
    45 Executor::Executor(unsigned int paramCount, ...)
     39Executor::Executor(const MultiType& param0,
     40                   const MultiType& param1,
     41                   const MultiType& param2,
     42                   const MultiType& param3,
     43                   const MultiType& param4)
    4644{
    4745  this->setClassID(CL_EXECUTOR, "Executor");
    4846
    49   if (paramCount > FUNCTOR_MAX_ARGUMENTS)
    50     paramCount = FUNCTOR_MAX_ARGUMENTS;
    51   // reading in Parameters.
    52   this->paramCount = paramCount;
    53   this->defaultValue = new MultiType[paramCount];
    5447
    55   va_list parameterList;
    56   va_start(parameterList, paramCount);
     48  // What Parameters have we got
     49  this->defaultValue[0] = param0;
     50  this->defaultValue[1] = param1;
     51  this->defaultValue[2] = param2;
     52  this->defaultValue[3] = param3;
     53  this->defaultValue[4] = param4;
    5754
    58   // What Parameters we have got
    59   for (unsigned int i = 0; i < paramCount; i++)
     55  for (unsigned int i = 0; i < FUNCTOR_MAX_ARGUMENTS; i++)
    6056  {
    61     int type = va_arg(parameterList, int);
    62     this->defaultValue[i].setType((MT_Type)type);
     57    printf("%d ", i);
     58    if (this->defaultValue[i] == MT_NULL)
     59    {
     60      this->paramCount = i;
     61      break;
     62    }
     63
    6364  }
     65  printf("%d\n", this->paramCount);
     66
     67  assert (paramCount <= FUNCTOR_MAX_ARGUMENTS);
    6468}
    6569
     
    6872 */
    6973Executor::~Executor()
    70 {
    71   delete[] this->defaultValue;
    72 }
     74{}
    7375
    7476/**
     
    7981  executor->functorType  = this->functorType;
    8082  executor->paramCount   = this->paramCount;
    81   executor->defaultValue = new MultiType[this->paramCount];
    8283  for (unsigned int i = 0; i < this->paramCount; i++)
    83   {
    8484    executor->defaultValue[i] =  this->defaultValue[i];
    85 //    printf("1: %s 2: %s\n", MultiType::MultiTypeToString(this->defaultValue[i].getType()),  MultiType::MultiTypeToString(executor->defaultValue[i].getType()));
    86   }
    8785}
    8886
     
    132130        this->defaultValue[i].setInt(va_arg(values, int));
    133131        break;
    134 /*      case MT_UINT:
    135         this->defaultValue[i].setInt((int)va_arg(values, unsigned int));
    136         break;*/
     132        /*      case MT_UINT:
     133                this->defaultValue[i].setInt((int)va_arg(values, unsigned int));
     134                break;*/
    137135      case MT_FLOAT:
    138136        this->defaultValue[i].setFloat(va_arg(values, double));
    139137        break;
    140 /*      case MT_LONG:
    141         this->defaultValue[i].setInt((int) va_arg(values, long));
    142         break;*/
     138        /*      case MT_LONG:
     139                this->defaultValue[i].setInt((int) va_arg(values, long));
     140                break;*/
    143141      default:
    144142        break;
     
    153151void Executor::debug()
    154152{
    155 /*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator();
    156   ExecutorClass* elemCL = iteratorCL->firstElement();
    157   while(elemCL != NULL)
    158   {
    159     PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
    160     tIterator<Executor>* iterator = elemCL->commandList->getIterator();
    161     const Executor* elem = iterator->firstElement();
    162     while(elem != NULL)
     153  /*  tIterator<ExecutorClass>* iteratorCL = ExecutorClass::commandClassList->getIterator();
     154    ExecutorClass* elemCL = iteratorCL->firstElement();
     155    while(elemCL != NULL)
    163156    {
    164       PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
    165       for (unsigned int i = 0; i< elem->paramCount; i++)
    166        printf("%s ", Executor::paramToString(elem->parameters[i]));
    167       if (elem->description != NULL)
    168        printf("- %s", elem->description);
    169       printf("\n");
     157      PRINT(0)("Class:'%s' registered %d commands: \n", elemCL->className, elemCL->commandList->getSize());
     158      tIterator<Executor>* iterator = elemCL->commandList->getIterator();
     159      const Executor* elem = iterator->firstElement();
     160      while(elem != NULL)
     161      {
     162        PRINT(0)("  command:'%s' : params:%d: ", elem->getName(), elem->paramCount);
     163        for (unsigned int i = 0; i< elem->paramCount; i++)
     164         printf("%s ", Executor::paramToString(elem->parameters[i]));
     165        if (elem->description != NULL)
     166         printf("- %s", elem->description);
     167        printf("\n");
    170168
    171       elem = iterator->nextElement();
     169        elem = iterator->nextElement();
     170      }
     171      delete iterator;
     172      elemCL = iteratorCL->nextElement();
    172173    }
    173     delete iterator;
    174     elemCL = iteratorCL->nextElement();
    175   }
    176   delete iteratorCL;*/
     174    delete iteratorCL;*/
    177175}
  • trunk/src/lib/util/executor/executor.h

    r5691 r7197  
    11/*!
    22 * @file executor.h
    3  * Definition of a on-screen-shell
     3 * Definition of an Executor
    44 */
    55
     
    1616#include <stdarg.h>
    1717
    18 // FORWARD DECLARATION
    19 template<class T> class tList;
    20 
    2118//! an enumerator for the definition of the Type.
    2219typedef enum {
     
    3027// BASE CLASS //
    3128////////////////
    32 //! a baseClass for all possible Executors
     29//! a BaseClass for all possible Executors
     30/**
     31 * An Executor is an Object, that is able to call Objects of Any type (class)
     32 * and execute a function with given parameters on it.
     33 *
     34 * The Executor is able to handle:
     35 *  Objects of any Class (Templated)
     36 *  Default Values
     37 *  Functions with up to 5 parameters (more seems useless)
     38 *  Functions with many types (see functor_list.h)
     39 */
    3340class Executor: public BaseObject
    3441{
     
    5259
    5360  protected:
    54     Executor();
    55     Executor(unsigned int paramCount, ...);
     61    Executor(const MultiType& param0 = MT_NULL,
     62             const MultiType& param1 = MT_NULL,
     63             const MultiType& param2 = MT_NULL,
     64             const MultiType& param3 = MT_NULL,
     65             const MultiType& param4 = MT_NULL);
    5666
    5767    void cloning(Executor* executor) const;
    58 
    59 //    const SubString& getSubString(const char* string) const { return SubString(string); };
    6068
    6169  protected:
    6270    long                        functorType;      //!< The type of Function we've got (either static or objective).
    6371    unsigned int                paramCount;       //!< the count of parameters.
    64     MultiType*                  defaultValue;     //!< Default Values.
     72    MultiType                   defaultValue[5];  //!< Default Values.
    6573};
    6674
     
    132140#define ExecutorConstructor1(t1) \
    133141  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE)) \
    134   : Executor(1, t1##_PARAM) \
     142  : Executor(t1##_PARAM) \
    135143  { \
    136144    this->functorType = EXECUTORTYPE; \
     
    141149#define ExecutorConstructor2(t1,t2) \
    142150  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE)) \
    143   : Executor(2, t1##_PARAM, t2##_PARAM) \
     151  : Executor(t1##_PARAM, t2##_PARAM) \
    144152  { \
    145153    this->functorType = EXECUTORTYPE; \
     
    150158#define ExecutorConstructor3(t1,t2,t3) \
    151159  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE)) \
    152   : Executor(3, t1##_PARAM, t2##_PARAM, t3##_PARAM) \
     160  : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM) \
    153161  { \
    154162    this->functorType = EXECUTORTYPE; \
     
    159167#define ExecutorConstructor4(t1,t2,t3,t4) \
    160168  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE)) \
    161   : Executor(4, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \
     169  : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM) \
    162170  { \
    163171    this->functorType = EXECUTORTYPE; \
     
    168176#define ExecutorConstructor5(t1,t2,t3,t4,t5) \
    169177  EXECUTOR(void EXECUTORINCLASS(*function)(t1##_TYPE, t2##_TYPE, t3##_TYPE, t4##_TYPE, t5##_TYPE)) \
    170   : Executor(5, t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \
     178  : Executor(t1##_PARAM, t2##_PARAM, t3##_PARAM, t4##_PARAM, t5##_PARAM) \
    171179  { \
    172180    this->functorType = EXECUTORTYPE; \
  • trunk/src/lib/util/executor/executor_specials.h

    r5944 r7197  
    2929     */
    3030    ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const char* paramName)
    31       : Executor(1, MT_EXT1)
     31      : Executor(MT_EXT1)
    3232    {
    3333      PRINTF(4)("Loading %s from XML-element %p\n", paramName, root);
  • trunk/src/lib/util/multi_type.cc

    r6859 r7197  
    3333 * creates a multiType without any stored value at all.
    3434 */
    35 MultiType::MultiType()
    36 {
    37   this->init();
     35MultiType::MultiType(MT_Type type)
     36{
     37  this->init();
     38  this->type = type;
    3839}
    3940/**
     
    274275  else if (this->type & MT_FLOAT) return (this->value.Float == 0.0f)? false : true;
    275276  else if (this->type & MT_CHAR) return (this->value.Char == '\0')? false : true;
    276   else if (this->type & MT_STRING) return (!strncmp(this->value.String, "true", 4) || !strncmp(this->value.String, "TRUE", 4) || !strncmp(this->value.String, "1", 1))? true : false; //! @TODO make this better.
     277  else if (this->type & MT_STRING && this->value.String != NULL) return (!strncmp(this->value.String, "true", 4) || !strncmp(this->value.String, "TRUE", 4) || !strncmp(this->value.String, "1", 1))? true : false; //! @TODO make this better.
    277278
    278279  return false;
     
    290291  else if (this->type & MT_FLOAT) return (int) this->value.Float;
    291292  else if (this->type & MT_CHAR) return (int) this->value.Char;
    292   else if (this->type & MT_STRING) {
     293  else if (this->type & MT_STRING && this->value.String != NULL) {
    293294    char* endPtr = NULL;
    294295    int result = strtol(this->value.String, &endPtr, 10);
     
    313314  else if (this->type & MT_INT) return (float) this->value.Int;
    314315  else if (this->type & MT_CHAR) return (float) this->value.Char;
    315   else if (this->type & MT_STRING) {
     316  else if (this->type & MT_STRING && this->value.String != NULL) {
    316317    char* endPtr = NULL;
    317318    double result = strtod(this->value.String, &endPtr);
     
    337338  else if (this->type & MT_INT) return (int) this->value.Int;
    338339  else if (this->type & MT_FLOAT) return (char) this->value.Float;
    339   else if (this->type & MT_STRING) return *this->value.String;
     340  else if (this->type & MT_STRING && this->value.String != NULL) return *this->value.String;
    340341
    341342  return '\0';
  • trunk/src/lib/util/multi_type.h

    r6645 r7197  
    3232class MultiType {
    3333  public:
    34     MultiType();
     34    MultiType(MT_Type type = MT_NULL);
    3535    MultiType(bool value);
    3636    MultiType(int value);
Note: See TracChangeset for help on using the changeset viewer.