Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/load_param.cc @ 9769

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

orxonox/branches/new_class_id: even more templates (mostly to safe space)

File size: 2.9 KB
Line 
1/*
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:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
17
18#include "util/loading/load_param.h"
19#include "load_param_class_description.h"
20#include "compiler.h"
21#include "debug.h"
22/**
23 * @brief Constructs a new LoadParameter
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)
27 * @param inLoadCycle If we are in a LoadCycle (loading differs.).
28 */
29LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle)
30    :  paramName(paramName), inLoadCycle(inLoadCycle)
31{
32  // determin the LoadString.
33  if (likely(!inLoadCycle))
34    this->loadElem = grabParameterElement(root, paramName);
35  else if (paramName == root->Value())
36    this->loadElem = (TiXmlElement*)root->FirstChild();
37  else
38    this->loadElem = NULL;
39}
40
41
42/**
43 * @param descriptionText The text to set as a description for this Parameter
44 * @returns a pointer to itself.
45 */
46void LoadParamBase::describe(const std::string& descriptionText)
47{
48  /// TODO REIMPLEMENT
49  /*  if (LoadParamClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty())
50  {
51    this->paramDesc->setDescription(descriptionText);
52  }*/
53}
54
55
56
57
58
59//////////////////////
60// HELPER FUNCTIONS //
61//////////////////////
62/**
63 * @param root: The XML-element to grab a parameter from
64 * @param parameterName: the parameter to grab
65 * @returns the Value of the parameter if found, NULL otherwise
66*/
67std::string grabParameter(const TiXmlElement* root, const std::string& parameterName)
68{
69  const TiXmlElement* element;
70  const TiXmlNode* node;
71
72  if (root == NULL)
73    return "";
74
75  element = root->FirstChildElement( parameterName);
76  if( element == NULL) return "";
77
78  node = element->FirstChild();
79  while( node != NULL)
80  {
81    if( node->ToText()) return node->Value();
82    node = node->NextSibling();
83  }
84  return "";
85}
86
87/**
88 * @param root: The XML-element to grab a parameter from
89 * @param parameterName: the parameter to grab
90 * @returns the Element of the parameter if found, NULL otherwise
91 */
92const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName)
93{
94  const TiXmlElement* element;
95  const TiXmlNode* node;
96
97  if (root == NULL)
98    return NULL;
99
100  element = root->FirstChildElement( parameterName);
101  if( element == NULL) return NULL;
102
103  node = element->FirstChild();
104  while( node != NULL)
105  {
106    if( node->ToText()) return (TiXmlElement*)node;
107    node = node->NextSibling();
108  }
109  return NULL;
110}
111
112
113
Note: See TracBrowser for help on using the repository browser.