[4597] | 1 | /* |
---|
[4250] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
[4285] | 12 | main-programmer: Benjamin Grauer |
---|
[4250] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[5654] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING |
---|
| 17 | |
---|
[7193] | 18 | #include "util/loading/load_param.h" |
---|
[9765] | 19 | #include "load_param_class_description.h" |
---|
[9727] | 20 | #include "compiler.h" |
---|
| 21 | #include "debug.h" |
---|
[4256] | 22 | /** |
---|
[9763] | 23 | * @brief Constructs a new LoadParameter |
---|
[5653] | 24 | * @param root the XML-element to load this Parameter from |
---|
| 25 | * @param paramName the Parameter to load |
---|
| 26 | * @param object the BaseObject, to load this parameter on to (will be cast to executor's Parameter) |
---|
[9763] | 27 | * @param inLoadCycle If we are in a LoadCycle (loading differs.). |
---|
[5653] | 28 | */ |
---|
[9769] | 29 | LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle) |
---|
| 30 | : paramName(paramName), inLoadCycle(inLoadCycle) |
---|
[5645] | 31 | { |
---|
[5654] | 32 | // determin the LoadString. |
---|
| 33 | if (likely(!inLoadCycle)) |
---|
[6613] | 34 | this->loadElem = grabParameterElement(root, paramName); |
---|
[7221] | 35 | else if (paramName == root->Value()) |
---|
[6613] | 36 | this->loadElem = (TiXmlElement*)root->FirstChild(); |
---|
[5645] | 37 | else |
---|
[6613] | 38 | this->loadElem = NULL; |
---|
[9727] | 39 | } |
---|
[5651] | 40 | |
---|
[9727] | 41 | |
---|
| 42 | /** |
---|
| 43 | * @param descriptionText The text to set as a description for this Parameter |
---|
| 44 | * @returns a pointer to itself. |
---|
| 45 | */ |
---|
[9770] | 46 | void LoadParamBase::describe(const ClassID& classID, const std::string& descriptionText) |
---|
[9727] | 47 | { |
---|
[9770] | 48 | PRINTF(5)("Describing Class '%s'(id:%d) Parameter '%s': description '%s'\n", |
---|
| 49 | classID.name().c_str(), classID.id(), paramName.c_str(), descriptionText.c_str()); |
---|
| 50 | |
---|
[9771] | 51 | LoadParamClassDescription::describeClass(classID, paramName, descriptionText); |
---|
| 52 | } |
---|
[9770] | 53 | |
---|
[9771] | 54 | /** |
---|
| 55 | * @brief sets the Values of the Description to a usefull text. |
---|
| 56 | */ |
---|
| 57 | void LoadParamBase::setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal) |
---|
| 58 | { |
---|
[9775] | 59 | if(LoadParamClassDescription::createsDescriptions()) |
---|
| 60 | LoadParamClassDescription::setValuesOf(classID, paramName, paramCount, defaultValues, retVal); |
---|
[9727] | 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
[5655] | 64 | ////////////////////// |
---|
| 65 | // HELPER FUNCTIONS // |
---|
| 66 | ////////////////////// |
---|
[4492] | 67 | /** |
---|
[4836] | 68 | * @param root: The XML-element to grab a parameter from |
---|
| 69 | * @param parameterName: the parameter to grab |
---|
| 70 | * @returns the Value of the parameter if found, NULL otherwise |
---|
[4492] | 71 | */ |
---|
[9771] | 72 | std::string LoadParamBase::grabParameter(const TiXmlElement* root, const std::string& parameterName) |
---|
[4492] | 73 | { |
---|
[9770] | 74 | const TiXmlElement* const element = grabParameterElement(root, parameterName); |
---|
| 75 | if (element != NULL) |
---|
| 76 | return element->Value(); |
---|
| 77 | else |
---|
[7198] | 78 | { |
---|
[9770] | 79 | static std::string empty(""); |
---|
| 80 | return empty; |
---|
[7198] | 81 | } |
---|
[4492] | 82 | } |
---|
[6613] | 83 | |
---|
| 84 | /** |
---|
| 85 | * @param root: The XML-element to grab a parameter from |
---|
| 86 | * @param parameterName: the parameter to grab |
---|
| 87 | * @returns the Element of the parameter if found, NULL otherwise |
---|
| 88 | */ |
---|
[9770] | 89 | const TiXmlElement* LoadParamBase::grabParameterElement(const TiXmlElement* root, const std::string& parameterName) |
---|
[6613] | 90 | { |
---|
| 91 | const TiXmlElement* element; |
---|
| 92 | const TiXmlNode* node; |
---|
| 93 | |
---|
[7221] | 94 | if (root == NULL) |
---|
[6613] | 95 | return NULL; |
---|
| 96 | |
---|
| 97 | element = root->FirstChildElement( parameterName); |
---|
| 98 | if( element == NULL) return NULL; |
---|
| 99 | |
---|
| 100 | node = element->FirstChild(); |
---|
| 101 | while( node != NULL) |
---|
| 102 | { |
---|
| 103 | if( node->ToText()) return (TiXmlElement*)node; |
---|
| 104 | node = node->NextSibling(); |
---|
| 105 | } |
---|
| 106 | return NULL; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|