| [6452] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
 | 3 |  *                    > www.orxonox.net < | 
|---|
 | 4 |  * | 
|---|
 | 5 |  * | 
|---|
 | 6 |  *   License notice: | 
|---|
 | 7 |  * | 
|---|
 | 8 |  *   This program is free software; you can redistribute it and/or | 
|---|
 | 9 |  *   modify it under the terms of the GNU General Public License | 
|---|
 | 10 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
 | 11 |  *   of the License, or (at your option) any later version. | 
|---|
 | 12 |  * | 
|---|
 | 13 |  *   This program is distributed in the hope that it will be useful, | 
|---|
 | 14 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 15 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 16 |  *   GNU General Public License for more details. | 
|---|
 | 17 |  * | 
|---|
 | 18 |  *   You should have received a copy of the GNU General Public License | 
|---|
 | 19 |  *   along with this program; if not, write to the Free Software | 
|---|
 | 20 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
 | 21 |  * | 
|---|
 | 22 |  *   Author: | 
|---|
 | 23 |  *      Fabian 'x3n' Landau | 
|---|
 | 24 |  *   Co-authors: | 
|---|
 | 25 |  *      ... | 
|---|
 | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | /** | 
|---|
 | 30 |     @file | 
|---|
| [7401] | 31 |     @ingroup Util | 
|---|
| [6452] | 32 |     @brief Declaration of the ORXONOX_VA_NARGS macro which returns the number of arguments passed to a variadic macro. | 
|---|
| [7401] | 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 |  | 
|---|
| [9550] | 38 |     Important: The macro can not be overloaded for 0 arguments: ORXONOX_VA_NARGS() returns 1! | 
|---|
 | 39 |  | 
|---|
| [7401] | 40 |     Example: A macro to call functions | 
|---|
 | 41 |     @code | 
|---|
 | 42 |     myfunction();                                           // A static function | 
|---|
 | 43 |     MyClass::myStaticFunction();                            // A static class function | 
|---|
 | 44 |     MyClass::myFunction();                                  // A member function | 
|---|
 | 45 |  | 
|---|
 | 46 |     #define CallFunction(...) \                             // Define a variadic macro that passes the arguments to the overloaded implementations | 
|---|
 | 47 |         BOOST_PP_EXPAND(BOOST_PP_CAT(CallFunction, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)) | 
|---|
 | 48 |  | 
|---|
 | 49 |     #define CallFunction1(function) \                       // Overloaded macro for 1 argument | 
|---|
 | 50 |         function()                                          // Calls the static function | 
|---|
 | 51 |  | 
|---|
 | 52 |     #define CallFunction2(class, function) \                // Overloaded macro for 2 arguments | 
|---|
 | 53 |         class::function()                                   // Calls the static class function | 
|---|
 | 54 |  | 
|---|
 | 55 |     #define CallFunction3(class, function, object) \        // Overloaded macro for 3 arguments | 
|---|
 | 56 |         object->class::function()                           // Calls the function on the object | 
|---|
 | 57 |  | 
|---|
 | 58 |  | 
|---|
 | 59 |     CallFunction(myFunction);                               // Call the macro with 1 argument | 
|---|
 | 60 |     CallFunction(MyClass, myStaticFunction);                // Call the macro with 2 arguments | 
|---|
 | 61 |     CallFunction(MyClass, myFunction, new MyClass());       // Call the macro with 3 arguments | 
|---|
 | 62 |     @endcode | 
|---|
 | 63 |  | 
|---|
 | 64 |     Note that the first (variadic) macro concatenates the name "CallFunction" with | 
|---|
 | 65 |     the number of arguments ("1" - "N"). Then all arguments are passed to the right macro. | 
|---|
| [6452] | 66 | */ | 
|---|
 | 67 |  | 
|---|
| [9550] | 68 | #include <boost/preprocessor/cat.hpp> | 
|---|
| [6454] | 69 | #include <boost/preprocessor/facilities/expand.hpp> | 
|---|
 | 70 |  | 
|---|
| [6452] | 71 | /** | 
|---|
 | 72 |     @brief Returns the number of arguments passed to a variadic macro. Important: The number of arguments must be greater than zero (ORXONOX_VA_NARGS() returns 1). | 
|---|
 | 73 | */ | 
|---|
 | 74 | #define ORXONOX_VA_NARGS(...) \ | 
|---|
 | 75 |     ORXONOX_VA_NARGS_CONCAT(__VA_ARGS__, ORXONOX_VA_NARGS_NUMBERS) | 
|---|
 | 76 |  | 
|---|
 | 77 |  | 
|---|
 | 78 | // some helper macros // | 
|---|
 | 79 |  | 
|---|
 | 80 | #define ORXONOX_VA_NARGS_CONCAT(...) \ | 
|---|
| [6454] | 81 |     BOOST_PP_EXPAND(ORXONOX_VA_NARGS_INTERN(__VA_ARGS__)) | 
|---|
| [6452] | 82 |  | 
|---|
 | 83 | #define ORXONOX_VA_NARGS_INTERN( \ | 
|---|
 | 84 |     arg1,  arg2,  arg3,  arg4,  arg5,  arg6,  arg7,  arg8,  arg9,  arg10, \ | 
|---|
 | 85 |     arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, \ | 
|---|
 | 86 |     arg21, arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29, arg30, \ | 
|---|
 | 87 |     arg31, arg32, arg33, arg34, arg35, arg36, arg37, arg38, arg39, arg40, \ | 
|---|
 | 88 |     arg41, arg42, arg43, arg44, arg45, arg46, arg47, arg48, arg49, arg50, \ | 
|---|
 | 89 |     arg51, arg52, arg53, arg54, arg55, arg56, arg57, arg58, arg59, arg60, \ | 
|---|
 | 90 |     arg61, arg62, arg63, argn, ...) argn | 
|---|
 | 91 |  | 
|---|
 | 92 | #define ORXONOX_VA_NARGS_NUMBERS \ | 
|---|
 | 93 |     63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, \ | 
|---|
 | 94 |     47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, \ | 
|---|
 | 95 |     31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, \ | 
|---|
 | 96 |     15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0 | 
|---|