[IronPython] Exposing C++/CLI template classes to ironpython
Dino Viehland
dinov at exchange.microsoft.com
Thu Jan 4 22:06:36 CET 2007
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.
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of "Bernhard Mäder"
Sent: Sunday, December 31, 2006 9:15 AM
To: users at lists.ironpython.com
Subject: [IronPython] Exposing C++/CLI template classes to ironpython
Hello all
I'm starting to work with ironpython and have successfully exported some .NET classes into an extension library.
Now I'm trying to get some C++ template classes to work with ironpython. I'm doing something like this:
// This is our C++ class.
template<typename T> struct cpp_klass
{
T foo() { return T(); }
}
// This wraps the class for a specific T
public ref class klass_uint8
{
typedef cpp_klass<unsigned char> klass_t;
klass_t * _klass;
klass_uint8() : _klass(new klass_t()) {};
~klass_uint8() {delete _klass;}
unsigned char foo()
{
return _klass.foo();
}
};
This works but has do be done for each version of T. I'm about to write a big macro that does it for all cpp_class<T> versions, but don't think this will be a nice solution... Is there a better way to do it?
Or would it be possible to load CPython extension DLLs with ironpython? If yes, I could use boost.python to get the exports done.
Thanks for any help!
cheers
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
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list