Quantcast

Wrapping a custom smart pointer

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

Wrapping a custom smart pointer

Jeremy Cowles
Hi swig-users,

I'm new to SWIG and want to wrap a fairly complex custom smart pointer (to C# and, perhaps later, to Go), so I started reading the typemap docs and looking at the standard smart_ptr library source and now I have some questions:

1) What triggers the auto-magic smart pointer internals? From other threads, I realize that the logic is baked into the SWIG executable and from the docs I understand that SWIG is attempting to detect smart pointers, but curious exactly how it's being triggered.

2) Perhaps related, what is this line doing in lib/shared_ptr.h?

%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }

3) The smart pointer I need to wrap doesn't match the <NAMESPACE>::<SUBNAMESPACE>::shared_ptr naming pattern and has slightly different semantics and API, so I think I'm going to write something very similar. The pointers typically take this form: TfRefPtr<Foo> which gets typedef'd to FooRefPtr (similarly FooConstRefPtr) as well as TfWeakPtr<Foo> / FooWeakPtr. I would love to avoid re-writing that logic, any suggestions?

4) I would like TfWeakPtr to be wrapped out as a weak reference in C#. I'm not sure if it should literally be NET's WeakReference<T>, but I want to correctly surface the weak-pointer-ness. Any guidance there?

5) The C++ class hierarchy is kind of... intricate (involving CRTP and several layers of base classes/templates) -- how much of that do I need to expose to SWIG? Can I get away with making a proxy class that has some limited set of public members and no base classes?


And most importantly: thanks for making and maintaining such an awesome tool! :D

--
Jeremy


------------------------------------------------------------------------------

_______________________________________________
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: Wrapping a custom smart pointer

Andrew Haining

I can’t really speak to points 1, 2 & 3. I haven’t looked into the shared_ptr implementation since I don’t use it but. But regarding points 4 & 5 here are my thoughts:

4.) It’s perfectly OK to wrap a weak pointer just as you would any other object, it imbues itself with weakness, taking a weak reference to a weak pointer doesn’t really make sense.

5.) I think it’s best to expose the cleanest interface you can, the .i doesn’t really need to resemble the header at all, except that the things it does define need to be in the class, removing functions or Base classes you don’t want to wrap is all perfectly acceptable. At the end of the day the generated code is just going to call the function you said was there, it (mostly) doesn’t really care about anything else. I also use CRTP and obfuscate it from SWIG for example.

 

From: Jeremy Cowles [mailto:[hidden email]]
Sent: 14 September 2016 17:26
To: [hidden email]
Subject: [Swig-user] Wrapping a custom smart pointer

 

Hi swig-users,

 

I'm new to SWIG and want to wrap a fairly complex custom smart pointer (to C# and, perhaps later, to Go), so I started reading the typemap docs and looking at the standard smart_ptr library source and now I have some questions:

 

1) What triggers the auto-magic smart pointer internals? From other threads, I realize that the logic is baked into the SWIG executable and from the docs I understand that SWIG is attempting to detect smart pointers, but curious exactly how it's being triggered.

 

2) Perhaps related, what is this line doing in lib/shared_ptr.h?

 

%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }

 

3) The smart pointer I need to wrap doesn't match the <NAMESPACE>::<SUBNAMESPACE>::shared_ptr naming pattern and has slightly different semantics and API, so I think I'm going to write something very similar. The pointers typically take this form: TfRefPtr<Foo> which gets typedef'd to FooRefPtr (similarly FooConstRefPtr) as well as TfWeakPtr<Foo> / FooWeakPtr. I would love to avoid re-writing that logic, any suggestions?

 

4) I would like TfWeakPtr to be wrapped out as a weak reference in C#. I'm not sure if it should literally be NET's WeakReference<T>, but I want to correctly surface the weak-pointer-ness. Any guidance there?

 

5) The C++ class hierarchy is kind of... intricate (involving CRTP and several layers of base classes/templates) -- how much of that do I need to expose to SWIG? Can I get away with making a proxy class that has some limited set of public members and no base classes?

 

 

And most importantly: thanks for making and maintaining such an awesome tool! :D

 

--

Jeremy

 


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________



Digital Barriers are world leaders in visually intelligent solutions for the global surveillance, security and safety markets, specialising in zero-latency streaming and analysis of secure video and related intelligence over wireless networks, including cellular, satellite, IP mesh and cloud. www.digitalbarriers.com Digital Barriers e-Mail Confidentiality and Disclaimer This message contains confidential information and is intended only for the individual named. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. Digital Barriers plc is a company registered in England and Wales. Registered number: 7149547. Registered office: Cargo Works, 1-2 Hatfields, London SE1 9PG, United Kingdom. For further information about Digital Barriers, please visit www.digitalbarriers.com.
______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

------------------------------------------------------------------------------

_______________________________________________
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: Wrapping a custom smart pointer

