Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

compiles again

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