ZFFramework
 
Loading...
Searching...
No Matches
ZFCoreUtilMacro.h File Reference

macro utils More...

#include "ZFCoreTypeDef.h"

Go to the source code of this file.

Macros

#define ZFBitTest(var, bit)
 macro to detect whether bit is set, zftrue if any one of test bit has set
 
#define ZFBitTestAll(var, bit)
 macro to detect whether bit is set, zftrue only if all the bits in bit is set
 
#define ZFBitGet(var, bit)
 macro to get the value at bit
 
#define ZFBitSet(var, bit)
 macro to set at bit
 
#define ZFBitUnset(var, bit)
 clear at bit
 
#define ZF_HINT(...)
 dummy macro to show a hint
 
#define ZFM_REPEAT(N, Type, LeftCommaFix, CenterCommaFix)
 macro to repeat something
 
#define ZFM_REPEAT_TEMPLATE(N)
 usually used by ZFM_REPEAT
 
#define ZFM_REPEAT_TYPE(N)
 usually used by ZFM_REPEAT
 
#define ZFM_REPEAT_TYPE_CONST(N)
 usually used by ZFM_REPEAT
 
#define ZFM_REPEAT_NAME(N)
 usually used by ZFM_REPEAT
 
#define ZFM_REPEAT_PARAM(N)
 usually used by ZFM_REPEAT
 
#define ZFM_BRACKET_L()
 macro to (
 
#define ZFM_BRACKET_R()
 macro to )
 
#define ZFM_EMPTY(...)
 macro to s space
 
#define ZFM_COMMA()
 macro to a comma
 
#define ZFM_EXPAND(...)
 macro to expand a macro
 
#define ZFM_CAT(a, b)
 expand a and b, then concatenate to ab
 
#define ZFM_TOSTRING(a)
 convert macro to string
 
#define ZFM_N_INC(n)
 increase n by macro expand
 
#define ZFM_N_DEC(n)
 decrease n by macro expand
 
#define ZFM_PARAM_NUM(...)
 get the param num of a certain sequence
 
#define ZFM_FIX_PARAM(ParamFix, commaFix, ...)
 fix each param in the VA_ARGS
 
#define ZFM_VA_APPEND(ToExpand, ToAppend, ...)
 util to appending item after VA_ARGS
 
#define zfidentityHash(hash, ...)
 util method to connect multiple hash value into one hash value
 
#define ZFUNUSED(v)
 explicit declare v is not used
 
#define ZFM_ARRAY_SIZE(array)
 calculate the size of an array
 
#define ZFUniqueName(name)
 declare a unique name
 
#define ZFM_CLASS_HAS_MEMBER_DECLARE(NameSpace, memberName, memberSig)
 util macro to check whether class has desired member function, for advanced use only
 
#define ZFM_CLASS_HAS_MEMBER(NameSpace, memberName, ClassToCheck)
 see ZFM_CLASS_HAS_MEMBER_DECLARE
 
#define ZFCORE_PARAM_DECLARE_SELF(T_self)
 see ZFCORE_PARAM
 
#define ZFCORE_PARAM(T_ParamType, paramName, ...)
 a util macro to generate setter and getter for POD like object
 

Detailed Description

macro utils

Macro Definition Documentation

◆ ZF_HINT

#define ZF_HINT ( ...)

dummy macro to show a hint

used to make some code more human readable, no actual use
for example, add to function call's param list to make params more readable:

void yourFunc(zfbool clickable, zfbool moveable) {...}
...
yourFunc(
ZF_HINT("clickable?")zftrue,
ZF_HINT("moveable?")zffalse);
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define ZF_HINT(...)
dummy macro to show a hint
Definition ZFCoreUtilMacro.h:48

◆ ZFM_REPEAT

#define ZFM_REPEAT ( N,
Type,
LeftCommaFix,
CenterCommaFix )

macro to repeat something

for example
ZFM_REPEAT(2, ZFM_REPEAT_TEMPLATE, ZFM_EMPTY, ZFM_COMMA)
would be expand as:
typename Type0, typename Type1
and ZFM_REPEAT(3, ZFM_REPEAT_PARAM, ZFM_COMMA, ZFM_COMMA)
would be expand as:
, Type0 param0, Type1 param1, Type2 param2

◆ ZFM_PARAM_NUM

#define ZFM_PARAM_NUM ( ...)

get the param num of a certain sequence

usage:

#define _EMPTY
zfindex n = 0;
n = ZFM_PARAM_NUM(a, b, c); // n would be 3
n = ZFM_PARAM_NUM(_EMPTY); // n would be 1
n = ZFM_PARAM_NUM(); // result not ensured, may be 0 or 1
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define ZFM_PARAM_NUM(...)
get the param num of a certain sequence
Definition ZFCoreUtilMacro.h:254

