[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 // |
---|
| 32 | template<class T> class tList; |
---|
[5546] | 33 | class LoadClassDescription; |
---|
| 34 | class LoadParamDescription; |
---|
[5556] | 35 | class MultiType; |
---|
[4251] | 36 | |
---|
[5646] | 37 | |
---|
| 38 | /** |
---|
| 39 | * Loads a Parameter from ROOT named PARAMETER_NAME |
---|
| 40 | * onto OBJECT of CLASS, trough the FUNCTION |
---|
| 41 | * @param ROOT the TiXmlElement to load the Parameter from |
---|
| 42 | * @param PARAMETER_NAME the Name of the Parameter to load |
---|
| 43 | * @param OBJECT The BaseObject to load the new setting to. |
---|
| 44 | * @param CLASS What Class the BaseObejct is of (this is for identifying the Functuon) |
---|
| 45 | * @param FUNCTION The function of Class to Load (if you want to call &CLASS::FUNCTION write FUNCTION here). |
---|
| 46 | */ |
---|
[5671] | 47 | #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
| 48 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorObjective<CLASS>(&CLASS::FUNCTION), false) |
---|
[5646] | 49 | |
---|
[5654] | 50 | #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[5671] | 51 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorObjective<CLASS>(&CLASS::FUNCTION), true) |
---|
[5654] | 52 | |
---|
[5651] | 53 | #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[5671] | 54 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) |
---|
[5646] | 55 | |
---|
[5654] | 56 | #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ |
---|
[5671] | 57 | CLoadParam(ROOT, PARAMETER_NAME, OBJECT, ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) |
---|
[5651] | 58 | |
---|
[5654] | 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 | |
---|
[5332] | 83 | /************************** |
---|
| 84 | **** REAL DECLARATIONS **** |
---|
| 85 | **************************/ |
---|
| 86 | //! abstract Base class for a Loadable parameter |
---|
[5671] | 87 | class CLoadParam : public BaseObject |
---|
[5332] | 88 | { |
---|
[5645] | 89 | public: |
---|
[5671] | 90 | CLoadParam(const TiXmlElement* root, const char* paramName, BaseObject* object, const Executor& executor, bool inLoadCycle = false); |
---|
| 91 | ~CLoadParam(); |
---|
[5332] | 92 | |
---|
[5708] | 93 | CLoadParam& describe(const char* descriptionText); |
---|
| 94 | CLoadParam& defaultValues(unsigned int count, ...); |
---|
| 95 | CLoadParam& attribute(const char* attributeName, const Executor& executor); |
---|
[5332] | 96 | |
---|
[5556] | 97 | |
---|
[5655] | 98 | private: |
---|
[5654] | 99 | bool inLoadCycle; |
---|
[5645] | 100 | Executor* executor; |
---|
[5646] | 101 | BaseObject* object; |
---|
[5652] | 102 | const char* paramName; |
---|
[5645] | 103 | |
---|
[5671] | 104 | LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter |
---|
[5645] | 105 | LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter |
---|
| 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); |
---|
| 115 | |
---|
[4233] | 116 | #endif /* _LOAD_PARAM_H */ |
---|