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

reflectable type define More...

#include "ZFTypeIdFwd.h"

Go to the source code of this file.

Macros

#define ZFTYPEID_DECLARE(ZFLIB_, TypeName, Type)
 register a type for reflection
 
#define ZFTYPEID_DECLARE_WITH_CUSTOM_WRAPPER(ZFLIB_, TypeName, Type)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_REG(ZFLIB_, TypeName, Type, ...)
 see ZFTYPEID_DECLARE
 
#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)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ACCESS_ONLY_REG(ZFLIB_, TypeName, Type, ...)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ACCESS_ONLY_DEFINE(TypeName, Type)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ACCESS_ONLY_DEFINE_UNCOMPARABLE(TypeName, Type)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ALIAS_DECLARE(ZFLIB_, AliasToTypeName, AliasToType, TypeName, Type)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ALIAS_REG(ZFLIB_, AliasToTypeName, AliasToType, TypeName, Type, ...)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ALIAS_REG_CUSTOM(ZFLIB_, AliasToTypeName, AliasToType, TypeName, Type, TypeIdValueConversion, ...)
 see ZFTYPEID_DECLARE
 
#define ZFTYPEID_ALIAS_DEFINE(AliasToTypeName, AliasToType, TypeName, Type)
 see ZFTYPEID_DECLARE
 

Detailed Description

reflectable type define

Macro Definition Documentation

◆ ZFTYPEID_DECLARE

#define ZFTYPEID_DECLARE ( ZFLIB_,
TypeName,
Type )

register a type for reflection

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
// * must be declared inside global namespace (#ZF_NAMESPACE_GLOBAL_BEGIN)
// * type name must be unique, you may use custom prefix to prevent name conflict
/ **
* add your Doxygen docs here
* /
ZFTYPEID_DECLARE(ZFLIB_APP, YourType, YourType)
ZFTYPEID_REG(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 ZFTypeIdDeclare.h:155
#define ZFTYPEID_DECLARE(ZFLIB_, TypeName, Type)
register a type for reflection
Definition ZFTypeIdDeclare.h:137
#define ZFTYPEID_DEFINE_BY_STRING_CONVERTER(TypeName, Type, convertFromStringAction, convertToStringAction)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:166
#define ZFTYPEID_REG(ZFLIB_, TypeName, Type,...)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:151
#define ZFTYPEID_DEFINE_BY_SERIALIZABLE_CONVERTER(TypeName, Type, serializeFromAction, serializeToAction)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:180

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:

ADVANCED:
ZFTypeId can also be declared in different namespace, or even declared as inner class, with some limitations

declare in different namespace:

// ============================================================
// in h file
ZF_NAMESPACE_BEGIN(YourNamespace)
// declare as usual, inside namespace
ZFTYPEID_DECLARE(ZFLIB_APP, YourType, YourType)
ZF_NAMESPACE_END(YourNamespace)
// ZFTYPEID_REG must be declared in global scope, with owner namespace declared
ZFTYPEID_REG(ZFLIB_APP, YourType, YourType, YourNamespace)
// ============================================================
// in cpp file
ZFTYPEID_DEFINE(YourType, YourType, ...)
#define ZF_NAMESPACE_END(NameSpace)
end namespace
Definition ZFNamespace.h:60
#define ZF_NAMESPACE_BEGIN(NameSpace)
begin namespace
Definition ZFNamespace.h:40


declare as inner class:

// ============================================================
// in h file
zfclass ZFLIB_APP YourOuterClass : zfextend ZFObject {
ZFOBJECT_DECLARE(YourOuterClass, ZFObject)
zfclassNotPOD YourType {};
// declare as inner class
ZFTYPEID_INNER_DECLARE(YourOuterClass, YourType, YourType)
};
// ZFTYPEID_INNER_REG must be declared in global scope
ZFTYPEID_INNER_REG(YourOuterClass, YourType, YourType)
// ============================================================
// in cpp file
ZFTYPEID_INNER_DEFINE(YourOuterClass, YourType, YourType, ...)
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
#define ZFTYPEID_INNER_REG(OuterClass, TypeName, Type)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare_inner.h:28
#define ZFTYPEID_INNER_DECLARE(OuterClass, TypeName, Type)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare_inner.h:14
#define ZFTYPEID_INNER_DEFINE(OuterClass, TypeName, Type, serializeFromAction, serializeToAction, convertFromStringAction, convertToStringAction)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare_inner.h:32
base class of all objects
Definition ZFObjectCore.h:209