Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2008, 4:28:06 PM (17 years ago)
Author:
landauf
Message:

added a variadic macro to ConfigValueIncludes.h:
ModifyConfigValue(varname, modifier, …) calls 'modifier' (which is a function like set, tset, update, reset, add, remove) and … are the possible arguments (or nothing). i'm not sure if this works on all compilers.
http://en.wikipedia.org/wiki/Variadic_macro

Location:
code/branches/core2/src/orxonox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/ConfigValueIncludes.h

    r1031 r1033  
    8383    else \
    8484    { \
    85         COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl; \
     85        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
     86    }
     87
     88/**
     89    @brief Modifies a config-value by using a modifier and some arguments.
     90    @param varname The name of the config-value
     91    @param modifier The name of the modifier: set, tset, add, remove, reset, update
     92*/
     93#define ModifyConfigValue(varname, modifier, ...) \
     94    orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
     95    if (container##varname##modify##modifier) \
     96    { \
     97        container##varname##modify##modifier->modifier(__VA_ARGS__); \
     98        container##varname##modify##modifier->getValue(&varname); \
     99    } \
     100    else \
     101    { \
     102        COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
    86103    }
    87104
  • code/branches/core2/src/orxonox/objects/test3.cc

    r1030 r1033  
    8787        for (unsigned int i = 0; i < this->vector_vector3_.size(); i++)
    8888        std::cout << "vector<vector3>: " << i << ": " << this->vector_vector3_[i] << std::endl;
     89
     90        ModifyConfigValue(value_int_, tset, "100");
     91        std::cout << std::endl;
     92        std::cout << "int:             " << this->value_int_ << std::endl;
     93
     94        ModifyConfigValue(value_int_, update);
     95        std::cout << std::endl;
     96        std::cout << "int:             " << this->value_int_ << std::endl;
    8997    }
    9098
Note: See TracChangeset for help on using the changeset viewer.