ZFFramework
Loading...
Searching...
No Matches
Classes | Macros
ZFTypeIdCore.h File Reference

reflectable type define More...

#include "ZFStyleable.h"
#include "ZFProgressable.h"
#include "ZFMethodUserRegister.h"
#include "ZFMethodFuncUserRegister.h"
#include "ZFMethodFuncDeclare.h"
#include "ZFObjectUtil.h"
#include "ZFSerializableUtil.h"
#include "ZFSerializableDataSerializableConverter.h"
#include "ZFObjectRetain.h"

Go to the source code of this file.

Classes

class  ZFTypeIdWrapper
 dummy base for all wrapper types, see ZFTypeId::Value More...
 

Macros

#define ZFTYPEID_DECLARE(ZFLIB_, TypeName, Type)
 register a type
 
#define ZFTYPEID_DECLARE_WITH_CUSTOM_WRAPPER(ZFLIB_, TypeName, Type)
 declare a type id with custom type wrapper
 
#define ZFTYPEID_DEFINE(TypeName, Type, serializeFromAction, serializeToAction, convertFromStringAction, convertToStringAction)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_DEFINE_WITH_CUSTOM_WRAPPER(TypeName, Type, serializeFromAction, serializeToAction, convertFromStringAction, convertToStringAction)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_DEFINE_BY_STRING_CONVERTER(TypeName, Type, convertFromStringAction, convertToStringAction)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_DEFINE_BY_STRING_CONVERTER_WITH_CUSTOM_WRAPPER(TypeName, Type, convertFromStringAction, convertToStringAction)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_DEFINE_BY_SERIALIZABLE_CONVERTER(TypeName, Type, serializeFromAction, serializeToAction)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_DEFINE_BY_SERIALIZABLE_CONVERTER_WITH_CUSTOM_WRAPPER(TypeName, Type, serializeFromAction, serializeToAction)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ACCESS_ONLY_DECLARE(ZFLIB_, TypeName, Type)
 declare a type that reflectable and accessable, but not serializable
 
#define ZFTYPEID_ACCESS_ONLY_DEFINE(TypeName, Type)
 see ZFTYPEID_ACCESS_ONLY_DECLARE
 
#define ZFTYPEID_ACCESS_ONLY_DEFINE_UNCOMPARABLE(TypeName, Type)
 see ZFTYPEID_ACCESS_ONLY_DECLARE
 
#define ZFTYPEID_ALIAS_DECLARE(ZFLIB_, AliasToTypeName, AliasToType, TypeName, Type)
 alias an existing type to another type, see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ALIAS_DEFINE(AliasToTypeName, AliasToType, TypeName, Type)
 see ZFTYPEID_ALIAS_DECLARE
 
#define ZFTYPEID_ALIAS_DECLARE_CUSTOM(ZFLIB_, AliasToTypeName, AliasToType, TypeName, Type, TypeIdValueConversion)
 see ZFTYPEID_ALIAS_DECLARE
 
#define ZFTYPEID_DISABLE(Type)
 explicitly mark the type can not be reflected when used in ZFMETHOD_INLINE_0 or ZFPROPERTY_ASSIGN
 
#define ZFTYPEID_PROGRESS_DEFINE(TypeName, Type, progressUpdateAction)
 register Type's progress update logic
 
#define ZFTYPEID_PROGRESS_DEFINE_BY_VALUE(TypeName, Type)
 util macro to declare ZFTYPEID_PROGRESS_DEFINE by raw value calculating
 

Detailed Description

reflectable type define

Macro Definition Documentation

◆ ZFTYPEID_DECLARE

#define ZFTYPEID_DECLARE ( ZFLIB_,
TypeName,
Type )

register a type

usually for implementation use only, ZFFramework would supply most of the types, however you may use this to register your own types

typical code to register a type:

