ZFFramework
 
Loading...
Searching...
No Matches
Serializable

to make an object serializable is easy:

// extend from any ZFObject type, and implement from ZFSerializable
ZFOBJECT_DECLARE(MyObject, MyParent)
// normal property value would be serialized automatically
// object type property can be serialized automatically
// if it's serializable
};
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#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 ZFIMPLEMENT_DECLARE(ImplementedInterfaces,...)
see ZFINTERFACE_DECLARE
Definition ZFObjectInterface.h:169
#define zfimplement
shows class implement from interface, see ZFInterface
Definition ZFObjectInterface.h:24
#define ZFPROPERTY_RETAIN(Type, Name,...)
declare a retain property
Definition ZFPropertyDeclare.h:104
#define ZFPROPERTY_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:128
base class of call serializable object
Definition ZFSerializable.h:163
see zfany
Definition zfany.h:106

once declared, the object can be serialized by:

// serialize to an data holder,
// which can be converted to raw data and write to file,
// you may also convert it to xml or json or other data formats
// serialize object from existing data
zfauto serializedObject = ZFObjectFromData(data);
ZFSerializableData ZFObjectToData(ZFObject *obj, zfbool *outSuccess=zft_zfnull, zfstring *outErrorHint=zft_zfnull, ZFSerializable *refOwner=zft_zfnull)
see ZFObjectFromDataT
zfauto ZFObjectFromData(const ZFSerializableData &serializableData, zfstring *outErrorHint=zft_zfnull, ZFSerializableData *outErrorPos=zft_zfnull)
see ZFObjectFromDataT
ZFSerializable's data container, see ZFSerializable.
Definition ZFSerializableData.h:74
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
util class to alloc and hold ZFObject type
Definition ZFObjectAutoPtr.h:157

Advanced

if any of contents of your object can't be serialized automatically, you may override some methods to supply your own serialize logic:

protected:
virtual zfbool serializableOnSerializeFromData(
ZF_IN const ZFSerializableData &serializableData
, ZF_OUT_OPT zfstring *outErrorHint = zfnull
) {
if(!zfsuperI(ZFSerializable)::serializableOnSerializeFromData(serializableData, outErrorHint, outErrorPos)) {return zffalse;}
// serialize your type from serializableData
// recommended to use ZFSerializableUtilSerializeAttrFromData series
return zftrue;
}
virtual zfbool serializableOnSerializeToData(
ZF_IN_OUT ZFSerializableData &serializableData
, ZF_OUT_OPT zfstring *outErrorHint = zfnull
) {
if(!zfsuperI(ZFSerializable)::serializableOnSerializeToData(serializableData, outErrorHint, refOwner)) {return zffalse;}
// serialize your type to serializableData
// recommended to use ZFSerializableUtilSerializeAttrFromData series
return zftrue;
}
private:
YourNotSerializableType data;
};
#define ZF_OUT_OPT
dummy macro that shows the param used as optional output
Definition ZFCoreTypeDef_ClassType.h:192
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define zfsuperI(T_SuperType)
class ref to proper super type, see ZFObject for more info
Definition ZFObjectDeclare.h:26
base class of all objects
Definition ZFObjectCore.h:209

for detailed usage, please refer to ZFSerializable