Changeset 2373 for code/branches/physics/src/core
- Timestamp:
- Dec 10, 2008, 1:33:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/core/XMLPort.h
r2303 r2373 82 82 @param mode The mode (load or save), you get this from the XMLPort function 83 83 84 *** EXPERIMENTAL. DO NOT USE UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING! ***85 86 84 In the XML file, a param or attribute will be set like this: 87 85 <classname paramname="value" /> … … 90 88 */ 91 89 #define XMLPortParamVariable(classname, paramname, variable, xmlelement, mode) \ 92 static XMLPortVariableHelperClass xmlcontainer##variable##dummy; \ 93 static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##loadexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(&(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getLoader(variable)), std::string( #classname ) + "::" + #variable + "loader")->setDefaultValue(1, &variable))); \ 94 static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##saveexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(&(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getSaver (variable)), std::string( #classname ) + "::" + #variable + "saver" )->setDefaultValue(0, variable))); \ 90 static XMLPortVariableHelperClass xmlcontainer##variable##dummy((void*)&variable); \ 91 static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##loadexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(&(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getLoader(variable)), std::string( #classname ) + "::" + #variable + "loader"))); \ 92 static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##saveexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(&(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getSaver (variable)), std::string( #classname ) + "::" + #variable + "saver" ))); \ 93 XMLPortParamGeneric(xmlcontainer##variable, classname, orxonox::XMLPortVariableHelperClass, &xmlcontainer##variable##dummy, paramname, xmlcontainer##variable##loadexecutor, xmlcontainer##variable##saveexecutor, xmlelement, mode) 94 95 /** 96 @brief Declares an XML attribute with a name, which will be set through a variable and gotten from a function. 97 @param classname The name of the class owning this param 98 @param paramname The name of the attribute 99 @param variable Name of the variable used to save the value 100 @param savefunction A function to get the value of the param from the object (~a get-function) 101 @param xmlelement The XMLElement, you get this from the XMLPort function 102 @param mode The mode (load or save), you get this from the XMLPort function 103 104 In the XML file, a param or attribute will be set like this: 105 <classname paramname="value" /> 106 107 The macro will then store "value" in the variable or read it when saving. 108 */ 109 #define XMLPortParamVariableOnLoad(classname, paramname, variable, savefunction, xmlelement, mode) \ 110 static XMLPortVariableHelperClass xmlcontainer##variable##dummy((void*)&variable); \ 111 static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##loadexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(&(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getLoader(variable)), std::string( #classname ) + "::" + #variable + "loader"))); \ 112 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 95 113 XMLPortParamGeneric(xmlcontainer##variable, classname, orxonox::XMLPortVariableHelperClass, &xmlcontainer##variable##dummy, paramname, xmlcontainer##variable##loadexecutor, xmlcontainer##variable##saveexecutor, xmlelement, mode) 96 114 … … 608 626 { 609 627 public: 628 XMLPortVariableHelperClass(void* var) 629 : variable_(var) 630 { } 631 610 632 template <class T> 611 inline void load(const T& value, T* var)612 { * var= value; }633 void load(const T& value) 634 { *((T*)this->variable_) = value; } 613 635 614 636 template <class T> 615 inline const T& save(const T& var)616 { return var; }637 const T& save() 638 { return *((T*)this->variable_); } 617 639 618 640 template <class T> 619 static void (XMLPortVariableHelperClass::*getLoader(const T& var))(const T& value , T* var)641 static void (XMLPortVariableHelperClass::*getLoader(const T& var))(const T& value) 620 642 { return &XMLPortVariableHelperClass::load<T>; } 621 643 622 644 template <class T> 623 static const T& (XMLPortVariableHelperClass::*getSaver(const T& var))( const T& var)645 static const T& (XMLPortVariableHelperClass::*getSaver(const T& var))() 624 646 { return &XMLPortVariableHelperClass::save<T>; } 647 648 private: 649 void* variable_; 625 650 }; 626 651 }
Note: See TracChangeset
for help on using the changeset viewer.