this macro could calculate 1 ~ 32 param num

◆ ZFM_FIX_PARAM

#define ZFM_FIX_PARAM ( ParamFix,
commaFix,
... )

fix each param in the VA_ARGS

usage:

// define your own expand method
#define EXPAND(arg) #arg " "
// result is:
// "1" " " "2" " " "3" " "
// which is same as:
// "1 2 3 "
ZFM_FIX_PARAM(EXPAND, ZFM_EMPTY, 1, 2, 3)
#define ZFM_FIX_PARAM(ParamFix, commaFix,...)
fix each param in the VA_ARGS
Definition ZFCoreUtilMacro.h:278
#define ZFM_EMPTY(...)
macro to s space
Definition ZFCoreUtilMacro.h:139

◆ ZFUniqueName

#define ZFUniqueName ( name)

declare a unique name

typical usage:

// assume this line is line 1
int ZFUniqueName(a) = 0; // same as "int _ZFP_zUniqueName_a_2 = 0;"
int ZFUniqueName(a) = 0; // same as "int _ZFP_zUniqueName_a_3 = 0;"
#define ZFUniqueName(name)
declare a unique name
Definition ZFCoreUtilMacro.h:435

this is usually used to declare a tmp variable, such as:

class MyClass {
public:
zfbool flag;
MyClass() : flag(zftrue) {}
};
#define MyClassBlock for(MyClass ZFUniqueName(cls); \\
ZFUniqueName(cls).flag; \\
ZFUniqueName(cls).flag = zffalse)
// to use the blocked code
MyClassBlock {
// code block
// there'll be a instance of MyClass named _ZFP_zUniqueName_cls_123
} // and the MyClass's instance will be deconstructed after the brace

REMARKS:
when used under Windows with embeded macros

#define ZFM_EXPAND(...)
macro to expand a macro
Definition ZFCoreUtilMacro.h:148

a C2065 "__LINE__Var undeclared identifier" may (or may not) occurred
this is a compiler bug
to solve it, turn "Program Database for edit and continue (/ZI)" to "Program Database (/Zi)" in your project setting
or, prevent use it within other macros

◆ ZFM_CLASS_HAS_MEMBER_DECLARE

#define ZFM_CLASS_HAS_MEMBER_DECLARE ( NameSpace,
memberName,
memberSig )

util macro to check whether class has desired member function, for advanced use only

usage:

// declare before use
YourNamespace, // namespace for avoid conflict
yourMemberName, // member method name to check
void (T::*F)(void) // member sig (T and F is reserved keyword for class and member type)
)
// once declared, you may check like this
// value would be true only if "ClassToCheck" has such member method:
// void ClassToCheck::yourMethodName(void); // can be static or virtual
zfbool value = ZFM_CLASS_HAS_MEMBER(YourNamespace, yourMethodName, ClassToCheck);
// typical method sig:
static void func(void)
: void (*F)(void)
virtual void func(void)
: void (T::*F)(void)
void func(void) const
: void (T::*F)(void) const
#define ZFM_CLASS_HAS_MEMBER_DECLARE(NameSpace, memberName, memberSig)
util macro to check whether class has desired member function, for advanced use only
Definition ZFCoreUtilMacro.h:473
#define ZFM_CLASS_HAS_MEMBER(NameSpace, memberName, ClassToCheck)
see ZFM_CLASS_HAS_MEMBER_DECLARE
Definition ZFCoreUtilMacro.h:488

limitations:

  • for static member methods, if parent have, then child type would also have, no way to check whether only child have
  • for non-public methods, the ZFM_CLASS_HAS_MEMBER_DECLARE must be declared in class scope to take effect

◆ ZFCORE_PARAM

#define ZFCORE_PARAM ( T_ParamType,
paramName,
... )

a util macro to generate setter and getter for POD like object

usage:

zfclassLikePOD YourType {
protected:
// declare self is required
/ **
* @ brief you can add Doxygen docs here
* /
ZFCORE_PARAM(YourType, YourParamType, paramName)
};
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZFCORE_PARAM_DECLARE_SELF(T_self)
see ZFCORE_PARAM
Definition ZFCoreUtilMacro.h:495
#define ZFCORE_PARAM(T_ParamType, paramName,...)
a util macro to generate setter and getter for POD like object
Definition ZFCoreUtilMacro.h:523

once declared, you can access your param by the generated getter and setter

YourType v;
v.paramName(someValue);
YourParamType paramValue = v.paramName();