Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2373


Ignore:
Timestamp:
Dec 10, 2008, 1:33:54 PM (16 years ago)
Author:
rgrieder
Message:

Finished work on new XMLport macro (XMLPortParamVariable).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/core/XMLPort.h

    r2303 r2373  
    8282    @param mode The mode (load or save), you get this from the XMLPort function
    8383
    84     *** EXPERIMENTAL. DO NOT USE UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING! ***
    85 
    8684    In the XML file, a param or attribute will be set like this:
    8785    <classname paramname="value" />
     
    9088*/
    9189#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); \
    95113    XMLPortParamGeneric(xmlcontainer##variable, classname, orxonox::XMLPortVariableHelperClass, &xmlcontainer##variable##dummy, paramname, xmlcontainer##variable##loadexecutor, xmlcontainer##variable##saveexecutor, xmlelement, mode)
    96114
     
    608626    {
    609627        public:
     628            XMLPortVariableHelperClass(void* var)
     629                : variable_(var)
     630                { }
     631
    610632            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; }
    613635
    614636            template <class T>
    615             inline const T& save(const T& var)
    616                 { return var; }
     637            const T& save()
     638                { return *((T*)this->variable_); }
    617639
    618640            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)
    620642                { return &XMLPortVariableHelperClass::load<T>; }
    621643
    622644            template <class T>
    623             static const T& (XMLPortVariableHelperClass::*getSaver(const T& var))(const T& var)
     645            static const T& (XMLPortVariableHelperClass::*getSaver(const T& var))()
    624646                { return &XMLPortVariableHelperClass::save<T>; }
     647
     648        private:
     649            void* variable_;
    625650    };
    626651}
Note: See TracChangeset for help on using the changeset viewer.