Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 20, 2005, 9:22:11 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: dissected LoadParam and Executor completely. Now there is no more LoadParam<Template that noone understands>(many params that are still the same, but cleaner now)
This is a major improvement, since understanding Executor is hard work but loadParam should not be.

File:
1 edited

Legend:

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

    r5654 r5655  
    2424
    2525#include <stdarg.h>
    26 
    27 /**
    28  * @param object The object this Parameter is loaded too.
    29  * @param root: the XML-element to load this option from.
    30  * @param paramName: The name of the parameter loaded.
    31  * @param paramCount: how many parameters this loading-function takes
    32  * @param multi: if false LoadParam assumes only one occurence of this parameter in root, if true it assumes multiple occurences.
    33  * @param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...)
    34 */
    35 LoadParamBase::LoadParamBase(const TiXmlElement* root, BaseObject* object, const char* paramName,
    36                              int paramCount, bool multi, const void* pointerToParam, ...)
    37 {
    38   this->setClassID(CL_LOAD_PARAM, "LoadParam");
    39   this->executor = NULL;
    40 
    41   this->loadString = NULL;
    42   this->pointerToParam = pointerToParam;
    43 
    44   if (paramCount == 0 || this->pointerToParam != NULL)
    45     this->loadString = "none";
    46   else
    47     {
    48       if (likely(!multi))
    49         this->loadString = grabParameter(root, paramName);
    50       else
    51         {
    52           if (!strcmp(root->Value(), paramName))
    53             {
    54               const TiXmlNode* val = root->FirstChild();
    55               if( val->ToText())
    56                 this->loadString = val->Value();
    57             }
    58         }
    59     }
    60 
    61   this->paramDesc = NULL;
    62   if (LoadClassDescription::parametersDescription)
    63   {
    64     // locating the class
    65     this->classDesc = LoadClassDescription::addClass(object->getClassName());
    66 
    67     if ((this->paramDesc = this->classDesc->addParam(paramName)) != NULL)
    68     {
    69 
    70       this->paramDesc->paramCount = paramCount;
    71       this->paramDesc->types = new int[paramCount];
    72       this->paramDesc->defaultValues = new char*[paramCount];
    73 
    74       va_list types;
    75       va_start (types, pointerToParam);
    76       char defaultVal[512];
    77       for(int i = 0; i < paramCount; i++)
    78       {
    79         defaultVal[0] = '\0';
    80           // parameters parsed
    81         int tmpType = va_arg (types, int);
    82         this->paramDesc->types[i] = tmpType;
    83         switch (tmpType)
    84         {
    85           case MT_INT:
    86             sprintf(defaultVal, "%d", va_arg(types, int));
    87             break;
    88 /*          case MT_LONG:
    89             sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE));
    90             break;*/
    91           case MT_FLOAT:
    92             sprintf(defaultVal, "%0.3f", va_arg(types, double));
    93             break;
    94           case MT_STRING:
    95             sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE));
    96             break;
    97           case MT_EXT1:
    98             sprintf(defaultVal, "");
    99             break;
    100         }
    101         this->paramDesc->defaultValues[i] = new char[strlen(defaultVal)+1];
    102         strcpy(this->paramDesc->defaultValues[i], defaultVal);
    103       }
    104       va_end(types);
    105 
    106       int argCount = 0;
    107     }
    108   }
    109 }
    11026
    11127/**
     
    11632 * @param executor the Executor, that executes the loading procedure.
    11733 */
    118 LoadParamBase::LoadParamBase(const TiXmlElement* root, const char* paramName, BaseObject* object, const Executor& executor, bool inLoadCycle)
     34LoadParam::LoadParam(const TiXmlElement* root, const char* paramName, BaseObject* object, const Executor& executor, bool inLoadCycle)
    11935{
    12036  this->paramName = paramName;
     
    14763 * Execution-Conditions are met, they are executed here.
    14864 */
    149 LoadParamBase::~LoadParamBase()
     65LoadParam::~LoadParam()
    15066{
    15167  if (likely(this->executor != NULL))
     
    16884 * @param ... the default values !! must be at least count parameters!!
    16985 */
    170 LoadParamBase* LoadParamBase::defaultValues(unsigned int count, ...)
     86LoadParam* LoadParam::defaultValues(unsigned int count, ...)
    17187{
    17288  if (this == NULL)
     
    188104 * @returns a pointer to itself.
    189105*/
    190 LoadParamBase* LoadParamBase::describe(const char* descriptionText)
     106LoadParam* LoadParam::describe(const char* descriptionText)
    191107{
    192108  if (LoadClassDescription::parametersDescription && this->paramDesc && !this->paramDesc->getDescription())
     
    215131// }
    216132
     133
     134
     135
     136/*
     137 * @param object The object this Parameter is loaded too.
     138 * @param root: the XML-element to load this option from.
     139 * @param paramName: The name of the parameter loaded.
     140 * @param paramCount: how many parameters this loading-function takes
     141 * @param multi: if false LoadParam assumes only one occurence of this parameter in root, if true it assumes multiple occurences.
     142 * @param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...)
     143*/
     144/*LoadParam::LoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName,
     145                             int paramCount, bool multi, const void* pointerToParam, ...)
     146{
     147  this->setClassID(CL_LOAD_PARAM, "LoadParam");
     148  this->executor = NULL;
     149
     150  this->loadString = NULL;
     151  this->pointerToParam = pointerToParam;
     152
     153  if (paramCount == 0 || this->pointerToParam != NULL)
     154    this->loadString = "none";
     155  else
     156{
     157      if (likely(!multi))
     158        this->loadString = grabParameter(root, paramName);
     159      else
     160{
     161          if (!strcmp(root->Value(), paramName))
     162{
     163              const TiXmlNode* val = root->FirstChild();
     164              if( val->ToText())
     165                this->loadString = val->Value();
     166}
     167}
     168}
     169
     170  this->paramDesc = NULL;
     171  if (LoadClassDescription::parametersDescription)
     172{
     173    // locating the class
     174    this->classDesc = LoadClassDescription::addClass(object->getClassName());
     175
     176    if ((this->paramDesc = this->classDesc->addParam(paramName)) != NULL)
     177{
     178
     179      this->paramDesc->paramCount = paramCount;
     180      this->paramDesc->types = new int[paramCount];
     181      this->paramDesc->defaultValues = new char*[paramCount];
     182
     183      va_list types;
     184      va_start (types, pointerToParam);
     185      char defaultVal[512];
     186      for(int i = 0; i < paramCount; i++)
     187{
     188        defaultVal[0] = '\0';
     189          // parameters parsed
     190        int tmpType = va_arg (types, int);
     191        this->paramDesc->types[i] = tmpType;
     192        switch (tmpType)
     193{
     194  case MT_INT:
     195            sprintf(defaultVal, "%d", va_arg(types, int));
     196            break;
     197//          case MT_LONG:
     198//            sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE));
     199//            break;
     200  case MT_FLOAT:
     201            sprintf(defaultVal, "%0.3f", va_arg(types, double));
     202            break;
     203  case MT_STRING:
     204            sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE));
     205            break;
     206  case MT_EXT1:
     207            sprintf(defaultVal, "");
     208            break;
     209}
     210        this->paramDesc->defaultValues[i] = new char[strlen(defaultVal)+1];
     211        strcpy(this->paramDesc->defaultValues[i], defaultVal);
     212}
     213      va_end(types);
     214
     215      int argCount = 0;
     216}
     217}
     218}*/
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229//////////////////////
     230// HELPER FUNCTIONS //
     231//////////////////////
    217232/**
    218233 * @param root: The XML-element to grab a parameter from
Note: See TracChangeset for help on using the changeset viewer.