// ============================================================
// in h file
// declare your type, name must be unique
/ **
* add your Doxygen docs here
* /
ZFTYPEID_DECLARE(ZFLIB_APP, YourType, YourType)
// ============================================================
// in cpp file
// register your type
ZFTYPEID_DEFINE(YourType, YourType, {
// serializeFrom callback, proto type:
// zfbool YourTypeFromDataT(
// ZF_OUT YourType &v
// , ZF_IN const ZFSerializableData &serializableData
// , ZF_OUT_OPT zfstring *outErrorHint = zfnull
// , ZF_OUT_OPT ZFSerializableData *outErrorPos = zfnull
// );
// you should:
// * check whether the type match the serializableData's type
// * serialize from serializableData
}, {
// serializeTo callback, proto type:
// zfbool YourTypeToDataT(
// ZF_OUT ZFSerializableData &serializableData
// , ZF_IN YourType const &v
// , ZF_OUT_OPT zfstring *outErrorHint = zfnull
// );
// you should:
// * save type name to the serializableData
// * save type value to the serializableData
}, {
// convertFromString callback, proto type:
// zfbool YourTypeFromStringT(
// ZF_OUT YourType &v
// , ZF_IN const zfchar *src
// , ZF_IN_OPT zfindex srcLen = zfindexMax()
// , ZF_OUT_OPT zfstring *errorHint = zfnull
// );
}, {
// convertToString callbackk, proto type:
// zfbool YourTypeToStringT(
// ZF_IN_OUT zfstring &s
// , ZF_IN YourType const &v
// , ZF_OUT_OPT zfstring *errorHint = zfnull
// );
})
// or, you may use #ZFTYPEID_DEFINE_BY_STRING_CONVERTER for short,
// if your type support converter from/to string
ZFTYPEID_DEFINE_BY_STRING_CONVERTER(YourType, YourType, YourTypeFromString, YourTypeToString)
// or, you may use #ZFTYPEID_DEFINE_BY_SERIALIZABLE_CONVERTER for short,
// if your type support converter from/to ZFSerializableData
ZFTYPEID_DEFINE_BY_SERIALIZABLE_CONVERTER(YourType, YourType, YourTypeFromData, YourTypeToData)
#define ZFLIB_APP
used to export symbols
Definition ZFCoreEnvDef.h:35
#define ZFTYPEID_DEFINE(TypeName, Type, serializeFromAction, serializeToAction, convertFromStringAction, convertToStringAction)
see ZFTYPEID_DECLARE
Definition ZFTypeIdCore.h:162
#define ZFTYPEID_DECLARE(ZFLIB_, TypeName, Type)
register a type
Definition ZFTypeIdCore.h:98
#define ZFTYPEID_DEFINE_BY_STRING_CONVERTER(TypeName, Type, convertFromStringAction, convertToStringAction)
see ZFTYPEID_DECLARE
Definition ZFTypeIdCore.h:291
#define ZFTYPEID_DEFINE_BY_SERIALIZABLE_CONVERTER(TypeName, Type, serializeFromAction, serializeToAction)
see ZFTYPEID_DECLARE
Definition ZFTypeIdCore.h:327

once registered, your type can be used as ZFPROPERTY_ASSIGN which benefits from the powerful automatic serialization logic, or, can be used as reflectable param or return type for ZFMETHOD_INLINE_0


ADVANCED:

◆ ZFTYPEID_DECLARE_WITH_CUSTOM_WRAPPER

#define ZFTYPEID_DECLARE_WITH_CUSTOM_WRAPPER ( ZFLIB_,
TypeName,
Type )

declare a type id with custom type wrapper

by default, all of your type should be registered by ZFTYPEID_DECLARE series, for some special case, you may need to register your type manually, to achieve this, you must:

  • specialize template ZFTypeId
  • use this macro to register your type

◆ ZFTYPEID_ACCESS_ONLY_DECLARE

#define ZFTYPEID_ACCESS_ONLY_DECLARE ( ZFLIB_,
TypeName,
Type )

declare a type that reflectable and accessable, but not serializable

by default, all return types and method types in ZFMethod must be registered by ZFTYPEID_DECLARE for advanced reflection logic
if you simply want basic method declaration, you may use this macro to disable your type explicitly
see ZFTYPEID_DECLARE for more info

◆ ZFTYPEID_ALIAS_DECLARE

#define ZFTYPEID_ALIAS_DECLARE ( ZFLIB_,
AliasToTypeName,
AliasToType,
TypeName,
Type )

alias an existing type to another type, see ZFTYPEID_DECLARE

