我有不同版本的基本功能void *_function()
:void *_function_standard()
,*_function_secure()
,*_function_fast()
我想定义MACROS接口,以便能够选择要调用的函数以及对返回值执行的操作,例如转换,调用FUNCTION_TYPE_MODE()
,而不是冗余地定义每个选项。
我想避免的事情:
#define F_CHAR (unsigned char *) _function_standard()
#define F_CHAR_FAST (unsigned char *) _function_fast()
#define F_CHAR_SECURE (unsigned char *) _function_secure()
#define F_SCHAR (signed char *) _function_standard()
#define F_SCHAR_FAST (signed char *) _function_fast()
#define F_SCHAR_SECURE (signed char *) _function_secure()
#define F_CHARPNT (unsigned char **) _function_standard()
#define F_CHARPNT_FAST (unsigned char **) _function_fast()
#define F_CHARPNT_SECURE (unsigned char **) _function_secure()
#define F_SHORT (unsigned short int *) _function_standard()
#define F_SHORT_FAST (unsigned short int *) _function_fast()
#define F_SHORT_SECURE (unsigned short int *) _function_secure()
#define F_INT (unsigned int *) _function_standard()
#define F_INT_FAST (unsigned int *) _function_fast()
#define F_INT_SECURE (unsigned int *) _function_secure()
如果我必须处理大量不同类型的数据和超过2/3的模式(STANDARD,SECURE,FAST),这可能会成为一个问题。
而我需要的是定义MACROS让我调用FUNCTION_TYPE_MODE中的函数,只定义一次corrisponeces _FAST - > _function_fast(),_SECURE - > _function_secure()和类型之间。
F_SHORT() -> (unsigned short int *) _function_standard()
F_SHORT_FAST() -> (unsigned short int *) _function_fast()
F_CHAR_SECURE() -> (unsigned char *) _function_secure()
...
我想定义DEFAULT_TYPE
和DEFAULT_MODE
,因此我可以为F()
致电(DEFAULT TYPE) _function/?fast()
。
我看了Combining two #defined symbols in C++ preprocessor,但我还没有理解如何使用FUNC_TYPE_MODE
形式而不是FUNC(TYPE, MODE)
形式。
连连呢? : - )