From d1fecbf9512471ad2bb0ab46cd931a37c7cdc2d5 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Mon, 6 Feb 2012 10:43:59 +0100 Subject: [PATCH] add ability to call interface methods with return value --- include/class.h | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/include/class.h b/include/class.h index 3ab436b..3af41c5 100644 --- a/include/class.h +++ b/include/class.h @@ -40,19 +40,28 @@ * @TODO: actually i use gcc feature ## for variadoc... think about * a way to make this standard. */ -#define CALL(object,_iface,method,...) \ - do { \ - class_ptr class = class_getClass((object)); \ - struct i_##_iface * iface; \ - if (class->init) class->init(); \ - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ - while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \ - class = class->parent; \ - if (class->init) class->init(); \ - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ - }; \ - assert(NULL != iface->method); \ - iface->method(object, ##__VA_ARGS__); \ +#define _CALL(object,_iface,method,...) \ + class_ptr class = class_getClass((object)); \ + struct i_##_iface * iface; \ + if (class->init) class->init(); \ + iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ + while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \ + class = class->parent; \ + if (class->init) class->init(); \ + iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ + }; \ + assert(NULL != iface->method); + +#define CALL(object,_iface,method,...) \ + do { \ + _CALL(object, _iface, method, ##__VA_ARGS__); \ + iface->method(object, ##__VA_ARGS__); \ + } while(0) + +#define RETCALL(object,_iface,method,ret,...) \ + do { \ + _CALL(object, _iface, method, ##__VA_ARGS__); \ + ret = iface->method(object, ##__VA_ARGS__); \ } while(0)