[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" |
---|
[5651] | 27 | #include "executor/executor_specials.h" |
---|
[5549] | 28 | |
---|
[5141] | 29 | #include "helper_functions.h" |
---|
[4233] | 30 | |
---|
[4251] | 31 | // Forward Declaration // |
---|
[5546] | 32 | class LoadClassDescription; |
---|
| 33 | class LoadParamDescription; |
---|
[5556] | 34 | class MultiType; |
---|
[4251] | 35 | |
---|
[5646] | 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 | */ |
---|
[5671] | 46 | #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
| 47 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorObjective<CLASS>(&CLASS::FUNCTION), false) |
---|
[5646] | 48 | |
---|
[5654] | 49 | #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[5671] | 50 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorObjective<CLASS>(&CLASS::FUNCTION), true) |
---|
[5654] | 51 | |
---|
[5651] | 52 | #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[5671] | 53 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) |
---|
[5646] | 54 | |
---|
[5654] | 55 | #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[5671] | 56 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) |
---|
[5651] | 57 | |
---|
[5654] | 58 | |
---|
| 59 | /** |
---|
| 60 | * this Starts a Cycle in the Loading Process |
---|
| 61 | * be aware, that in the cycle the first parameter of load_param should because |
---|
| 62 | * called element, and that you must say true at the Fith parameter, or it will fail |
---|
| 63 | * also you will have to close the Cycle again with LOAD_PARAM_END_CYCLE |
---|
| 64 | * |
---|
| 65 | * @param ROOT The root XLM-element to search element under. |
---|
| 66 | * @param ELEMENT the element to search |
---|
| 67 | */ |
---|
| 68 | #define LOAD_PARAM_START_CYCLE(ROOT, ELEMENT) \ |
---|
| 69 | const TiXmlElement* ELEMENT; \ |
---|
| 70 | ELEMENT= ROOT->FirstChildElement(); \ |
---|
| 71 | while( ELEMENT != NULL) \ |
---|
| 72 | { |
---|
| 73 | /** |
---|
| 74 | * closes a LoadParam Loop |
---|
| 75 | * @see LOAD_PARAM_START_CYCLE |
---|
| 76 | * @param ELEMENT the Element to step through. |
---|
| 77 | */ |
---|
| 78 | #define LOAD_PARAM_END_CYCLE(ELEMENT) \ |
---|
| 79 | ELEMENT = ELEMENT->NextSiblingElement(); \ |
---|
| 80 | } |
---|
| 81 | |
---|
[5332] | 82 | /************************** |
---|
| 83 | **** REAL DECLARATIONS **** |
---|
| 84 | **************************/ |
---|
| 85 | //! abstract Base class for a Loadable parameter |
---|
[5671] | 86 | class CLoadParam : public BaseObject |
---|
[5332] | 87 | { |
---|
[5645] | 88 | public: |
---|
[5671] | 89 | CLoadParam(const TiXmlElement* root, const char* paramName, BaseObject* object, const Executor& executor, bool inLoadCycle = false); |
---|
[6981] | 90 | virtual ~CLoadParam(); |
---|
[5332] | 91 | |
---|
[5708] | 92 | CLoadParam& describe(const char* descriptionText); |
---|
| 93 | CLoadParam& defaultValues(unsigned int count, ...); |
---|
| 94 | CLoadParam& attribute(const char* attributeName, const Executor& executor); |
---|
[5332] | 95 | |
---|
[5556] | 96 | |
---|
[5655] | 97 | private: |
---|
[5654] | 98 | bool inLoadCycle; |
---|
[5645] | 99 | Executor* executor; |
---|
[5646] | 100 | BaseObject* object; |
---|
[5652] | 101 | const char* 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 char* loadString; //!< The string loaded by this LoadParam |
---|
| 107 | const void* pointerToParam; //!< A Pointer to a Parameter. |
---|
| 108 | |
---|
| 109 | MultiType* defaultValue; |
---|
[5332] | 110 | }; |
---|
| 111 | |
---|
[4492] | 112 | // helper function |
---|
[4233] | 113 | |
---|
[4492] | 114 | const char* grabParameter(const TiXmlElement* root, const char* parameterName); |
---|
[6613] | 115 | const TiXmlElement* grabParameterElement(const TiXmlElement* root, const char* parameterName); |
---|
[4492] | 116 | |
---|
[4233] | 117 | #endif /* _LOAD_PARAM_H */ |
---|