Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 11, 2010, 12:34:00 AM (14 years ago)
Author:
landauf
Message:

merged doc branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/util/VA_NARGS.h

    r7284 r7401  
    2929/**
    3030    @file
     31    @ingroup Util
    3132    @brief Declaration of the ORXONOX_VA_NARGS macro which returns the number of arguments passed to a variadic macro.
     33
     34    With this utility you can overload a macro for different numbers of arguments
     35    (of course overloading is not possible for different types, as macros are not
     36    type aware, but for different numbers of arguments is still very powerful).
     37
     38    Example: A macro to call functions
     39    @code
     40    myfunction();                                           // A static function
     41    MyClass::myStaticFunction();                            // A static class function
     42    MyClass::myFunction();                                  // A member function
     43
     44    #define CallFunction(...) \                             // Define a variadic macro that passes the arguments to the overloaded implementations
     45        BOOST_PP_EXPAND(BOOST_PP_CAT(CallFunction, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__))
     46
     47    #define CallFunction1(function) \                       // Overloaded macro for 1 argument
     48        function()                                          // Calls the static function
     49
     50    #define CallFunction2(class, function) \                // Overloaded macro for 2 arguments
     51        class::function()                                   // Calls the static class function
     52
     53    #define CallFunction3(class, function, object) \        // Overloaded macro for 3 arguments
     54        object->class::function()                           // Calls the function on the object
     55
     56
     57    CallFunction(myFunction);                               // Call the macro with 1 argument
     58    CallFunction(MyClass, myStaticFunction);                // Call the macro with 2 arguments
     59    CallFunction(MyClass, myFunction, new MyClass());       // Call the macro with 3 arguments
     60    @endcode
     61
     62    Note that the first (variadic) macro concatenates the name "CallFunction" with
     63    the number of arguments ("1" - "N"). Then all arguments are passed to the right macro.
    3264*/
    3365
Note: See TracChangeset for help on using the changeset viewer.