[IronPython] Exposing C++/CLI template classes to ironpython

"Bernhard Mäder" NoNuschk at gmx.net
Thu Jan 11 21:00:40 CET 2007


Thanks for the answer! 

-------- Original-Nachricht --------
Datum: Thu, 4 Jan 2007 13:06:36 -0800
Von: Dino Viehland <dinov at exchange.microsoft.com>
An: Discussion of IronPython <users at lists.ironpython.com>
Betreff: Re: [IronPython] Exposing C++/CLI template classes to ironpython

> Unfortunately you can't the CPython extension libraries w/ IronPython. 
> You could do it w/ templates instead of macros and force the instantiation of
> the generic public class like:
> 
> template<typename T> class NativeData {
> public:
>         T foo;
> };
> 
> template<typename T> public ref class GenericData {
> private:
>         NativeData<T> *data;
> };
> 
> public ref class GDI : GenericData<int> {};
> public ref class GDC : GenericData<char> {};
> 
> That seems to export both the GenericData<int> and GenericData<char> types
> (even if GDI/GDC are private) though maybe there's a better way to force
> the GenericData<x> type to get exported.

You're right, it's definitely a good thing to NOT use macros. :-)

I'm now doing something similar to the scheme you provided. But I need to have additional marshalling stuff to get from the wrapper back to the native classes (and vice-versa). This tends to lead to quite some boilerplate code, but I'm willing to take that.

Three more questings though:

1) In your example, GenericData<> only exports those functions that are declared virtual or used somewhere in the code. I guess that's something C++/CLI specific, but is there a way to circumvent this?

2) The [Pythonname] attribute doesn't seem to work for me. When, e.g., I'm deriving from ISequence, the AddSequence() method does not become __add__ in python. What can possibly go wrong there? Are these attributes even intended as public interfaces?

3) Is there an easy way to add free standing functions? Currently, I'm doing this by either adding delegates, using a callable object or creating static methods in a class. Delegates are very difficult to use in a generic way and static methods are difficult to separate into different compiler-units, so I'm mostly using callable objects. 

Thanks!
Bernhard

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer



More information about the Ironpython-users mailing list