diff --git a/m-core.h b/m-core.h index 101315cd..b18d95c4 100644 --- a/m-core.h +++ b/m-core.h @@ -984,10 +984,18 @@ m_core_hash (const void *str, size_t length) #define M_OPEXTEND(op, ...) (__VA_ARGS__, M_OPFLAT op) /* Test if a method is present in an oplist. - Return 0 or 1 */ -#define M_TEST_METHOD_P(method, oplist) \ + Return 0 (method is absent or disabled) or 1 (method is present and not disabled) */ +#define M_TEST_METHOD_P(method, oplist) \ M_BOOL(M_GET_METHOD (method, 0, M_OPFLAT oplist)) +/* Test if a method is disabled in an oplist. + To disable an oplist, just put '0' in the method like this: + Example: (INIT(0), CLEAR(clear)) + Here INIT is disabled, whereas CLEAR is not. + Return 1 (method is disabled) or 0 (method is not disabled - absent or present) */ +#define M_TEST_DISABLED_METHOD_P(method, oplist) \ + M_INV(M_BOOL(M_GET_METHOD (method, 1, M_OPFLAT oplist))) + /* Perfom a preprocessing M_IF, if the method is present in the oplist. Example: M_IF_METHOD(HASH, oplist)(define function with HASH method, ) */ #define M_IF_METHOD(method, oplist) M_IF(M_TEST_METHOD_P(method, oplist)) diff --git a/tests/test-mcore.c b/tests/test-mcore.c index 65f71083..90a5c265 100644 --- a/tests/test-mcore.c +++ b/tests/test-mcore.c @@ -233,6 +233,12 @@ static void test_oplist(void) assert (!M_OPLIST_P()); assert (!M_OPLIST_P((()))); assert (!M_OPLIST_P(INIT(init))); + +#define a (INIT(0), CLEAR(clear)) + assert (M_TEST_DISABLED_METHOD_P(INIT, a)); + assert (!M_TEST_DISABLED_METHOD_P(INIT2, a)); + assert (!M_TEST_DISABLED_METHOD_P(CLEAR, a)); + assert (!M_TEST_DISABLED_METHOD_P(INIT, ())); } static void test_cast(void)