/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ /*! * @file load_param.h * A Class and macro-functions, that makes our lives easy to load-in parameters */ #ifndef _LOAD_PARAM_H #define _LOAD_PARAM_H #include "base_object.h" #include "executor/executor.h" #include "parser/tinyxml/tinyxml.h" // Forward Declaration // class LoadClassDescription; class LoadParamDescription; /** * Loads a Parameter from ROOT named PARAMETER_NAME * onto OBJECT of CLASS, trough the FUNCTION * @param ROOT the TiXmlElement to load the Parameter from * @param PARAMETER_NAME the Name of the Parameter to load * @param OBJECT The BaseObject to load the new setting to. * @param CLASS What Class the BaseObejct is of (this is for identifying the Functuon) * @param FUNCTION The function of Class to Load (if you want to call &CLASS::FUNCTION write FUNCTION here). */ #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor(&CLASS::FUNCTION), false) #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor(&CLASS::FUNCTION), true) /** * this Starts a Cycle in the Loading Process * be aware, that in the cycle the first parameter of load_param should because * called element, and that you must say true at the Fith parameter, or it will fail * also you will have to close the Cycle again with LOAD_PARAM_END_CYCLE * * @param ROOT The root XLM-element to search element under. * @param ELEMENT the element to search */ #define LOAD_PARAM_START_CYCLE(ROOT, ELEMENT) \ const TiXmlElement* ELEMENT; \ ELEMENT= ROOT->FirstChildElement(); \ while( ELEMENT != NULL) \ { /** * closes a LoadParam Loop * @see LOAD_PARAM_START_CYCLE * @param ELEMENT the Element to step through. */ #define LOAD_PARAM_END_CYCLE(ELEMENT) \ ELEMENT = ELEMENT->NextSiblingElement(); \ } /************************** **** REAL DECLARATIONS **** **************************/ class LoadParamBase : public BaseObject { protected: LoadParamBase(const TiXmlElement* root, const std::string& paramName, BaseObject* object, bool inLoadCycle = false); protected: void describe(const std::string& descriptionText); protected: BaseObject* object; const std::string paramName; bool inLoadCycle; LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter const TiXmlElement* loadElem; //!< The Element to load. }; //! abstract Base class for a Loadable parameter class CLoadParam : public LoadParamBase { public: CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false); virtual ~CLoadParam(); CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, const MultiType& value4 = MT_NULL); CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(descriptionText); return *this; }; // CLoadParam& attribute(const std::string& attributeName, const Executor& executor); private: Executor* executor; }; // helper function std::string grabParameter(const TiXmlElement* root, const std::string& parameterName); const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName); #endif /* _LOAD_PARAM_H */