ZFFramework
Loading...
Searching...
No Matches
ZFCoreStaticInitializer.h
Go to the documentation of this file.
1
5#ifndef _ZFI_ZFCoreStaticInitializer_h_
6#define _ZFI_ZFCoreStaticInitializer_h_
7
9
11
12// ============================================================
13typedef void *(*_ZFP_SI_Constructor)(void);
14typedef void (*_ZFP_SI_Destructor)(ZF_IN void *p);
15zfclassLikePOD ZFLIB_ZFCore _ZFP_SI_Holder {
16public:
17 _ZFP_SI_Holder(
18 ZF_IN const zfstring &name
19 , ZF_IN _ZFP_SI_Constructor constructor
20 , ZF_IN _ZFP_SI_Destructor destructor
21 );
22 ~_ZFP_SI_Holder(void);
23public:
24 void *instance;
25};
26
27// ============================================================
60#define ZF_STATIC_INITIALIZER_INIT(Name) \
61 zfclassNotPOD _ZFP_SI_##Name { \
62 protected: \
63 typedef _ZFP_SI_##Name zfself; \
64 public: \
65 static void *_ZFP_SI_ctor_##Name(void) { \
66 static zfbyte d[sizeof(_ZFP_SI_##Name)]; \
67 return (void *)zfnewPlacement(d, _ZFP_SI_##Name); \
68 } \
69 static void _ZFP_SI_dtor_##Name(ZF_IN void *p) { \
70 zfdeletePlacement((_ZFP_SI_##Name *)p); \
71 } \
72 static _ZFP_SI_##Name *_ZFP_SI_I(void) { \
73 static _ZFP_SI_Holder d(zftext(#Name), \
74 _ZFP_SI_##Name::_ZFP_SI_ctor_##Name, \
75 _ZFP_SI_##Name::_ZFP_SI_dtor_##Name); \
76 return (_ZFP_SI_##Name *)d.instance; \
77 } \
78 public: \
79 _ZFP_SI_##Name(void)
80
83#define ZF_STATIC_INITIALIZER_DESTROY(Name) \
84 ~_ZFP_SI_##Name(void)
85
88#define ZF_STATIC_INITIALIZER_END(Name) \
89 }; \
90 ZF_STATIC_REGISTER_INIT(SI_##Name) { \
91 _ZFP_SI_##Name::_ZFP_SI_I(); \
92 } \
93 ZF_STATIC_REGISTER_END(SI_##Name)
94
97#define ZF_STATIC_INITIALIZER_INSTANCE(Name) \
98 (_ZFP_SI_##Name::_ZFP_SI_I())
99
100#define _ZFP_ZF_STATIC_INITIALIZER_CLASS(Name) \
101 _ZFP_SI_##Name
105#define ZF_STATIC_INITIALIZER_CLASS(Name) \
106 _ZFP_ZF_STATIC_INITIALIZER_CLASS(Name)
107
109#endif // #ifndef _ZFI_ZFCoreStaticInitializer_h_
110
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
static register util
#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 ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:184
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98