Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4624 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Jun 13, 2005, 8:32:05 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: default Values should work now

Location:
orxonox/trunk/src/util/loading
Files:
2 edited

Legend:

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

    r4623 r4624  
    113113}
    114114
     115
     116int isInt(const char* Int, int defaultValue)
     117{
     118  char* endPtr = NULL;
     119  int result = strtol(Int, &endPtr, 10);
     120
     121  if ( endPtr >= Int && endPtr < Int + strlen(Int))
     122    return defaultValue;
     123  else
     124    return result;
     125}
     126
     127float isFloat(const char* Float, float defaultValue)
     128{
     129  char* endPtr = NULL;
     130  double result = strtod(Float, &endPtr);
     131
     132  if ( endPtr >= Float && endPtr < Float + strlen(Float))
     133    return defaultValue;
     134  else
     135    return result;
     136}
     137
     138const char* isString(const char* string, const char* defaultValue)
     139{
     140  if (string != NULL)
     141    return string;
     142  else
     143    return defaultValue;
     144}
     145
     146
    115147/**
    116148   \param descriptionText The text to set as a description for this Parameter
  • orxonox/trunk/src/util/loading/load_param.h

    r4623 r4624  
    5151
    5252#define l_INT_TYPE         int                  //!< The type of an INT
    53 #define l_INT_FUNC         atoi                 //!< The function to call to parse INT
     53#define l_INT_FUNC         isInt                //!< The function to call to parse INT
    5454#define l_INT_NAME         "int"                //!< The name of an INT
    5555#define l_INT_DEFAULT      0                    //!< a default Value for an INT
    5656
    5757#define l_LONG_TYPE        long                 //!< The type of a LONG
    58 #define l_LONG_FUNC        atol                 //!< The function to parse a LONG
     58#define l_LONG_FUNC        isInt                //!< The function to parse a LONG
    5959#define l_LONG_NAME        "long"               //!< The name of a LONG
    6060#define l_LONG_DEFAULT     0                    //!< a default Value for a LONG
     
    6666
    6767#define l_FLOAT_TYPE       float                //!< The type of a FLOAT
    68 #define l_FLOAT_FUNC       atof                 //!< The function to parse a FLOAT
     68#define l_FLOAT_FUNC       isFloat              //!< The function to parse a FLOAT
    6969#define l_FLOAT_NAME       "float"              //!< The name of a FLOAT
    7070#define l_FLOAT_DEFAULT    0.0                  //!< a default Value for a FLOAT
    7171
    7272#define l_STRING_TYPE      const char*          //!< The type of a STRING
    73 #define l_STRING_FUNC                           //!< The function to parse a STRING
     73#define l_STRING_FUNC      isString             //!< The function to parse a STRING
    7474#define l_STRING_NAME      "string"             //!< The name of a STRING
    7575#define l_STRING_DEFAULT   ""                   //!< a default Value for an STRING
     
    9595    { \
    9696      if (loadString != NULL && root != NULL) \
    97         (*pt2Object.*function)(type1##_FUNC(loadString)); \
     97        (*pt2Object.*function)(type1##_FUNC(loadString, default1)); \
    9898      else \
    9999        PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
     
    116116          SubString subLoads(loadString); \
    117117          if (subLoads.getCount() == 2) \
    118             (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1))); \
     118            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2)); \
    119119          else \
    120120            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
     
    142142          SubString subLoads(loadString); \
    143143          if (subLoads.getCount() == 3) \
    144             (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2))); \
     144            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2), type3##_FUNC(subLoads.getString(2), default3)); \
    145145          else \
    146146            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
     
    171171          SubString subLoads(loadString); \
    172172          if (subLoads.getCount() == 4) \
    173             (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3))); \
     173            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2), type3##_FUNC(subLoads.getString(2), default3), type4##_FUNC(subLoads.getString(3), default4)); \
    174174          else \
    175175            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
     
    202202          SubString subLoads(loadString); \
    203203          if (subLoads.getCount() == 5) \
    204             (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0)), type2##_FUNC(subLoads.getString(1)), type3##_FUNC(subLoads.getString(2)), type4##_FUNC(subLoads.getString(3)), type5##_FUNC(subLoads.getString(4))); \
     204            (*pt2Object.*function)(type1##_FUNC(subLoads.getString(0), default1), type2##_FUNC(subLoads.getString(1), default2), type3##_FUNC(subLoads.getString(2), default3), type4##_FUNC(subLoads.getString(3), default4), type5##_FUNC(subLoads.getString(4), default5)); \
    205205          else \
    206206            PRINTF(2)("Not loaded Parameter %s of %s, because wrong count of arguments.\n -> Should have %d but have %d\n", \
     
    226226}
    227227
     228
     229/***********************
     230*** HELPER FUNCTIONS ***
     231***********************/
     232int           isInt(const char* Int, int defaultValue);
     233float         isFloat(const char* Float, float defaultValue);
     234const char*   isString(const char* string, const char* defaultValue);
     235//TiXmlEmlemnt* isXmlElem(const)
     236
     237
     238/************************
     239*** DESCRIPTION STUFF ***
     240************************/
    228241//! A class that handles the description of loadable parameters
    229242class LoadParamDescription
     
    269282};
    270283
     284
     285/**************************
     286**** REAL DECLARATIONS ****
     287**************************/
    271288//! abstract Base class for a Loadable parameter
    272289class BaseLoadParam : public BaseObject
Note: See TracChangeset for help on using the changeset viewer.