[4592] | 1 | /* |
---|
[4250] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[4233] | 3 | |
---|
[4250] | 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 | |
---|
[4592] | 16 | /*! |
---|
[5039] | 17 | * @file load_param.h |
---|
[5129] | 18 | * A Class and macro-functions, that makes our lives easy to load-in parameters |
---|
| 19 | */ |
---|
[4250] | 20 | |
---|
[4233] | 21 | #ifndef _LOAD_PARAM_H |
---|
| 22 | #define _LOAD_PARAM_H |
---|
| 23 | |
---|
[5652] | 24 | #include "base_object.h" |
---|
[5129] | 25 | |
---|
[5645] | 26 | #include "executor/executor.h" |
---|
[8048] | 27 | #include "executor/executor_xml.h" |
---|
[5549] | 28 | |
---|
[4251] | 29 | // Forward Declaration // |
---|
[5546] | 30 | class LoadClassDescription; |
---|
| 31 | class LoadParamDescription; |
---|
[5556] | 32 | class MultiType; |
---|
[4251] | 33 | |
---|
[5646] | 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 | */ |
---|
[5671] | 44 | #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[7721] | 45 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), false) |
---|
[5646] | 46 | |
---|
[5654] | 47 | #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[7721] | 48 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true) |
---|
[5654] | 49 | |
---|
[5651] | 50 | #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[7721] | 51 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) |
---|
[5646] | 52 | |
---|
[5654] | 53 | #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[7721] | 54 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) |
---|
[5651] | 55 | |
---|
[5654] | 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 | |
---|
[5332] | 80 | /************************** |
---|
| 81 | **** REAL DECLARATIONS **** |
---|
| 82 | **************************/ |
---|
| 83 | //! abstract Base class for a Loadable parameter |
---|
[5671] | 84 | class CLoadParam : public BaseObject |
---|
[5332] | 85 | { |
---|
[5645] | 86 | public: |
---|
[7721] | 87 | CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false); |
---|
[6981] | 88 | virtual ~CLoadParam(); |
---|
[5332] | 89 | |
---|
[7221] | 90 | CLoadParam& describe(const std::string& descriptionText); |
---|
[7198] | 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); |
---|
[7221] | 94 | CLoadParam& attribute(const std::string& attributeName, const Executor& executor); |
---|
[5332] | 95 | |
---|
[5556] | 96 | |
---|
[5655] | 97 | private: |
---|
[5654] | 98 | bool inLoadCycle; |
---|
[5645] | 99 | Executor* executor; |
---|
[5646] | 100 | BaseObject* object; |
---|
[7221] | 101 | const std::string paramName; |
---|
[5645] | 102 | |
---|
[5671] | 103 | LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter |
---|
[5645] | 104 | LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter |
---|
[6613] | 105 | const TiXmlElement* loadElem; //!< The Element to load. |
---|
[5645] | 106 | const void* pointerToParam; //!< A Pointer to a Parameter. |
---|
| 107 | |
---|
| 108 | MultiType* defaultValue; |
---|
[5332] | 109 | }; |
---|
| 110 | |
---|
[4492] | 111 | // helper function |
---|
[4233] | 112 | |
---|
[7221] | 113 | std::string grabParameter(const TiXmlElement* root, const std::string& parameterName); |
---|
| 114 | const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName); |
---|
[4492] | 115 | |
---|
[4233] | 116 | #endif /* _LOAD_PARAM_H */ |
---|