Add macros
FUNC_OBJ_ITF_DEF_AS FUNC_OBJ_INS_DEF_AS
This commit is contained in:
1 parent
affb3778a0
commit
8340cf70fb
2 files changed
+45
-1
No files matched your search
+25
-1
@@ -38,6 +38,17 @@
|
||||
M_END_PROTECTED_CODE
|
||||
|
||||
|
||||
/* Define a function object interface of name 'name'
|
||||
* as the given name name_t
|
||||
* USAGE:
|
||||
* FUNC_OBJ_ITF_DEF_AS(name, name_t, retcode type, type of param1, type of param 2, ...)
|
||||
*/
|
||||
#define FUNC_OBJ_ITF_DEF_AS(name, name_t, ...) \
|
||||
M_BEGIN_PROTECTED_CODE \
|
||||
M_IF_NARGS_EQ1(__VA_ARGS__)(FUNCOBJI_ITF_NO_PARAM_DEF, FUNCOBJI_ITF_PARAM_DEF)(name, name_t, __VA_ARGS__) \
|
||||
M_END_PROTECTED_CODE
|
||||
|
||||
|
||||
/* Define a function object instance of name 'name' based on the interface 'base_name'
|
||||
* The function is defined as per :
|
||||
* - the prototype of the inherited interface
|
||||
@@ -62,6 +73,19 @@
|
||||
M_END_PROTECTED_CODE
|
||||
|
||||
|
||||
/* Define a function object instance of name 'name' based on the interface 'base_name'
|
||||
* as the given name name_t.
|
||||
* See FUNC_OBJ_INS_DEF for additional details.
|
||||
*
|
||||
* USAGE/EXAMPLE:
|
||||
* FUNC_OBJ_INS_DEF_AS(name, name_t, base_name, (param1, ...), { return param1 * self->member1 }, (member1, int), ...)
|
||||
*/
|
||||
#define FUNC_OBJ_INS_DEF_AS(name, name_t, base_name, param_list, ...) \
|
||||
M_BEGIN_PROTECTED_CODE \
|
||||
M_IF_NARGS_EQ1(__VA_ARGS__)(FUNCOBJI_INS_NO_ATTR_DEF, FUNCOBJI_INS_ATTR_DEF)(name, name_t, base_name, param_list, __VA_ARGS__) \
|
||||
M_END_PROTECTED_CODE
|
||||
|
||||
|
||||
/* OPLIST of the instanced function object
|
||||
* USAGE:
|
||||
* FUNC_OBJ_INS_OPLIST(name, oplist of the attr1, ...)
|
||||
@@ -282,7 +306,7 @@
|
||||
FUNCOBJI_CONTROL_ALL_OPLIST(name, __VA_ARGS__) \
|
||||
\
|
||||
static inline M_C(base_name, _retcode_ct) \
|
||||
M_C(name, _callback)(M_C(base_name, _t) _self \
|
||||
M_C(name, _callback)(M_C(base_name, _ct) _self \
|
||||
M_IF_EMPTY(M_OPFLAT param_list)( \
|
||||
/* No param */, \
|
||||
M_MAP3(FUNCOBJI_INS_ARGLIST, base_name, M_OPFLAT param_list)\
|
||||
|
||||
@@ -69,6 +69,17 @@ END_COVERAGE
|
||||
|
||||
#define M_OPL_instance22_t() FUNC_OBJ_INS_OPLIST(instance22, M_DEFAULT_OPLIST)
|
||||
|
||||
FUNC_OBJ_ITF_DEF_AS(Interface, Interface, double, double)
|
||||
|
||||
FUNC_OBJ_INS_DEF_AS(Instance, Instance,
|
||||
Interface,
|
||||
(a), {
|
||||
return a * self->a + self->b;
|
||||
},
|
||||
(a, double),
|
||||
(b, double) )
|
||||
#define M_OPL_Instance() FUNC_OBJ_INS_OPLIST(Instance, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
|
||||
|
||||
static void test_instance11(void)
|
||||
{
|
||||
instance11_t cmp;
|
||||
@@ -117,11 +128,20 @@ static void test_instance22(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void test_double(void)
|
||||
{
|
||||
M_LET( (func, 2.0, 3.0), Instance) {
|
||||
double d = Interface_call(Instance_as_interface(func), 4.0);
|
||||
assert (d == 2.0 * 4.0 + 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_instance11();
|
||||
test_instance12();
|
||||
test_instance21();
|
||||
test_instance22();
|
||||
test_double();
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user