0
我试图迫使痛饮使用自己的包装围绕“默认”生成的包装,这里有一个例子...各地SWIG包装定制包装
我有以下的“接口”代码:
template<typename T>
class Expected
{
public:
T Value();
};
%template(Expected_Int) Expected<int>;
%template(Expected_Bool) Expected<bool>;
%template(Expected_Void) Expected<void>;
和我自己的C#实现(我自己的包装)
public class Expected
{
public Expected(Expected_Void private) {...}
}
在其他班,我用的是预期收益值,像这样的“预期setHandle(IViewHandle *手柄)”,并痛饮生成验证码:
public override Expected_Void setHandle(IViewHandle handle) {
Expected_Void ret = new Expected_Void(luciadsdkPINVOKE.ViewContext_setHandle(swigCPtr, IViewHandle.getCPtr(handle)), true);
if (luciadsdkPINVOKE.SWIGPendingException.Pending) throw luciadsdkPINVOKE.SWIGPendingException.Retrieve();
return ret;
}
现在,我希望生成下面的C#代码(大约有SWIG包装我自己的包装)
public override Expected setHandle(IViewHandle handle) {
Expected_Void ret = new Expected_Void(luciadsdkPINVOKE.ViewContext_setHandle(swigCPtr, IViewHandle.getCPtr(handle)), true);
if (luciadsdkPINVOKE.SWIGPendingException.Pending) throw luciadsdkPINVOKE.SWIGPendingException.Retrieve();
return Expected(ret);
}
这可能吗?
感谢
的解
%typemap(csout,excode=SWIGEXCODE) Expected<void> {
IExpected ret = new IExpected($imcall, true);$excode
return ret;
}
%typemap(cstype) Expected<void> "IExpected"
谢谢, 我将我的解决方案添加到帖子中。你离我的解决方案还不太远;-) – CDZ
好的,我看到你的解决方案。如果您没有创建IExpected来解决这个问题,那显然是最好的。 无论如何,我注意到我在回答中犯了一个错误,我编辑这个帖子以防万一。 –
另一个提示,只是要知道,这个typemap将适用于所有返回预期的方法。要专注于一种方法,您需要指定方法名称,就像我一样。 –