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