Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/loading/load_param.cc @ 10585

Last change on this file since 10585 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.3 KB
RevLine 
[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
[9869]18#include "load_param.h"
19#include "load_param_class_description.h"
20#include "compiler.h"
21#include "debug.h"
[4256]22/**
[9869]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
[9869]26 * @param inLoadCycle If we are in a LoadCycle (loading differs.).
[5653]27 */
[9869]28LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle)
29    :  paramName(paramName), inLoadCycle(inLoadCycle)
[5645]30{
[5654]31  // determin the LoadString.
32  if (likely(!inLoadCycle))
[6613]33    this->loadElem = grabParameterElement(root, paramName);
[7221]34  else if (paramName == root->Value())
[6613]35    this->loadElem = (TiXmlElement*)root->FirstChild();
[5645]36  else
[6613]37    this->loadElem = NULL;
[5645]38}
[5651]39
[5645]40
[5653]41/**
[9869]42 * @param classID the ID of the class. This is needed to identify into what class this Parameter belongs.
43 * @param descriptionText The text to set as a description for this Parameter
44 * @returns a pointer to itself.
[5653]45 */
[9869]46void LoadParamBase::describe(const ClassID& classID, const std::string& descriptionText)
[5652]47{
[9869]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());
[5652]50
[9869]51  if (LoadParamClassDescription::descriptionsCaptured())
52    LoadParamClassDescription::describeClass(classID, paramName, descriptionText);
[5652]53}
54
[4860]55/**
[9869]56 * @brief sets the Values of the Description to a usefull text.
57 */
58void LoadParamBase::setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal)
[4254]59{
[9869]60  if(LoadParamClassDescription::descriptionsCaptured())
61    LoadParamClassDescription::setValuesOf(classID, paramName, paramCount, defaultValues, retVal);
[4254]62}
63
[5100]64
[5655]65//////////////////////
66// HELPER FUNCTIONS //
67//////////////////////
[4492]68/**
[4836]69 * @param root: The XML-element to grab a parameter from
70 * @param parameterName: the parameter to grab
71 * @returns the Value of the parameter if found, NULL otherwise
[4492]72*/
[9869]73std::string LoadParamBase::grabParameter(const TiXmlElement* root, const std::string& parameterName)
[4492]74{
[9869]75  const TiXmlElement* const element = grabParameterElement(root, parameterName);
76  if (element != NULL)
77    return element->Value();
78  else
[7198]79  {
[9869]80    static std::string empty("");
81    return empty;
[7198]82  }
[4492]83}
[6613]84
85/**
86 * @param root: The XML-element to grab a parameter from
87 * @param parameterName: the parameter to grab
88 * @returns the Element of the parameter if found, NULL otherwise
89 */
[9869]90const TiXmlElement* LoadParamBase::grabParameterElement(const TiXmlElement* root, const std::string& parameterName)
[6613]91{
92  const TiXmlElement* element;
93  const TiXmlNode* node;
94
[7221]95  if (root == NULL)
[6613]96    return NULL;
97
98  element = root->FirstChildElement( parameterName);
99  if( element == NULL) return NULL;
100
101  node = element->FirstChild();
102  while( node != NULL)
103  {
104    if( node->ToText()) return (TiXmlElement*)node;
105    node = node->NextSibling();
106  }
107  return NULL;
108}
Note: See TracBrowser for help on using the repository browser.