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
ZFPROPERTY_RETAIN(SomeSerializable *, mySerializableProperty)
};
#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:108
#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:103
#define ZFPROPERTY_ASSIGN(Type, Name,...)
see ZFPROPERTY_RETAIN
Definition ZFPropertyDeclare.h:127
base class of call serializable object
Definition ZFSerializable.h:151

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=0, zfstring *outErrorHint=0, ZFSerializable *referencedOwnerOrNull=0)
see ZFObjectFromDataT
zfauto ZFObjectFromData(const ZFSerializableData &serializableData, zfstring *outErrorHint=0, ZFSerializableData *outErrorPos=0)
see ZFObjectFromDataT
ZFSerializable's data container, see ZFSerializable.
Definition ZFSerializableData.h:72
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:164

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 ZFSerializableUtilSerializeAttributeFromData series
return zftrue;
}
virtual zfbool serializableOnSerializeToData(
ZF_IN_OUT ZFSerializableData &serializableData
, ZF_IN ZFSerializable *referencedOwnerOrNull
, ZF_OUT_OPT zfstring *outErrorHint = zfnull
) {
if(!zfsuperI(ZFSerializable)::serializableOnSerializeToData(serializableData, outErrorHint, outErrorPos)) {return zffalse;}
// serialize your type to serializableData
// recommended to use ZFSerializableUtilSerializeAttributeFromData 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_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:58
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:62
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:66
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:50
#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