Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4623 in orxonox.OLD for orxonox/trunk/src/util/loading/load_param.cc


Ignore:
Timestamp:
Jun 13, 2005, 7:31:50 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: 1-st step to LoadParam→default-values (get printed and stuff)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/loading/load_param.cc

    r4598 r4623  
    2727   \param paramCount: how many parameters this loading-function takes
    2828   \param multi: if false LoadParam assumes only one occurence of this parameter in root, if true it assumes multiple occurences.
    29    \param ...: the parameter information
     29   \param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...)
    3030*/
    3131BaseLoadParam::BaseLoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName,
     
    5555  this->paramDesc = NULL;
    5656  if (LoadClassDescription::parametersDescription)
    57     {
     57  {
     58      //! \todo this must only be done once for each class.
    5859      // locating the class
    59       this->classDesc = LoadClassDescription::addClass(object->getClassName());
    60       this->paramDesc = this->classDesc->addParam(paramName);
    61 
     60    this->classDesc = LoadClassDescription::addClass(object->getClassName());
     61
     62    if ((this->paramDesc = this->classDesc->addParam(paramName)) != NULL)
     63    {
     64
     65      this->paramDesc->paramCount = paramCount;
    6266      this->paramDesc->types = new char*[paramCount];
    63       this->paramDesc->paramCount = paramCount;
     67      this->paramDesc->defaultValues = new char*[paramCount];
    6468
    6569      va_list types;
    6670      va_start (types, pointerToParam);
     71      char defaultVal[512];
    6772      for(int i = 0; i < paramCount; i++)
    68         {
    69           const char* tmpTypeName = va_arg (types, const char*);
    70           this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1];
    71           strcpy(this->paramDesc->types[i], tmpTypeName);
    72         }
     73      {
     74          // parameters parsed
     75        const char* tmpTypeName = va_arg (types, const char*);
     76        this->paramDesc->types[i] = new char[strlen(tmpTypeName)+1];
     77        strcpy(this->paramDesc->types[i], tmpTypeName);
     78
     79          // default value description
     80        if (!strcmp(tmpTypeName, l_INT_NAME))
     81        {
     82          sprintf(defaultVal, "%d", va_arg(types, l_INT_TYPE));
     83        }
     84        else if (!strcmp(tmpTypeName, l_LONG_NAME))
     85        {
     86          sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE));
     87        }
     88          /*          else if (!strcmp(tmpTypeName, l_SHORT_NAME))
     89        {
     90        sprintf(defaultVal, "%d", va_arg(types, l_SHORT_TYPE));
     91      }*/
     92        else if (!strcmp(tmpTypeName, l_FLOAT_NAME))
     93        {
     94          sprintf(defaultVal, "%0.3f", va_arg(types, double));
     95        }
     96        else if (!strcmp(tmpTypeName, l_STRING_NAME))
     97        {
     98          sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE));
     99        }
     100        else if (!strcmp(tmpTypeName, l_XML_ELEM_NAME))
     101        {
     102          sprintf(defaultVal, "");
     103        }
     104
     105        this->paramDesc->defaultValues[i] = new char[strlen(defaultVal)+1];
     106        strcpy(this->paramDesc->defaultValues[i], defaultVal);
     107      }
    73108      va_end(types);
    74109
    75110      int argCount = 0;
    76111    }
     112  }
    77113}
    78114
     
    99135  this->paramName = new char[strlen(paramName)+1];
    100136  strcpy(this->paramName, paramName);
     137  this->defaultValues = NULL;
    101138}
    102139
     
    107144{
    108145  for(int i = 0; i < this->paramCount; i++)
    109     {
    110       delete this->types[i];
    111     }
     146  {
     147    delete this->types[i];
     148  }
     149  for(int i = 0; i < this->paramCount; i++)
     150  {
     151    delete this->defaultValues[i];
     152  }
     153
    112154  delete []this->types;
     155  delete []this->defaultValues;
    113156  delete []this->paramName;
    114157  delete []this->description;
     
    139182  if (this->description)
    140183    PRINT(3)(" -- %s", this->description);
     184  // default values
     185  if (this->paramCount > 0)
     186  {
     187      PRINT(3)(" (Default: ");
     188    for (int i = 0; i < this->paramCount; i++)
     189    {
     190      if (i > 0)
     191        PRINT(3)(", ");
     192      PRINT(3)("%s", this->defaultValues[i]);
     193    }
     194    PRINT(3)(")");
     195  }
    141196  PRINT(3)("\n");
    142197}
Note: See TracChangeset for help on using the changeset viewer.