Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/loading/load_param.h @ 9733

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

cleanup

File size: 4.1 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/*!
17 * @file load_param.h
18 * A Class and macro-functions, that makes our lives easy to load-in parameters
19 */
20
21#ifndef _LOAD_PARAM_H
22#define _LOAD_PARAM_H
23
24#include "base_object.h"
25
26#include "executor/executor.h"
27#include "executor/executor_functional.h"
28
29#include "parser/tinyxml/tinyxml.h"
30
31// Forward Declaration //
32class LoadClassDescription;
33class LoadParamDescription;
34class TiXmlElement;
35
36/**
37 * Loads a Parameter from ROOT named PARAMETER_NAME
38 * onto OBJECT of CLASS, trough the FUNCTION
39 * @param ROOT the TiXmlElement to load the Parameter from
40 * @param PARAMETER_NAME the Name of the Parameter to load
41 * @param OBJECT The BaseObject to load the new setting to.
42 * @param CLASS What Class the BaseObejct is of (this is for identifying the Functuon)
43 * @param FUNCTION The function of Class to Load (if you want to call &CLASS::FUNCTION write FUNCTION here).
44 */
45#define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
46         CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), false)
47
48#define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
49         CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true)
50
51/**
52 * this Starts a Cycle in the Loading Process
53 * be aware, that in the cycle the first parameter of load_param should because
54 * called element, and that you must say true at the Fith parameter, or it will fail
55 * also you will have to close the Cycle again with LOAD_PARAM_END_CYCLE
56 *
57 * @param ROOT The root XLM-element to search element under.
58 * @param ELEMENT the element to search
59 */
60#define LOAD_PARAM_START_CYCLE(ROOT, ELEMENT) \
61  const TiXmlElement* ELEMENT; \
62  ELEMENT= ROOT->FirstChildElement(); \
63  while( ELEMENT != NULL) \
64{
65/**
66   * closes a LoadParam Loop
67   * @see LOAD_PARAM_START_CYCLE
68   * @param ELEMENT the Element to step through.
69 */
70#define LOAD_PARAM_END_CYCLE(ELEMENT) \
71  ELEMENT = ELEMENT->NextSiblingElement(); \
72}
73
74
75/**************************
76**** REAL DECLARATIONS ****
77**************************/
78class LoadParamBase : public BaseObject
79{
80protected:
81  LoadParamBase(const TiXmlElement* root, const std::string& paramName, BaseObject* object, bool inLoadCycle = false);
82
83protected:
84  void describe(const std::string& descriptionText);
85
86protected:
87  BaseObject*              object;
88  const std::string        paramName;
89  bool                     inLoadCycle;
90
91  LoadClassDescription*    classDesc;            //!< The LoadClassDescription of this CLoadParameter
92  LoadParamDescription*    paramDesc;            //!< The LoadParameterDescription of this LoadParameter
93  const TiXmlElement*      loadElem;             //!< The Element to load.
94};
95
96
97//! abstract Base class for a Loadable parameter
98class CLoadParam : public LoadParamBase
99{
100public:
101  CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const SubString>* executor, bool inLoadCycle = false);
102  virtual ~CLoadParam();
103
104  CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
105                            const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
106                            const MultiType& value4 = MT_NULL);
107  CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; };
108  //     CLoadParam& attribute(const std::string& attributeName, const Executor<SubString>& executor);
109
110
111private:
112  Executor<const SubString>*         executor;
113};
114
115// helper function
116
117std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);
118const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);
119
120#endif /* _LOAD_PARAM_H */
Note: See TracBrowser for help on using the repository browser.