Schlimbach, Frank
In reply to this post by Jeremy Cowles
Most of the shared_ptr logic you care about is probably in the typemaps (Lib/shared_ptr.i). We had a similar problem with our own shared-ptr implementation (but not for C#). I copied this file and adjusted the names (of namespaces and shared_ptr class) so that it works with our stuff (and of course I include the new interface-file file instead of the standard one). This works with only little modifications because the interfaces of the shared_ptr implementations are sufficiently similar.

Generally I suggest you consider using the C++11 shared pointer, though.

frank

-----

Message: 3
Date: Thu, 15 Sep 2016 08:14:44 +0000
From: Andrew Haining <[hidden email]>
Subject: Re: [Swig-user] Wrapping a custom smart pointer
To: "[hidden email]"
        <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="utf-8"

I can?t really speak to points 1, 2 & 3. I haven?t looked into the shared_ptr implementation since I don?t use it but. But regarding points 4 & 5 here are my thoughts:
4.) It?s perfectly OK to wrap a weak pointer just as you would any other object, it imbues itself with weakness, taking a weak reference to a weak pointer doesn?t really make sense.
5.) I think it?s best to expose the cleanest interface you can, the .i doesn?t really need to resemble the header at all, except that the things it does define need to be in the class, removing functions or Base classes you don?t want to wrap is all perfectly acceptable. At the end of the day the generated code is just going to call the function you said was there, it (mostly) doesn?t really care about anything else. I also use CRTP and obfuscate it from SWIG for example.

From: Jeremy Cowles [mailto:[hidden email]]
Sent: 14 September 2016 17:26
To: [hidden email]
Subject: [Swig-user] Wrapping a custom smart pointer

Hi swig-users,

I'm new to SWIG and want to wrap a fairly complex custom smart pointer (to C# and, perhaps later, to Go), so I started reading the typemap docs and looking at the standard smart_ptr library source and now I have some questions:

1) What triggers the auto-magic smart pointer internals? From other threads, I realize that the logic is baked into the SWIG executable and from the docs I understand that SWIG is attempting to detect smart pointers, but curious exactly how it's being triggered.

2) Perhaps related, what is this line doing in lib/shared_ptr.h?

%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }

3) The smart pointer I need to wrap doesn't match the <NAMESPACE>::<SUBNAMESPACE>::shared_ptr naming pattern and has slightly different semantics and API, so I think I'm going to write something very similar. The pointers typically take this form: TfRefPtr<Foo> which gets typedef'd to FooRefPtr (similarly FooConstRefPtr) as well as TfWeakPtr<Foo> / FooWeakPtr. I would love to avoid re-writing that logic, any suggestions?

4) I would like TfWeakPtr to be wrapped out as a weak reference in C#. I'm not sure if it should literally be NET's WeakReference<T>, but I want to correctly surface the weak-pointer-ness. Any guidance there?

5) The C++ class hierarchy is kind of... intricate (involving CRTP and several layers of base classes/templates) -- how much of that do I need to expose to SWIG? Can I get away with making a proxy class that has some limited set of public members and no base classes?


And most importantly: thanks for making and maintaining such an awesome tool! :D

--
Jeremy


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com ______________________________________________________________________

________________________________
Digital Barriers are world leaders in visually intelligent solutions for the global surveillance, security and safety markets, specialising in zero-latency streaming and analysis of secure video and related intelligence over wireless networks, including cellular, satellite, IP mesh and cloud. www.digitalbarriers.com Digital Barriers e-Mail Confidentiality and Disclaimer This message contains confidential information and is intended only for the individual named. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. Digital Barriers plc is a company registered in England and Wales. Registered number: 7149547. Registered office: Cargo Works, 1-2 Hatfields, London SE1 9PG, United Kingdom. For further information about Digital Barriers, please visit www.digitalbarriers.com.

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com ______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

------------------------------------------------------------------------------


------------------------------

_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user


End of Swig-user Digest, Vol 124, Issue 8
*****************************************
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


------------------------------------------------------------------------------
_______________________________________________
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: Wrapping a custom smart pointer

Jeremy Cowles
I had a chance to play with swig a bit more this weekend and now it all makes sense.

I got my weak and shared pointers working and converting in a desirable way, but now I'm realizing that the shared pointer is really just an object instance in C#, so I might try to just have instances of Foo and FooWeakPtr.

I also need to figure out how to wrap a variant class (very similar to boost::any<T>).

One thing I've found difficult (even after RTFM) is figuring out what typemaps effect what output and what local variables and helper functions should be used. Also the required order of typemaps and class declarations is totally mysterious to me and one of my bigger stumbling blocks.

So no new questions, but any tips would be super welcome!

Thanks!

