Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/new_class_id: new Executor construct, that is much more typesafe, faster, and easier to extend…

Also changed the LoadParam process, and adapted ScriptEngine calls

Then at the end, some missing headers appeared, and appended them to all the cc-files again.

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