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