Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added a Substring handler

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_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 the 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#define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
50         CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true)
51
52/**
53 * this Starts a Cycle in the Loading Process
54 * be aware, that in the cycle the first parameter of load_param should because
55 * called element, and that you must say true at the Fith parameter, or it will fail
56 * also you will have to close the Cycle again with LOAD_PARAM_END_CYCLE
57 *
58 * @param ROOT The root XLM-element to search element under.
59 * @param ELEMENT the element to search
60 */
61#define LOAD_PARAM_START_CYCLE(ROOT, ELEMENT) \
62  const TiXmlElement* ELEMENT; \
63  ELEMENT= ROOT->FirstChildElement(); \
64  while( ELEMENT != NULL) \
65{
66/**
67   * closes a LoadParam Loop
68   * @see LOAD_PARAM_START_CYCLE
69   * @param ELEMENT the Element to step through.
70 */
71#define LOAD_PARAM_END_CYCLE(ELEMENT) \
72  ELEMENT = ELEMENT->NextSiblingElement(); \
73}
74
75
76/**************************
77**** REAL DECLARATIONS ****
78**************************/
79class LoadParamBase : public BaseObject
80{
81protected:
82  LoadParamBase(const TiXmlElement* root, const std::string& paramName, BaseObject* object, bool inLoadCycle = false);
83
84protected:
85  void describe(const std::string& descriptionText);
86
87protected:
88  BaseObject*              object;
89  const std::string        paramName;
90  bool                     inLoadCycle;
91
92  LoadClassDescription*    classDesc;            //!< The LoadClassDescription of this CLoadParameter
93  LoadParamDescription*    paramDesc;            //!< The LoadParameterDescription of this LoadParameter
94  const TiXmlElement*      loadElem;             //!< The Element to load.
95};
96
97
98//! abstract Base class for a Loadable parameter
99class CLoadParam : public LoadParamBase
100{
101public:
102  CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor<const SubString>* executor, bool inLoadCycle = false);
103  virtual ~CLoadParam();
104
105  CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
106                            const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
107                            const MultiType& value4 = MT_NULL);
108  CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; };
109  //     CLoadParam& attribute(const std::string& attributeName, const Executor<SubString>& executor);
110
111
112private:
113  Executor<const SubString>*         executor;
114};
115
116// helper function
117
118std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);
119const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);
120
121#endif /* _LOAD_PARAM_H */
Note: See TracBrowser for help on using the repository browser.