Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/loading/load_param.h @ 7721

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

orxonox/trunk: introduced the absolutely new, much faster, more templated, and easier to look at Executor, and use it directly inside the LoadParam-Class

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