6#ifndef _ZFI_ZFObjectInterface_h_
7#define _ZFI_ZFObjectInterface_h_
20#define zfinterface class
24#define zfimplement public
29 virtual ~_ZFP_ObjI_Base(
void) {}
34 static void _ZFP_Obj_initImpl(
ZFClass *cls) {}
36 static void _ZFP_ObjI_ICk(
void) {}
38#define _ZFP_ZFINTERFACE_DECLARE(InterfaceName, ParentInterface, OuterClass, ...) \
39 ZFCLASS_DISALLOW_COPY_CONSTRUCTOR(InterfaceName) \
41 static void _ZFP_zftIsZFObject(void) {} \
42 static void _ZFP_zftIsZFInterface(void) {} \
45 typedef ParentInterface zfsuper; \
47 typedef InterfaceName zfself; \
49 static void _ZFP_Obj_initImplCk(ZF_IN ZFClass *cls) { \
50 if(cls->_ZFP_ZFClass_implListNeedInit) { \
51 cls->_ZFP_ZFClass_implListNeedInit = zffalse; \
52 if(zfself::_ZFP_Obj_initImpl != zfsuper::_ZFP_Obj_initImpl) { \
53 zfself::_ZFP_Obj_initImpl(cls); \
59 static const ZFClass *ClassData(void) { \
60 static _ZFP_ZFClassRegisterHolder _holder( \
61 ZF_NAMESPACE_CURRENT(), \
62 zftext(#InterfaceName), \
63 ParentInterface::ClassData(), \
64 OuterClass::ClassData(), \
69 &zfself::_ZFP_Obj_initImplCk, \
75 virtual void _ZFP_ObjI_ICk(void) { \
77 _ZFP_ObjI_Base::_ZFP_ObjI_ICk(); \
81 template<typename T_ZFObject> \
82 inline T_ZFObject to(void) { \
83 return zfcast(T_ZFObject, this); \
94#define ZFINTERFACE_DECLARE_WITH_CUSTOM_CTOR(InterfaceName, ParentInterface, ...) \
95 ZFM_VA_APPEND(_ZFP_ZFINTERFACE_DECLARE, _ZFP_ObjI_Base, InterfaceName, ParentInterface, ##__VA_ARGS__) \
100#define ZFINTERFACE_DECLARE(InterfaceName, ParentInterface, ...) \
101 ZFM_VA_APPEND(_ZFP_ZFINTERFACE_DECLARE, _ZFP_ObjI_Base, InterfaceName, ParentInterface, ##__VA_ARGS__) \
104 InterfaceName(void) {} \
105 virtual ~InterfaceName(void) {} \
109template<
typename T_FromZFObjectOrZFInterface,
typename T_ToZFInterface,
int isFromInterface>
112template<
typename T_FromZFObjectOrZFInterface,
typename T_ToZFInterface>
113zfclassNotPOD _ZFP_ObjICW<T_FromZFObjectOrZFInterface, T_ToZFInterface, 0> {
116 return (T_ToZFInterface *)
zfcast(T_FromZFObjectOrZFInterface *, obj);
119template<
typename T_FromZFObjectOrZFInterface,
typename T_ToZFInterface>
120zfclassNotPOD _ZFP_ObjICW<T_FromZFObjectOrZFInterface, T_ToZFInterface, 1> {
122 template<
typename T_ZFObject>
124 return zfcast(T_ToZFInterface *, obj->toObject());
127template<
typename T_FromZFObjectOrZFInterface>
128zfclassNotPOD _ZFP_ObjICW<T_FromZFObjectOrZFInterface, ZFInterface, 0> {
130 template<
typename T_ZFObject>
135template<
typename T_FromZFObjectOrZFInterface>
136zfclassNotPOD _ZFP_ObjICW<T_FromZFObjectOrZFInterface, ZFInterface, 1> {
138 template<
typename T_ZFObject>
143#define _ZFP_ZFIMPLEMENT_DECLARE_EXPAND_PARAM(Interface) \
144 , Interface::ClassData(), &zfself::_ZFP_ObjICCb_##Interface
145#define _ZFP_ZFIMPLEMENT_DECLARE_EXPAND_CAST_CALLBACK(Interface) \
146 static ZFInterface *_ZFP_ObjICCb_##Interface(ZF_IN ZFObject *obj) { \
147 return _ZFP_ObjICW<zfself, Interface, (zftIsTypeOf<zfself, ZFObject>::Value ? 0 : 1)>::_ZFP_cast(obj); \
149#define _ZFP_ZFIMPLEMENT_DECLARE_EXPAND_INTERFACE_ON_INIT(Interface) \
150 Interface::_ZFP_ObjI_onInit();
151#define _ZFP_ZFIMPLEMENT_DECLARE_EXPAND_INTERFACE_ON_DEALLOC(Interface) \
152 Interface::_ZFP_ObjI_onDealloc();
153#define _ZFP_ZFIMPLEMENT_DECLARE(ImplementedInterfaces, ...) \
155 static void _ZFP_Obj_initImpl(ZFClass *cls) { \
156 if(cls->_ZFP_ZFClass_interfaceNeedRegister()) { \
157 cls->_ZFP_ZFClass_interfaceRegister(0 \
158 ZFM_FIX_PARAM(_ZFP_ZFIMPLEMENT_DECLARE_EXPAND_PARAM, ZFM_EMPTY, ImplementedInterfaces, ##__VA_ARGS__) \
159 , (const ZFClass *)zfnull \
164 ZFM_FIX_PARAM(_ZFP_ZFIMPLEMENT_DECLARE_EXPAND_CAST_CALLBACK, ZFM_EMPTY, ImplementedInterfaces, ##__VA_ARGS__) \
169#define ZFIMPLEMENT_DECLARE(ImplementedInterfaces, ...) \
170 _ZFP_ZFIMPLEMENT_DECLARE(ImplementedInterfaces, ##__VA_ARGS__) \
172 virtual inline void _ZFP_ObjI_onInitIvk(void) { \
173 zfsuper::_ZFP_ObjI_onInitIvk(); \
174 ZFM_FIX_PARAM(_ZFP_ZFIMPLEMENT_DECLARE_EXPAND_INTERFACE_ON_INIT, ZFM_EMPTY, ImplementedInterfaces, ##__VA_ARGS__) \
176 virtual inline void _ZFP_ObjI_onDeallocIvk(void) { \
177 ZFM_FIX_PARAM(_ZFP_ZFIMPLEMENT_DECLARE_EXPAND_INTERFACE_ON_DEALLOC, ZFM_EMPTY, ImplementedInterfaces, ##__VA_ARGS__) \
178 zfsuper::_ZFP_ObjI_onDeallocIvk(); \
251 _ZFP_ZFINTERFACE_DECLARE(ZFInterface, _ZFP_ObjI_Base, _ZFP_ObjI_Base)
260 static void _ZFP_Obj_initImpl(
ZFClass *cls) {}
261 zffinal inline void _ZFP_ObjI_onInit(
void) {}
262 zffinal inline void _ZFP_ObjI_onDealloc(
void) {}
290#define ZFINTERFACE_ON_INIT_DECLARE() \
292 zffinal void _ZFP_ObjI_onInit(void)
294#define ZFINTERFACE_ON_INIT_DEFINE(YourInterface) \
295 void YourInterface::_ZFP_ObjI_onInit(void)
298#define ZFINTERFACE_ON_DEALLOC_DECLARE() \
300 zffinal void _ZFP_ObjI_onDealloc(void)
302#define ZFINTERFACE_ON_DEALLOC_DEFINE(YourInterface) \
303 void YourInterface::_ZFP_ObjI_onDealloc(void)
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfpurevirtual
dummy macro shows that a method is pure virtual method
Definition ZFCoreTypeDef_ClassType.h:68
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition ZFObjectCast.h:28
#define zfinterface
shows the type is an interface, see ZFInterface
Definition ZFObjectInterface.h:20
ZFObject's class info.
Definition ZFClass.h:67
dummy base of interface types
Definition ZFObjectInterface.h:250
virtual ZFObject * toObject(void)=0
convert to ZFObject type
virtual const ZFClass * classData(void)=0
get instance's class info
base class of all objects
Definition ZFObjectCore.h:209
util class to cast ZFObject types freely