the original type must be declared by ZFTYPEID_DECLARE or ZFTYPEID_ACCESS_ONLY_DECLARE
the newly aliased type would share same type id, serializable converter and string converter, with the original exist one
see ZFTYPEID_DECLARE for more info

Note
aliased type would:
  • create temp holder object for conversion
  • perform value copy during conversion

which would cause bad performance during reflection
if performance matters, you should consider supply custom type id specializations (by ZFTYPEID_ALIAS_DECLARE_CUSTOM), or, prevent to use aliased type for reflectable method

◆ ZFTYPEID_ALIAS_DECLARE_CUSTOM

#define ZFTYPEID_ALIAS_DECLARE_CUSTOM ( ZFLIB_,
AliasToTypeName,
AliasToType,
TypeName,
Type,
TypeIdValueConversion )

see ZFTYPEID_ALIAS_DECLARE

the TypeIdValueConversion must supply as macro expansion with these proto type:

#define MyExpand(ZFLIB_, AliasToTypeName, AliasToType, TypeName, Type) \
template<typename T_Access = _ZFP_PropTypeW_##TypeName \
, int T_IsPointer = ((zftTraits<typename zftTraits<T_Access>::TrNoRef>::TrIsPtr \
&& zftIsSame< \
typename zftTraits<T_Access>::TrNoRef, \
_ZFP_PropTypeW_##TypeName \
>::Value != 1) \
? 1 : 0) \
, typename T_Fix = void \
> \
zfclassNotPOD Value { \
public: \
static zfbool zfvAccessAvailable(ZF_IN_OUT zfauto &obj) { \
return yourChecker(xxx); \
} \
static T_Access zfvAccess(ZF_IN_OUT zfauto &obj) { \
return yourAccess(xxx); \
} \
static void zfvAccessFinish(ZF_IN_OUT zfauto &obj) { \
yourCleanup(xxx); \
} \
}; \
template<typename T_Access> \
zfclassNotPOD Value<T_Access, 1> { \
public: \
static zfbool zfvAccessAvailable(ZF_IN_OUT zfauto &obj) { \
return yourChecker(xxx); \
} \
static T_Access zfvAccess(ZF_IN_OUT zfauto &obj) { \
return yourAccess(xxx); \
} \
static void zfvAccessFinish(ZF_IN_OUT zfauto &obj) { \
yourCleanup(xxx); \
} \
};

◆ ZFTYPEID_DISABLE

#define ZFTYPEID_DISABLE ( Type)

explicitly mark the type can not be reflected when used in ZFMETHOD_INLINE_0 or ZFPROPERTY_ASSIGN

by default, all return types and method types in ZFMethod must be registered by ZFTYPEID_DECLARE for advanced reflection logic
if you simply want basic method declaration, you may use this macro to disable your type explicitly
see ZFTYPEID_DECLARE for more info

◆ ZFTYPEID_PROGRESS_DEFINE

#define ZFTYPEID_PROGRESS_DEFINE ( TypeName,
Type,
progressUpdateAction )

register Type's progress update logic

a progress update means, the type can be changed by timeline by supply a "from/to" value range
for example, an float type with range "[0.5, 3.0]" and progress "0.3", would result "0.5 + (3.0 - 0.5) * 0.3", which is 1.25
this is useful to make a property change with animation

to use this, register your type by this macro, with this proto type:

zfbool update(
ZF_OUT Type &ret
, ZF_IN Type const &from
, ZF_IN Type const &to
, ZF_IN zffloat progress
);
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_OUT
dummy macro that shows the param used as required output
Definition ZFCoreTypeDef_ClassType.h:188
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:58
_ZFT_t_zffloat zffloat
same as float, see zfindex
Definition ZFCoreTypeDef_CoreType.h:135

then use them by ZFProgressable::progressUpdate

to register:

ZFTYPEID_PROGRESS_DEFINE(YourType, YourType, {
yourProgress(ret, from, to, progress);
})
#define ZFTYPEID_PROGRESS_DEFINE(TypeName, Type, progressUpdateAction)
register Type's progress update logic
Definition ZFTypeIdCore.h:704

or use ZFTYPEID_PROGRESS_DEFINE_BY_VALUE for short