ZFFramework
Loading...
Searching...
No Matches
Serialization without extra code

unlike other serialization framework, when you want to serialize your own subclass in ZFFramework, typically there's no need to write any other serialization code, all property can be serialized if it's type is serializable, even for your custom type
example:

zfclassNotPOD MyCppType {
public:
zfint myValue;
};
ZFTYPEID_DECLARE(ZFLIB_APP, MyCppType, MyCppType)
ZFPROPERTY_ASSIGN(MyCppType, myProp1)
};
ZFTYPEID_DEFINE_BY_STRING_CONVERTER(MyCppType, MyCppType, {
// supply MyCppType's string conversion
return zfintFromStringT(v.myValue, src, srcLen);
}, {
// supply MyCppType's string conversion
return zfintToStringT(s, v.myValue);
})
#define ZFLIB_APP
used to export symbols
Definition ZFCoreEnvDef.h:35
#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
_ZFT_t_zfint zfint
same as int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:121
#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:124
#define ZFPROPERTY_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:127
zfbool zfintToStringT(zfstring &s, zfint const &v, zfstring *errorHint=0)
util method to convert zfint to string
zfbool zfintFromStringT(zfint &v, const zfchar *src, zfindex srcLen=((zfindex) -1), zfstring *errorHint=0)
util method to convert zfint from string
#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:276
common styleable object
Definition ZFStyleable.h:168

that's all, MyClass are serializable now, as you can see, you have no need to write any code to implement MyClass's serialization logic, all you need to do is to ensure all your property's type are serializable
also, like MyCppType, all plain cpp type can be embeded to ZFFramework's powerful serialization logic