ZFFramework
Loading...
Searching...
No Matches
Macros | Functions
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(YourIdName)
 declare an id in global scope, see ZFIDMAP
 
#define ZFIDMAP_GLOBAL_DETAIL(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

const zfcharZFIdMapNameForId (zfidentity idValue)
 get id name from id value, or null if no such id, see ZFIdMapIdForName
 
zfidentity ZFIdMapIdForName (const zfchar *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
 
zfidentity ZFIdMapDynamicRegister (const zfchar *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:181
#define ZFIDMAP(YourIdName)
declare an id within ZFObject class scope
Definition ZFIdMap.h:111
#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();
const zfchar *idName = ZFIdMapNameForId(idValue);
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:192
const zfchar * 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 ( 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 ZF_NAMESPACE_END(NameSpace)
end namespace
Definition ZFCoreEnvDef.h:50
#define ZF_NAMESPACE_BEGIN(NameSpace)
begin namespace
Definition ZFCoreEnvDef.h:42
#define ZFIDMAP_GLOBAL_REGISTER(YourIdName)
see ZFIDMAP
Definition ZFIdMap.h:191
#define ZFIDMAP_GLOBAL(YourIdName)
declare an id in global scope, see ZFIDMAP
Definition ZFIdMap.h:165

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

Function Documentation

◆ ZFIdMapIdForName()

zfidentity ZFIdMapIdForName ( const zfchar * 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 accessed or registered by ZFIDMAP_REGISTER

◆ ZFIdMapDynamicRegister()

zfidentity ZFIdMapDynamicRegister ( const zfchar * 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