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

id to string map util, useful to define extendable string enum More...

#include "../ZFCoreDef.h"

Go to the source code of this file.

Macros

#define ZFIDMAP(YourIdName)
 declare an id within ZFObject class scope
 
#define ZFIDMAP_DETAIL(prefix, YourIdName)
 see ZFIDMAP
 
#define ZFIDMAP_INLINE(YourIdName)
 auto register version of ZFIDMAP
 
#define ZFIDMAP_DETAIL_INLINE(prefix, YourIdName)
 see ZFIDMAP_INLINE
 
#define ZFIDMAP_GLOBAL(ZFLIB_, YourIdName)
 declare an id in global scope, see ZFIDMAP
 
#define ZFIDMAP_GLOBAL_DETAIL(ZFLIB_, prefix, YourIdName)
 see ZFIDMAP_GLOBAL
 
#define ZFIDMAP_REGISTER(Scope, YourIdName)
 see ZFIDMAP
 
#define ZFIDMAP_REGISTER_DETAIL(Scope, prefix, YourIdName)
 see ZFIDMAP
 
#define ZFIDMAP_GLOBAL_REGISTER(YourIdName)
 see ZFIDMAP
 
#define ZFIDMAP_GLOBAL_REGISTER_DETAIL(prefix, YourIdName)
 see ZFIDMAP
 

Functions

zfstring ZFIdMapNameForId (zfidentity idValue)
 get id name from id value, or null if no such id, see ZFIdMapIdForName
 
zfidentity ZFIdMapIdForName (const zfstring &idName)
 get id value from id name, or zfidentityInvalid if no such id name, see ZFIDMAP
 
void ZFIdMapGetAll (ZFCoreArray< zfidentity > &idValues, ZFCoreArray< zfstring > &idNames)
 see ZFIDMAP
 
void ZFIdMapGetAllValueT (ZFCoreArray< zfidentity > &idValues)
 see ZFIdMapGetAll
 
ZFCoreArray< zfidentityZFIdMapGetAllValue (void)
 see ZFIdMapGetAll
 
void ZFIdMapGetAllNameT (ZFCoreArray< zfstring > &idNames)
 see ZFIdMapGetAll
 
ZFCoreArray< zfstringZFIdMapGetAllName (void)
 see ZFIdMapGetAll
 
zfidentity ZFIdMapDynamicRegister (const zfstring &idName)
 dynamically register your own id
 
void ZFIdMapDynamicUnregister (zfidentity idValue)
 unregister id that was registered by ZFIdMapDynamicRegister
 

Detailed Description

id to string map util, useful to define extendable string enum

Macro Definition Documentation

◆ ZFIDMAP

#define ZFIDMAP ( YourIdName)

declare an id within ZFObject class scope

usage:

zfclass YourClass ... {
ZFIDMAP(YourSth)
};
ZFIDMAP_REGISTER(YourClass, YourSth)
#define ZFIDMAP_REGISTER(Scope, YourIdName)
see ZFIDMAP
Definition ZFIdMap.h:185
#define ZFIDMAP(YourIdName)
declare an id within ZFObject class scope
Definition ZFIdMap.h:123
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38

declared id can be accessed by:

zfidentity idValue = YourClass::IdYourSth();
zfstring idName = ZFIdMapNameForId(idValue);
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:225
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
zfstring ZFIdMapNameForId(zfidentity idValue)
get id name from id value, or null if no such id, see ZFIdMapIdForName

note that subclass may declare an id same as parent, while the final id name is different:
ParentClass::IdYourSth() => "ParentClass.IdYourSth"
ChildClass::IdYourSth() => "ChildClass.IdYourSth"

Note
we declare the id as int types for performance, it's ensured each id has different value, but it's only ensured while app is running, after relaunching the app, the id value is not ensured the same, you should use the name of the id to store or pass between apps, and you can use ZFIdMapIdForName or ZFIdMapNameForId to convert them easily

◆ ZFIDMAP_INLINE

#define ZFIDMAP_INLINE ( YourIdName)

auto register version of ZFIDMAP

note: this would create a dummy class to perform register, which would increase your owner object's size

◆ ZFIDMAP_GLOBAL

#define ZFIDMAP_GLOBAL ( ZFLIB_,
YourIdName )

declare an id in global scope, see ZFIDMAP

usage:

// in header files
ZF_NAMESPACE_BEGIN(YourNamespace)
/ ** @brief you can add doxygen docs here * /
ZF_NAMESPACE_END(YourNamespace)
// use the id
zfidentity idValue = YourNamespace::IdYourSth();
#define ZFIDMAP_GLOBAL_REGISTER(YourIdName)
see ZFIDMAP
Definition ZFIdMap.h:204
#define ZFIDMAP_GLOBAL(ZFLIB_, YourIdName)
declare an id in global scope, see ZFIDMAP
Definition ZFIdMap.h:177
#define ZF_NAMESPACE_END(NameSpace)
end namespace
Definition ZFNamespace.h:60
#define ZF_NAMESPACE_BEGIN(NameSpace)
begin namespace
Definition ZFNamespace.h:40

unlike ZFIDMAP, this macro would declare id outside of class scope

Function Documentation

◆ ZFIdMapIdForName()

zfidentity ZFIdMapIdForName ( const zfstring & idName)
extern

get id value from id name, or zfidentityInvalid if no such id name, see ZFIDMAP

the id name should looks like YourClass.YourIdName or YourNamespace.YourIdName

note: can be found only if:

◆ ZFIdMapGetAll()

void ZFIdMapGetAll ( ZFCoreArray< zfidentity > & idValues,
ZFCoreArray< zfstring > & idNames )
extern

see ZFIDMAP

get all registered id data, for debug use only

Note
can be found only if registered by ZFIDMAP_REGISTER

◆ ZFIdMapDynamicRegister()

zfidentity ZFIdMapDynamicRegister ( const zfstring & idName)
extern

dynamically register your own id

assert fail if already registered

◆ ZFIdMapDynamicUnregister()

void ZFIdMapDynamicUnregister ( zfidentity idValue)
extern

unregister id that was registered by ZFIdMapDynamicRegister

do nothing if no such id, assert fail if the id is not dynamically registered