ZFFramework
 
Loading...
Searching...
No Matches
ZFIdMap.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFIdMap_h_
7#define _ZFI_ZFIdMap_h_
8
9#include "../ZFCoreDef.h"
10
12
14
15// ============================================================
16extern ZFLIB_ZFCore const zfidentity *_ZFP_ZFIdMapRegister(
17 ZF_IN const zfstring &idName
18 , ZF_IN_OPT zfbool isDynamicRegister = zffalse
19 );
20extern ZFLIB_ZFCore void _ZFP_ZFIdMapUnregister(
21 ZF_IN zfidentity idValue
22 , ZF_IN_OPT zfbool isDynamicRegister = zffalse
23 );
38
48 );
57
63 return ret;
64}
65
79
80zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFIdMapHolder {
81public:
82 _ZFP_ZFIdMapHolder(
83 ZF_IN const zfstring &idName
84 , ZF_IN const ZFClass *ownerClass
85 , ZF_IN const zfstring &ownerNamespace
86 , ZF_IN const zfstring &methodName
87 );
88 ~_ZFP_ZFIdMapHolder(void);
89
90public:
91 const zfidentity *idValue;
92};
123#define ZFIDMAP(YourIdName) \
124 ZFIDMAP_DETAIL(Id, YourIdName)
125
126#define ZFIDMAP_DETAIL(prefix, YourIdName) \
127 public: \
128 \
129 static zfidentity prefix##YourIdName(void);
130
137#define ZFIDMAP_INLINE(YourIdName) \
138 ZFIDMAP_DETAIL_INLINE(Id, YourIdName)
139
140#define ZFIDMAP_DETAIL_INLINE(prefix, YourIdName) \
141 private: \
142 zfclassNotPOD _ZFP_IdMapReg_##prefix##YourIdName { \
143 public: \
144 _ZFP_IdMapReg_##prefix##YourIdName(void) { \
145 zfself::prefix##YourIdName(); \
146 } \
147 } _ZFP_IdMap_##prefix##YourIdName; \
148 public: \
149 static zfidentity prefix##YourIdName(void) { \
150 static _ZFP_ZFIdMapHolder d( \
151 zfstr("%s.%s", zfself::ClassData()->classNameFull(), ZFM_TOSTRING(prefix##YourIdName)) \
152 , zfself::ClassData() \
153 , zfnull \
154 , zftext(ZFM_TOSTRING(prefix##YourIdName)) \
155 ); \
156 return *(d.idValue); \
157 }
158
177#define ZFIDMAP_GLOBAL(ZFLIB_, YourIdName) \
178 ZFIDMAP_GLOBAL_DETAIL(ZFLIB_, Id, YourIdName)
179
180#define ZFIDMAP_GLOBAL_DETAIL(ZFLIB_, prefix, YourIdName) \
181 \
182 extern ZFLIB_ zfidentity prefix##YourIdName(void);
183
185#define ZFIDMAP_REGISTER(Scope, YourIdName) \
186 ZFIDMAP_REGISTER_DETAIL(Scope, Id, YourIdName)
187
188#define ZFIDMAP_REGISTER_DETAIL(Scope, prefix, YourIdName) \
189 zfidentity Scope::prefix##YourIdName(void) { \
190 static _ZFP_ZFIdMapHolder d( \
191 zfstr("%s.%s", zfself::ClassData()->classNameFull(), ZFM_TOSTRING(prefix##YourIdName)) \
192 , zfself::ClassData() \
193 , zfnull \
194 , zftext(ZFM_TOSTRING(prefix##YourIdName)) \
195 ); \
196 return *(d.idValue); \
197 } \
198 ZF_STATIC_REGISTER_INIT(ZFIdMap_##Scope##_##YourIdName) { \
199 (void)Scope::prefix##YourIdName(); \
200 } \
201 ZF_STATIC_REGISTER_END(ZFIdMap_##Scope##_##YourIdName)
202
204#define ZFIDMAP_GLOBAL_REGISTER(YourIdName) \
205 ZFIDMAP_GLOBAL_REGISTER_DETAIL(Id, YourIdName)
206
207#define ZFIDMAP_GLOBAL_REGISTER_DETAIL(prefix, YourIdName) \
208 zfidentity prefix##YourIdName(void) { \
209 static _ZFP_ZFIdMapHolder d( \
210 zfstr("%s.%s", ZF_NAMESPACE_CURRENT() ? ZF_NAMESPACE_CURRENT() : "", ZFM_TOSTRING(prefix##YourIdName)) \
211 , zfnull \
212 , ZF_NAMESPACE_CURRENT() \
213 , zftext(ZFM_TOSTRING(prefix##YourIdName)) \
214 ); \
215 return *(d.idValue); \
216 } \
217 ZF_STATIC_REGISTER_INIT(ZFIdMap_##YourIdName) { \
218 (void)prefix##YourIdName(); \
219 } \
220 ZF_STATIC_REGISTER_END(ZFIdMap_##YourIdName) \
221
223#endif // #ifndef _ZFI_ZFIdMap_h_
224
necessary header file for all types
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#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:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:225
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
ZFCoreArray< zfstring > ZFIdMapGetAllName(void)
see ZFIdMapGetAll
Definition ZFIdMap.h:60
void ZFIdMapGetAll(ZFCoreArray< zfidentity > &idValues, ZFCoreArray< zfstring > &idNames)
see ZFIDMAP
void ZFIdMapGetAllNameT(ZFCoreArray< zfstring > &idNames)
see ZFIdMapGetAll
void ZFIdMapGetAllValueT(ZFCoreArray< zfidentity > &idValues)
see ZFIdMapGetAll
ZFCoreArray< zfidentity > ZFIdMapGetAllValue(void)
see ZFIdMapGetAll
Definition ZFIdMap.h:52
zfidentity ZFIdMapIdForName(const zfstring &idName)
get id value from id name, or zfidentityInvalid if no such id name, see ZFIDMAP
zfidentity ZFIdMapDynamicRegister(const zfstring &idName)
dynamically register your own id
void ZFIdMapDynamicUnregister(zfidentity idValue)
unregister id that was registered by ZFIdMapDynamicRegister
zfstring ZFIdMapNameForId(zfidentity idValue)
get id name from id value, or null if no such id, see ZFIdMapIdForName
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
ZFObject's class info.
Definition ZFClass.h:67
light weight array
Definition ZFCoreArray.h:331