On Thu, Sep 15, 2016 at 1:44 AM Schlimbach, Frank <[hidden email]> wrote:
Most of the shared_ptr logic you care about is probably in the typemaps (Lib/shared_ptr.i). We had a similar problem with our own shared-ptr implementation (but not for C#). I copied this file and adjusted the names (of namespaces and shared_ptr class) so that it works with our stuff (and of course I include the new interface-file file instead of the standard one). This works with only little modifications because the interfaces of the shared_ptr implementations are sufficiently similar.

Generally I suggest you consider using the C++11 shared pointer, though.

frank

-----

Message: 3
Date: Thu, 15 Sep 2016 08:14:44 +0000
From: Andrew Haining <[hidden email]>
Subject: Re: [Swig-user] Wrapping a custom smart pointer
To: "[hidden email]"
        <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="utf-8"

I can?t really speak to points 1, 2 & 3. I haven?t looked into the shared_ptr implementation since I don?t use it but. But regarding points 4 & 5 here are my thoughts:
4.) It?s perfectly OK to wrap a weak pointer just as you would any other object, it imbues itself with weakness, taking a weak reference to a weak pointer doesn?t really make sense.
5.) I think it?s best to expose the cleanest interface you can, the .i doesn?t really need to resemble the header at all, except that the things it does define need to be in the class, removing functions or Base classes you don?t want to wrap is all perfectly acceptable. At the end of the day the generated code is just going to call the function you said was there, it (mostly) doesn?t really care about anything else. I also use CRTP and obfuscate it from SWIG for example.

From: Jeremy Cowles [mailto:[hidden email]]
Sent: 14 September 2016 17:26
To: [hidden email]
Subject: [Swig-user] Wrapping a custom smart pointer

Hi swig-users,

I'm new to SWIG and want to wrap a fairly complex custom smart pointer (to C# and, perhaps later, to Go), so I started reading the typemap docs and looking at the standard smart_ptr library source and now I have some questions:

1) What triggers the auto-magic smart pointer internals? From other threads, I realize that the logic is baked into the SWIG executable and from the docs I understand that SWIG is attempting to detect smart pointers, but curious exactly how it's being triggered.

2) Perhaps related, what is this line doing in lib/shared_ptr.h?

%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }

3) The smart pointer I need to wrap doesn't match the <NAMESPACE>::<SUBNAMESPACE>::shared_ptr naming pattern and has slightly different semantics and API, so I think I'm going to write something very similar. The pointers typically take this form: TfRefPtr<Foo> which gets typedef'd to FooRefPtr (similarly FooConstRefPtr) as well as TfWeakPtr<Foo> / FooWeakPtr. I would love to avoid re-writing that logic, any suggestions?

4) I would like TfWeakPtr to be wrapped out as a weak reference in C#. I'm not sure if it should literally be NET's WeakReference<T>, but I want to correctly surface the weak-pointer-ness. Any guidance there?

5) The C++ class hierarchy is kind of... intricate (involving CRTP and several layers of base classes/templates) -- how much of that do I need to expose to SWIG? Can I get away with making a proxy class that has some limited set of public members and no base classes?


And most importantly: thanks for making and maintaining such an awesome tool! :D

--
Jeremy


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com ______________________________________________________________________

________________________________
Digital Barriers are world leaders in visually intelligent solutions for the global surveillance, security and safety markets, specialising in zero-latency streaming and analysis of secure video and related intelligence over wireless networks, including cellular, satellite, IP mesh and cloud. www.digitalbarriers.com Digital Barriers e-Mail Confidentiality and Disclaimer This message contains confidential information and is intended only for the individual named. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. Digital Barriers plc is a company registered in England and Wales. Registered number: 7149547. Registered office: Cargo Works, 1-2 Hatfields, London SE1 9PG, United Kingdom. For further information about Digital Barriers, please visit www.digitalbarriers.com.

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com ______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

------------------------------------------------------------------------------


------------------------------

_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user


End of Swig-user Digest, Vol 124, Issue 8
*****************************************
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user

------------------------------------------------------------------------------

_______________________________________________
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

Multimap typemap for C#

RAVI NANJUNDAPPA
In reply to this post by Schlimbach, Frank
Hi All,

Can anyone provide me the example code for multimap ( to covert from String[] to argc & argv) for C# ?


Thanks and Best Regards,
N Ravi
 
------------------------------------------------------------------------------

_______________________________________________
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: Multimap typemap for C#

RAVI NANJUNDAPPA
In reply to this post by Schlimbach, Frank
Hi,

Can anyone help us in getting this multimap example working for csharp ?

Thanks and Best Regards,
N Ravi
 
 
--------- Original Message ---------
Sender : RAVI NANJUNDAPPA <[hidden email]> Chief Engineer/SRI-Bangalore-Advanced Web/Samsung Electronics
Date   : 2016-09-21 17:38 (GMT+5:30)
Title  : [Swig-user]  Multimap typemap for C#
 
Hi All, 
 
Can anyone provide me the example code for multimap ( to covert from String[] to argc & argv) for C# ?
 
 
Thanks and Best Regards, 
N Ravi
 
------------------------------------------------------------------------------
 
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
 
------------------------------------------------------------------------------

_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...