Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4623 in orxonox.OLD


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)

Location:
orxonox/trunk/src/util/loading
Files:
2 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}
  • orxonox/trunk/src/util/loading/load_param.h

    r4599 r4623  
    5050*/
    5151
    52 #define l_INT_TYPE       int                  //!< The type of an INT
    53 #define l_INT_FUNC       atoi                 //!< the function to call to parse INT
    54 #define l_INT_NAME       "int"                //!< the name of an INT
    55 
    56 #define l_LONG_TYPE      long                 //!< The type of a LONG
    57 #define l_LONG_FUNC      atol                 //!< The function to parse a LONG
    58 #define l_LONG_NAME      "long"               //!< The name of a LONG
    59 
    60 #define l_SHORT_TYPE     short                //!< The type of a SHORT
    61 #define l_SHORT_FUNC     atoi                 //!< The function to parse a SHORT
    62 #define l_SHORT_NAME     "short"              //!< The name of a SHORT
    63 
    64 #define l_FLOAT_TYPE     float                //!< The type of a FLOAT
    65 #define l_FLOAT_FUNC     atof                 //!< The function to parse a FLOAT
    66 #define l_FLOAT_NAME     "float"              //!< The name of a FLOAT
    67 
    68 #define l_STRING_TYPE    const char*          //!< The type of a STRING
    69 #define l_STRING_FUNC                         //!< The function to parse a STRING
    70 #define l_STRING_NAME    "string"             //!< The name of a STRING
    71 
    72 #define l_XML_ELEM_TYPE  const TiXmlElement*  //!< The type of an XML_ELEM
    73 #define l_XML_ELEM_FUNC                       //!< The function to parse an XML_ELEM
    74 #define l_XML_ELEM_NAME  "XML"                //!< The name of an XML_ELEM
    75 
     52#define l_INT_TYPE         int                  //!< The type of an INT
     53#define l_INT_FUNC         atoi                 //!< The function to call to parse INT
     54#define l_INT_NAME         "int"                //!< The name of an INT
     55#define l_INT_DEFAULT      0                    //!< a default Value for an INT
     56
     57#define l_LONG_TYPE        long                 //!< The type of a LONG
     58#define l_LONG_FUNC        atol                 //!< The function to parse a LONG
     59#define l_LONG_NAME        "long"               //!< The name of a LONG
     60#define l_LONG_DEFAULT     0                    //!< a default Value for a LONG
     61
     62// #define l_SHORT_TYPE       short                //!< The type of a SHORT
     63// #define l_SHORT_FUNC       atoi                 //!< The function to parse a SHORT
     64// #define l_SHORT_NAME       "short"              //!< The name of a SHORT
     65// #define l_SHORT_DEFAULT    0                    //!< a default Value for a SHORT
     66
     67#define l_FLOAT_TYPE       float                //!< The type of a FLOAT
     68#define l_FLOAT_FUNC       atof                 //!< The function to parse a FLOAT
     69#define l_FLOAT_NAME       "float"              //!< The name of a FLOAT
     70#define l_FLOAT_DEFAULT    0.0                  //!< a default Value for a FLOAT
     71
     72#define l_STRING_TYPE      const char*          //!< The type of a STRING
     73#define l_STRING_FUNC                           //!< The function to parse a STRING
     74#define l_STRING_NAME      "string"             //!< The name of a STRING
     75#define l_STRING_DEFAULT   ""                   //!< a default Value for an STRING
     76
     77#define l_XML_ELEM_TYPE    const TiXmlElement*  //!< The type of an XML_ELEM
     78#define l_XML_ELEM_FUNC                         //!< The function to parse an XML_ELEM
     79#define l_XML_ELEM_NAME    "XML"                //!< The name of an XML_ELEM
     80#define l_XML_ELEM_DEFAULT NULL                 //!< The dafault Value for an XML_ELEM
     81
     82
     83/*****************************************
     84**** MACROS DEFINITIONS OF LOADABLES *****
     85*****************************************/
    7686// 1. TYPE
    7787/**
     
    8090*/
    8191#define LoadParam1(type1) \
    82  LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), bool multi = false) \
    83   : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_NAME) \
     92 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE), \
     93           bool multi = false, type1##_TYPE default1 = type1##_DEFAULT) \
     94  : BaseLoadParam(root, pt2Object, paramName, 1, multi, NULL, type1##_NAME, default1) \
    8495    { \
    8596      if (loadString != NULL && root != NULL) \
     
    97108*/
    98109#define LoadParam2(type1, type2) \
    99  LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE), bool multi = false) \
    100   : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_NAME, type2##_NAME) \
     110 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE), \
     111           bool multi = false,  type1##_TYPE default1 = type1##_DEFAULT,  type2##_TYPE default2 = type2##_DEFAULT) \
     112  : BaseLoadParam(root, pt2Object, paramName, 2, multi, NULL, type1##_NAME, default1, type2##_NAME, default2) \
    101113    { \
    102114      if (loadString != NULL && root != NULL) \
     
    122134*/
    123135#define LoadParam3(type1, type2, type3) \
    124  LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE), bool multi = false)\
    125   : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME) \
     136 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE), \
     137           bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT)\
     138  : BaseLoadParam(root, pt2Object, paramName, 3, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3) \
    126139    { \
    127140      if (loadString != NULL && root != NULL) \
     
    148161*/
    149162#define LoadParam4(type1, type2, type3, type4) \
    150  LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE), bool multi = false) \
    151   : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME) \
     163 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE), \
     164           bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \
     165           type4##_TYPE default4 = type4##_DEFAULT) \
     166  : BaseLoadParam(root, pt2Object, paramName, 4, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \
     167                  type4##_NAME, default4) \
    152168    { \
    153169      if (loadString != NULL && root != NULL) \
     
    175191*/
    176192#define LoadParam5(type1, type2, type3, type4, type5) \
    177  LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE), bool multi = false) \
    178   : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_NAME, type2##_NAME, type3##_NAME, type2##_NAME, type4##_NAME, type5##_NAME) \
     193 LoadParam(const TiXmlElement* root, const char* paramName, T* pt2Object, \
     194           void(T::*function)(type1##_TYPE, type2##_TYPE, type3##_TYPE, type4##_TYPE, type5##_TYPE), \
     195           bool multi = false, type1##_TYPE default1 = type1##_DEFAULT, type2##_TYPE default2 = type2##_DEFAULT, type3##_TYPE default3 = type3##_DEFAULT, \
     196           type4##_TYPE default4 = type4, ##_DEFAULTtype5##_TYPE default5 = type5##_DEFAULT ) \
     197  : BaseLoadParam(root, pt2Object, paramName, 5, multi, NULL, type1##_NAME, default1, type2##_NAME, default2, type3##_NAME, default3, \
     198                  type4##_NAME, default4, type5##_NAME, default5) \
    179199    { \
    180200      if (loadString != NULL && root != NULL) \
     
    221241  void print(void) const;
    222242 private:
    223   char*         paramName;             //!< The name of the parameter
    224   int           paramCount;            //!< The count of parameters
     243  char*         paramName;             //!< The name of the parameter.
     244  int           paramCount;            //!< The count of parameters.
    225245  char**        types;                 //!< What kind of parameters does this function take ??
    226   char*         description;           //!< A longer description about this function
     246  char*         description;           //!< A longer description about this function.
     247  char**        defaultValues;         //!< The 'Default Values'.
    227248};
    228249
Note: See TracChangeset for help on using the changeset viewer.