Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6613 in orxonox.OLD for trunk


Ignore:
Timestamp:
Jan 19, 2006, 1:51:00 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: better LoadParam

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

Legend:

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

    r5708 r6613  
    3838  // determin the LoadString.
    3939  if (likely(!inLoadCycle))
    40     this->loadString = grabParameter(root, paramName);
     40    this->loadElem = grabParameterElement(root, paramName);
     41  //this->loadString = grabParameter(root, paramName);
     42  else if (!strcmp(root->Value(), paramName))
     43    this->loadElem = (TiXmlElement*)root->FirstChild();
    4144  else
    42   {
    43     if (!strcmp(root->Value(), paramName))
    44     {
    45       const TiXmlNode* val = root->FirstChild();
    46       if( val->ToText())
    47         this->loadString = val->Value();
    48     }
    49     else
    50       this->loadString = NULL;
    51   }
     45    this->loadElem = NULL;
    5246
    5347  // set the Executor.
     
    6559  if (likely(this->executor != NULL))
    6660  {
    67     if (likely(this->object != NULL && this->executor != NULL) &&
     61    if (this->loadElem != NULL &&  this->loadElem->ToText())
     62      this->loadString = this->loadElem->Value();
     63    else
     64      this->loadString = NULL;
     65    if (likely(this->object != NULL) &&
    6866        ( this->loadString != NULL ||
    6967         ((this->executor->getType() & Executor_NoLoadString) == Executor_NoLoadString)))
     
    7472    delete this->executor;
    7573  }
    76 
    7774}
    7875
     
    250247  return NULL;
    251248}
     249
     250/**
     251 * @param root: The XML-element to grab a parameter from
     252 * @param parameterName: the parameter to grab
     253 * @returns the Element of the parameter if found, NULL otherwise
     254 */
     255const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char* parameterName)
     256{
     257  const TiXmlElement* element;
     258  const TiXmlNode* node;
     259
     260  if (root == NULL || parameterName == NULL)
     261    return NULL;
     262  assert( parameterName != NULL);
     263
     264  element = root->FirstChildElement( parameterName);
     265  if( element == NULL) return NULL;
     266
     267  node = element->FirstChild();
     268  while( node != NULL)
     269  {
     270    if( node->ToText()) return (TiXmlElement*)node;
     271    node = node->NextSibling();
     272  }
     273  return NULL;
     274}
     275
     276
     277
  • trunk/src/util/loading/load_param.h

    r5708 r6613  
    104104    LoadClassDescription*    classDesc;            //!< The LoadClassDescription of this CLoadParameter
    105105    LoadParamDescription*    paramDesc;            //!< The LoadParameterDescription of this LoadParameter
     106    const TiXmlElement*      loadElem;             //!< The Element to load.
    106107    const char*              loadString;           //!< The string loaded by this LoadParam
    107108    const void*              pointerToParam;       //!< A Pointer to a Parameter.
     
    113114
    114115const char* grabParameter(const TiXmlElement* root, const char* parameterName);
     116const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char* parameterName);
    115117
    116118#endif /* _LOAD_PARAM_H */
Note: See TracChangeset for help on using the changeset viewer.