Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib/util/loading/load_param.h


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/loading/load_param.h

    r8048 r9869  
    2222#define _LOAD_PARAM_H
    2323
    24 #include "base_object.h"
     24#include "util/executor/executor_substring.h"
     25#include "util/executor/executor_member.h"
     26#include "util/executor/functor_member.h"
    2527
    26 #include "executor/executor.h"
    27 #include "executor/executor_xml.h"
     28#include "parser/tinyxml/tinyxml.h"
    2829
    2930// Forward Declaration //
    3031class LoadClassDescription;
    3132class LoadParamDescription;
    32 class MultiType;
    33 
     33class TiXmlElement;
    3434
    3535/**
    3636 * Loads a Parameter from ROOT named PARAMETER_NAME
    37  * onto OBJECT of CLASS, trough the FUNCTION
     37 * onto OBJECT of CLASS, trough FUNCTION
    3838 * @param ROOT the TiXmlElement to load the Parameter from
    3939 * @param PARAMETER_NAME the Name of the Parameter to load
     
    4343 */
    4444#define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
    45          CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), false)
     45         CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), false)
    4646
     47/**
     48 * @brief Does essentially the same as LoadParam, but within a Cycle in an ordered fashion.
     49 *
     50 * This Function looks in each Element, if the PARAMETER_NAME matches, and loads onto OBJECT
     51 * of CLASS the ROOT through FUNCTION
     52 *
     53 * @see LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION)
     54 */
    4755#define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
    48          CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true)
    49 
    50 #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
    51          CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false)
    52 
    53 #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \
    54          CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true)
    55 
     56         CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), true)
    5657
    5758/**
     
    7879}
    7980
     81
    8082/**************************
    8183**** REAL DECLARATIONS ****
    8284**************************/
    83 //! abstract Base class for a Loadable parameter
    84 class CLoadParam : public BaseObject
     85//!< A BaseClass for all LoadParam's.
     86class LoadParamBase
    8587{
    86   public:
    87     CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false);
    88     virtual ~CLoadParam();
     88protected:
     89  LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle = false);
    8990
    90     CLoadParam& describe(const std::string& descriptionText);
    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);
    94     CLoadParam& attribute(const std::string& attributeName, const Executor& executor);
     91protected:
     92  void describe(const ClassID& classID, const std::string& descriptionText);
     93  void setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal = false);
     94
     95public:
     96  static std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);
     97  static const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);
     98
     99protected:
     100  const std::string        paramName;            //!< The Name of the Parameter this LoadParams applies to.
     101  bool                     inLoadCycle;          //!< If the Parameter is in a LoadCycle.
     102
     103  const TiXmlElement*      loadElem;             //!< The Element to load.
     104};
    95105
    96106
    97   private:
    98     bool                     inLoadCycle;
    99     Executor*                executor;
    100     BaseObject*              object;
    101     const std::string        paramName;
     107//! The Loading Class of the LoadParam, that acctually executes the loading process.
     108template <class OperateClass> class CLoadParam : public LoadParamBase
     109{
     110public:
     111  /**
     112   * @brief generates a LoadParam based on:
     113   * @param root the Root Element to load onto the object. @param paramName the Parameter name that is loaded.
     114   * @param object the Object to apply the changes on. @param executor the Functional Object, that actually executes the function Call.
     115   * @param inLoadCycle If we are inside of a loading cycle. (Loading will be different here)
     116   */
     117  CLoadParam(const TiXmlElement* root, const std::string& paramName, OperateClass* object, Executor<const SubString, OperateClass>* executor, bool inLoadCycle = false)
     118      : LoadParamBase(root, paramName, inLoadCycle)
     119  {
     120    assert (executor != NULL);
     121    this->object = object;
     122    this->executor = executor;
     123  }
     124  virtual ~CLoadParam()
     125  {
     126    std::string loadString;
     127    if (this->loadElem != NULL &&  this->loadElem->ToText())
     128    {
     129      loadString = this->loadElem->Value();
     130      if (!loadString.empty())
     131      {
     132        /*      PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n",
     133                this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName());*/
     134        (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\'));
     135      }
     136    }
     137    this->setDescriptionValues(OperateClass::staticClassID(), executor->getParamCount(), executor->getDefaultValues(), executor->hasRetVal());
     138    delete this->executor;
     139  }
     140  /**
     141   * @brief set the default values of the executor
     142   * @param value0 the first default value   @param value1 the second default value
     143   * @param value2 the third default value   @param value3 the fourth default value
     144   * @param value4 the fifth default value
     145   */
     146  CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
     147                            const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
     148                            const MultiType& value4 = MT_NULL)
     149  { this->executor->defaultValues(value0, value1, value2, value3, value4); return *this;  };
     150  //! Describes a LoadParam
     151  CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(OperateClass::staticClassID(), descriptionText); return *this; };
     152  //     CLoadParam& attribute(const std::string& attributeName, const Executor<SubString>& executor);
    102153
    103     LoadClassDescription*    classDesc;            //!< The LoadClassDescription of this CLoadParameter
    104     LoadParamDescription*    paramDesc;            //!< The LoadParameterDescription of this LoadParameter
    105     const TiXmlElement*      loadElem;             //!< The Element to load.
    106     const void*              pointerToParam;       //!< A Pointer to a Parameter.
    107 
    108     MultiType*               defaultValue;
     154private:
     155  Executor<const SubString, OperateClass>*         executor;            //!< The Executor, that actually executes the Loading process.
     156  OperateClass*                                    object;              //!< The Object this LoadParam operates on.
    109157};
    110158
    111 // helper function
    112 
    113 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);
    114 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);
    115 
    116159#endif /* _LOAD_PARAM_H */
Note: See TracChangeset for help on using the changeset viewer.