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

high level object IO More...

#include "ZFFile.h"

Go to the source code of this file.

Macros

#define ZFOBJECTIO_DEFINE(registerSig, level, checkerAction, fromInputAction, toOutputAction)
 see ZFObjectIOLoad
 
#define ZFStyleDecoder_ZFObjectIO
 see ZFSTYLE_DECODER_DEFINE
 

Functions

zfauto ZFObjectIOLoad (const ZFInput &input, zfstring *outErrorHint=zft_zfnull)
 high level object IO
 
zfbool ZFObjectIOLoadT (zfauto &ret, const ZFInput &input, zfstring *outErrorHint=zft_zfnull)
 see ZFObjectIOLoad
 
zfbool ZFObjectIOSave (const ZFOutput &output, ZFObject *obj, zfstring *outErrorHint=zft_zfnull)
 see ZFObjectIOLoad
 

Detailed Description

high level object IO

Macro Definition Documentation

◆ ZFOBJECTIO_DEFINE

#define ZFOBJECTIO_DEFINE ( registerSig,
level,
checkerAction,
fromInputAction,
toOutputAction )

see ZFObjectIOLoad

usage:

// callback to check whether the pathInfo can be used as object IO
// proto type:
// zfbool checker(
// ZF_IN zfbool isOutput
// , ZF_IN const ZFPathInfo &pathInfo
// , ZF_IN const zfstring &fileName
// , ZF_IN const zfstring &fileExt
// );
// pathInfo: ZFCallback::pathInfo
}, {
// callback to load object from input
// proto type:
// zfbool fromInput(
// ZF_OUT zfauto &ret
// , ZF_IN_OUT const ZFInput &input
// , ZF_OUT_OPT zfstring *outErrorHint = zfnull
// );
}, {
// callback to save object to output
// proto type:
// zfbool toOutput(
// ZF_IN_OUT const ZFOutput &output
// , ZF_IN zfany const &obj
// , ZF_OUT_OPT zfstring *outErrorHint = zfnull
// );
})
@ ZFLevelZFFrameworkPostNormal
ZFFramework post normal.
Definition ZFLevel.h:30
#define ZFOBJECTIO_DEFINE(registerSig, level, checkerAction, fromInputAction, toOutputAction)
see ZFObjectIOLoad
Definition ZFObjectIO.h:94

◆ ZFStyleDecoder_ZFObjectIO

#define ZFStyleDecoder_ZFObjectIO

see ZFSTYLE_DECODER_DEFINE

styleKey should start with '@' and holds a ZFPathInfo, the result style object would be created by ZFInputForPathInfo and ZFObjectIOLoad

Function Documentation

◆ ZFObjectIOLoad()

zfauto ZFObjectIOLoad ( const ZFInput & input,
zfstring * outErrorHint = zft_zfnull )
extern

high level object IO

most object of ZFFramework are seraizliable, and can be stored as different type (such as xml or json), to make app level code more convenient, we introduced this method to load/save serializable object without knowing underlying storage type

typical usage:

// serialize object from xml file
zfauto obj = ZFObjectIOLoad(ZFInputForRes("data.xml"));
// load image
zfauto img = ZFObjectIOLoad(ZFInputForRes("image.png"));
zfauto ZFObjectIOLoad(const ZFInput &input, zfstring *outErrorHint=zft_zfnull)
high level object IO
ZFInput ZFInputForRes(const zfstring &resFilePath)
util to create a resource file input callback, see ZFResOpen for what resource file is
Definition ZFPathType_res.h:33
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34


how it works:

  • get ZFCallback::pathInfo from input/output
  • call all impl checker method to check whether it matches impl's type, until we find an impl can resolve it (for most case, this is done by checking the file ext from pathInfo's pathData)
  • call impl callback to serialize from input or to output


to add your own type, please refer to ZFOBJECTIO_DEFINE