2017-05-31 76 views
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" 

回答

1

你没有张贴,但我猜你的C++方法setHandle看起来像:

Expected<void> setHandle(IViewHandle); 

所以,如果你只是只想为这种方法修改返回类型,你可以设置一个%typemap(csout),有点像这样:

%typemap(csout) Expected<void> MyClass::setHandle %{ 
    Expected_void ret = $imcall;$excode 
    return Expected(ret); 
%} 

我认为这应该有效。也许我忘了一些东西,但看看围绕this,也许你会发现更多的信息。

希望它有帮助。

编辑:

实际上不会工作,这就是我的意思:

%typemap(csout) Expected<void> MyClass::setHandle %{ 
    Expected ret = new Expected($imcall);$excode 
    return ret; 
%} 
+0

谢谢, 我将我的解决方案添加到帖子中。你离我的解决方案还不太远;-) – CDZ

+0

好的,我看到你的解决方案。如果您没有创建IExpected来解决这个问题,那显然是最好的。 无论如何,我注意到我在回答中犯了一个错误,我编辑这个帖子以防万一。 –

+0

另一个提示,只是要知道,这个typemap将适用于所有返回预期的方法。要专注于一种方法,您需要指定方法名称,就像我一样。 –