Custom wrapper around template wrapper

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Custom wrapper around template wrapper

Christophe Demez

Hi,

I try to force SWIG to use my own wrapper around the "default" generated wrappers, here is an example...

I have the following "interface" code :

    template<typename T>
    class Expected
    {
    public:
       T Value();
    };
 
    %template(Expected_Int)   Expected<int>;
    %template(Expected_Bool)  Expected<bool>;
    %template(Expected_Void)  Expected<void>;

And my own C# implementation (my own wrapper)

    public class Expected
    {
      public Expected(Expected_Void private) {...}
    }

In other classes, I use the Expected<void> return value, like this "Expected<void> setHandle(IViewHandle * handle)" and SWIG generate this code  :

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;
  }

Now, I wish to generate the following C# code (have my own wrapper around SWIG wrappers)

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);
}

Is it possible ?

Thanks

--
Luciad Email Signature Christophe Demez
PROJECT LEADER  

LUCIAD  CONNECT  •  VISUALIZE   ANALYZE   ACT  

[hidden email]   T +32 16 23 95 91
Follow us on LinkedIn or @LUCIADconnect  

Luciad

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Custom wrapper around template wrapper

William S Fulton


On 31 May 2017 at 14:58, Christophe Demez <[hidden email]> wrote:

Hi,

I try to force SWIG to use my own wrapper around the "default" generated wrappers, here is an example...

I have the following "interface" code :

    template<typename T>
    class Expected
    {
    public:
       T Value();
    };
 
    %template(Expected_Int)   Expected<int>;
    %template(Expected_Bool)  Expected<bool>;
    %template(Expected_Void)  Expected<void>;

And my own C# implementation (my own wrapper)

    public class Expected
    {
      public Expected(Expected_Void private) {...}
    }

In other classes, I use the Expected<void> return value, like this "Expected<void> setHandle(IViewHandle * handle)" and SWIG generate this code  :

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;
  }

Now, I wish to generate the following C# code (have my own wrapper around SWIG wrappers)

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);
}

Is it possible ?

Yes, use the "csout" typemap.

William


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...