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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of "Bernhard Mäder"
Sent: Sunday, December 31, 2006 9:15 AM
To: [email protected]
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
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to