Merge pull request #14 from oatpp/issue_13_codegen

portable 'OATPP_MACRO_HAS_ARGS'
This commit is contained in:
Leonid Stryzhevskyi 2018-10-15 05:37:58 +03:00 committed by GitHub
commit 63ce57cc12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,44 @@ ENV::log("macro", "param: %d/%d: '%s'", INDEX, COUNT, #X);
#define OATPP_MACRO_HAS_ARGS_ARR(...) OATPP_MACRO__NUM_ARGS(__VA_ARGS__, true, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
//////////////////////////////////////////////////////////////////////////////////////////////////
// BEGIN(Detect empty macro)
// Please note:
// this code is taken from
// https://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments/
//////////////////////////////////////////////////////////////////////////////////////////////////
// #define OATPP_MACRO_HAS_ARGS(...) OATPP_MACRO_HAS_ARGS_ARR(L, ##__VA_ARGS__)
#define OATPP_MACRO_TRIGGER_PARENTHESIS_(...) ,
#define OATPP_MACRO_ISEMPTY(...) \
OATPP_MACRO_ISEMPTY_( \
/* test if there is just one argument, eventually an empty one */ \
OATPP_MACRO_HAS_ARGS_ARR(__VA_ARGS__), \
/* test if OATPP_MACRO_TRIGGER_PARENTHESIS_ together with the argument adds a comma */ \
OATPP_MACRO_HAS_ARGS_ARR(OATPP_MACRO_TRIGGER_PARENTHESIS_ __VA_ARGS__), \
/* test if the argument together with a parenthesis adds a comma */ \
OATPP_MACRO_HAS_ARGS_ARR(__VA_ARGS__ (/*empty*/)), \
/* test if placing it between OATPP_MACRO_TRIGGER_PARENTHESIS_ and the parenthesis adds a comma */ \
OATPP_MACRO_HAS_ARGS_ARR(OATPP_MACRO_TRIGGER_PARENTHESIS_ __VA_ARGS__ (/*empty*/)) \
)
#define OATPP_MACRO_PASTE5(_0, _1, _2, _3, _4) _0 ## _1 ## _2 ## _3 ## _4
#define OATPP_MACRO_ISEMPTY_(_0, _1, _2, _3) OATPP_MACRO_HAS_ARGS_ARR(OATPP_MACRO_PASTE5(OATPP_MACRO_IS_EMPTY_CASE_, _0, _1, _2, _3))
#define OATPP_MACRO_IS_EMPTY_CASE_0001 ,
#define OATPP_MACRO_HAS_ARGS_NOT_1 0
#define OATPP_MACRO_HAS_ARGS_NOT_0 1
#define OATPP_MACRO_HAS_ARGS__(X) OATPP_MACRO_HAS_ARGS_NOT_ ## X
#define OATPP_MACRO_HAS_ARGS_(X) OATPP_MACRO_HAS_ARGS__(X)
#define OATPP_MACRO_HAS_ARGS(...) OATPP_MACRO_HAS_ARGS_(OATPP_MACRO_ISEMPTY(__VA_ARGS__))
//////////////////////////////////////////////////////////////////////////////////////////////////
// END(Detect empty macro)
//////////////////////////////////////////////////////////////////////////////////////////////////
#define OATPP_MACRO_CONCAT(X,Y) OATPP_MACRO_CONCAT(X,Y)
#define OATPP_MACRO_CONCAT2(X,Y) X##Y
#define OATPP_MACRO_CONCAT_2 OATPP_MACRO_CONCAT
@ -44,8 +82,6 @@ ENV::log("macro", "param: %d/%d: '%s'", INDEX, COUNT, #X);
#define OATPP_MACRO_STR(X) #X
#define OATPP_MACRO_HAS_ARGS(...) OATPP_MACRO_HAS_ARGS_ARR(L, ##__VA_ARGS__)
#define OATPP_MACRO_EXPAND(X) X
#define OATPP_MACRO_FIRSTARG(X, ...) X
#define OATPP_MACRO_FIRSTARG_STR(X, ...) #X