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 , ZF_IN_OPT const zfstring &filter = zfnull
49 );
53 , ZF_IN_OPT const zfstring &filter = zfnull
54 );
58 ZFIdMapGetAllIdT(ret, filter);
59 return ret;
60}
61
64 , ZF_IN_OPT const zfstring &filter = zfnull
65 );
69 ZFIdMapGetAllNameT(ret, filter);
70 return ret;
71}
72
86
87zfclassLikePOD ZFLIB_ZFCore _ZFP_ZFIdMapHolder {
88public:
89 _ZFP_ZFIdMapHolder(
90 ZF_IN const zfstring &idName
91 , ZF_IN const ZFClass *ownerClass
92 , ZF_IN const zfstring &ownerNamespace
93 , ZF_IN const zfstring &methodName
94 );
95 ~_ZFP_ZFIdMapHolder(void);
96
97public:
98 const zfidentity *idValue;
99};
130#define ZFIDMAP(YourIdName) \
131 ZFIDMAP_DETAIL(Id, YourIdName)
132
133#define ZFIDMAP_DETAIL(prefix, YourIdName) \
134 public: \
135 \
136 static zfidentity prefix##YourIdName(void);
137
144#define ZFIDMAP_INLINE(YourIdName) \
145 ZFIDMAP_DETAIL_INLINE(Id, YourIdName)
146
147#define ZFIDMAP_DETAIL_INLINE(prefix, YourIdName) \
148 private: \
149 zfclassNotPOD _ZFP_IdMapReg_##prefix##YourIdName { \
150 public: \
151 _ZFP_IdMapReg_##prefix##YourIdName(void) { \
152 zfself::prefix##YourIdName(); \
153 } \
154 } _ZFP_IdMap_##prefix##YourIdName; \
155 public: \
156 static zfidentity prefix##YourIdName(void) { \
157 static _ZFP_ZFIdMapHolder d( \
158 zfstr("%s.%s", zfself::ClassData()->classNameFull(), ZFM_TOSTRING(prefix##YourIdName)) \
159 , zfself::ClassData() \
160 , zfnull \
161 , zftext(ZFM_TOSTRING(prefix##YourIdName)) \
162 ); \
163 return *(d.idValue); \
164 }
165
184#define ZFIDMAP_GLOBAL(ZFLIB_, YourIdName) \
185 ZFIDMAP_GLOBAL_DETAIL(ZFLIB_, Id, YourIdName)
186
187#define ZFIDMAP_GLOBAL_DETAIL(ZFLIB_, prefix, YourIdName) \
188 \
189 extern ZFLIB_ zfidentity prefix##YourIdName(void);
190
192#define ZFIDMAP_REGISTER(Scope, YourIdName) \
193 ZFIDMAP_REGISTER_DETAIL(Scope, Id, YourIdName)
194
195#define ZFIDMAP_REGISTER_DETAIL(Scope, prefix, YourIdName) \
196 zfidentity Scope::prefix##YourIdName(void) { \
197 static _ZFP_ZFIdMapHolder d( \
198 zfstr("%s.%s", zfself::ClassData()->classNameFull(), ZFM_TOSTRING(prefix##YourIdName)) \
199 , zfself::ClassData() \
200 , zfnull \
201 , zftext(ZFM_TOSTRING(prefix##YourIdName)) \
202 ); \
203 return *(d.idValue); \
204 } \
205 ZF_STATIC_REGISTER_INIT(ZFIdMap_##Scope##_##YourIdName) { \
206 (void)Scope::prefix##YourIdName(); \
207 } \
208 ZF_STATIC_REGISTER_END(ZFIdMap_##Scope##_##YourIdName)
209
211#define ZFIDMAP_GLOBAL_REGISTER(YourIdName) \
212 ZFIDMAP_GLOBAL_REGISTER_DETAIL(Id, YourIdName)
213
214#define ZFIDMAP_GLOBAL_REGISTER_DETAIL(prefix, YourIdName) \
215 zfidentity prefix##YourIdName(void) { \
216 static _ZFP_ZFIdMapHolder d( \
217 zfstr("%s.%s", ZF_NAMESPACE_CURRENT() ? ZF_NAMESPACE_CURRENT() : "", ZFM_TOSTRING(prefix##YourIdName)) \
218 , zfnull \
219 , ZF_NAMESPACE_CURRENT() \
220 , zftext(ZFM_TOSTRING(prefix##YourIdName)) \
221 ); \
222 return *(d.idValue); \
223 } \
224 ZF_STATIC_REGISTER_INIT(ZFIdMap_##YourIdName) { \
225 (void)prefix##YourIdName(); \
226 } \
227 ZF_STATIC_REGISTER_END(ZFIdMap_##YourIdName) \
228
230#endif // #ifndef _ZFI_ZFIdMap_h_
231
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:196
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:200
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:212
#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
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
zfidentity ZFIdMapIdForName(const zfstring &idName)
get id value from id name, or zfidentityInvalid if no such id name, see ZFIDMAP
void ZFIdMapGetAllIdT(ZFCoreArray< zfidentity > &idValues, const zfstring &filter=zft_zfnull)
see ZFIdMapGetAll
ZFCoreArray< zfstring > ZFIdMapGetAllName(const zfstring &filter=zft_zfnull)
see ZFIdMapGetAll
Definition ZFIdMap.h:67
void ZFIdMapGetAllNameT(ZFCoreArray< zfstring > &idNames, const zfstring &filter=zft_zfnull)
see ZFIdMapGetAll
ZFCoreArray< zfidentity > ZFIdMapGetAllId(const zfstring &filter=zft_zfnull)
see ZFIdMapGetAll
Definition ZFIdMap.h:56
zfidentity ZFIdMapDynamicRegister(const zfstring &idName)
dynamically register your own id
void ZFIdMapDynamicUnregister(zfidentity idValue)
unregister id that was registered by ZFIdMapDynamicRegister
void ZFIdMapGetAll(ZFCoreArray< zfidentity > &idValues, ZFCoreArray< zfstring > &idNames, const zfstring &filter=zft_zfnull)
see ZFIDMAP
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:63
light weight array
Definition ZFCoreArray.h:297