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

user registered ZFMethod More...

#include "ZFMethod.h"

Go to the source code of this file.

Classes

class  ZFMethodDynamicRegisterParam
 param for ZFMethodDynamicRegister More...
 
class  ZFMP
 util for ZFDynamic::method More...
 

Functions

const ZFMethodZFMethodDynamicRegister (const ZFMethodDynamicRegisterParam &param, zfstring *errorHint=zft_zfnull)
 dynamic register a method, return null if fail
 
const ZFMethodZFMethodDynamicRegister (const ZFClass *ownerClass, const zfstring &returnTypeId, const zfstring &methodName, const ZFMP &methodParam, const ZFListener &methodImpl, ZFMethodType methodType=ZFMethodTypeVirtual, ZFMethodAccessType methodAccessType=ZFMethodAccessTypePublic, zfstring *errorHint=zft_zfnull)
 util to ZFMethodDynamicRegister
 
const ZFMethodZFMethodDynamicRegister (const zfstring &methodNamespace, const zfstring &returnTypeId, const zfstring &methodName, const ZFMP &methodParam, const ZFListener &methodImpl, ZFMethodType methodType=ZFMethodTypeVirtual, ZFMethodAccessType methodAccessType=ZFMethodAccessTypePublic, zfstring *errorHint=zft_zfnull)
 util to ZFMethodDynamicRegister
 
void ZFMethodDynamicUnregister (const ZFMethod *method)
 see ZFMethodDynamicRegister
 

Detailed Description

user registered ZFMethod

Function Documentation

◆ ZFMethodDynamicRegister()

const ZFMethod * ZFMethodDynamicRegister ( const ZFMethodDynamicRegisterParam & param,
zfstring * errorHint = zft_zfnull )
extern

dynamic register a method, return null if fail

comparing to ZFMethodUserRegister_0, a dynamic method would:

  • completely dynamic, can be registered from script language
  • use ZFMethodGenericInvoker to implement, have lower performance (trade for flexibility)
Note
you may override parent's method by registering a dynamic method in subclass, at this case, you may use ZFArgs::callSuper to call parent's method
dynamic registered contents would be removed automatically during ZFFrameworkCleanup as level ZFLevelZFFrameworkHigh
Warning
(ZFTAG_LIMITATION) for dynamic registered method, if your method has return value, you must take care the life cycle of the return value
when the method called by plain ZFMethod::executeExact instead of ZFMethod::methodGenericInvoker, the ZFTypeIdWrapper created by generic invoker would be released immediately after method call, which would cause the raw return value points to invalid address
to solve this, you have these workaround when implementing ZFMethodDynamicRegisterParam::methodGenericInvoker:
  • try not to have "non value type" return value for dynamic method (i.e. reference or pointer type)
  • store return value to owner object as ZFObject::objectTag (at this case, you should take care of circular reference, and value's life cycle)
  • zfRetain and zfautoRelease to extend the return value's life time (at this case, you should ensure the method's caller won't store the return value for a long time)