/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING #include "util/loading/load_param.h" #include "load_param_class_description.h" #include "compiler.h" #include "debug.h" /** * @brief Constructs a new LoadParameter * @param root the XML-element to load this Parameter from * @param paramName the Parameter to load * @param object the BaseObject, to load this parameter on to (will be cast to executor's Parameter) * @param inLoadCycle If we are in a LoadCycle (loading differs.). */ LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle) : paramName(paramName), inLoadCycle(inLoadCycle) { // determin the LoadString. if (likely(!inLoadCycle)) this->loadElem = grabParameterElement(root, paramName); else if (paramName == root->Value()) this->loadElem = (TiXmlElement*)root->FirstChild(); else this->loadElem = NULL; } /** * @param descriptionText The text to set as a description for this Parameter * @returns a pointer to itself. */ void LoadParamBase::describe(const std::string& descriptionText) { /// TODO REIMPLEMENT /* if (LoadParamClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty()) { this->paramDesc->setDescription(descriptionText); }*/ } ////////////////////// // HELPER FUNCTIONS // ////////////////////// /** * @param root: The XML-element to grab a parameter from * @param parameterName: the parameter to grab * @returns the Value of the parameter if found, NULL otherwise */ std::string grabParameter(const TiXmlElement* root, const std::string& parameterName) { const TiXmlElement* element; const TiXmlNode* node; if (root == NULL) return ""; element = root->FirstChildElement( parameterName); if( element == NULL) return ""; node = element->FirstChild(); while( node != NULL) { if( node->ToText()) return node->Value(); node = node->NextSibling(); } return ""; } /** * @param root: The XML-element to grab a parameter from * @param parameterName: the parameter to grab * @returns the Element of the parameter if found, NULL otherwise */ const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName) { const TiXmlElement* element; const TiXmlNode* node; if (root == NULL) return NULL; element = root->FirstChildElement( parameterName); if( element == NULL) return NULL; node = element->FirstChild(); while( node != NULL) { if( node->ToText()) return (TiXmlElement*)node; node = node->NextSibling(); } return NULL; }