Hi Robert,

On Sat, Apr 25, 2009 at 2:12 PM, Robert Bradshaw
<rober...@math.washington.edu> wrote:
>
> This summer Danilo Freitas got accepted to work on better C++ support
> for Cython as a GSoC project. This is a great opportunity to make it
> easier to wrap and use C++ code from Python. We are still in the
> planning stages, and I want to get input from those who've used both:
> what do you want to see by the end of the summer? Taken to the limit,
> this could be much longer than a summer project, so we're looking for
> direction from the community to focus our energy and direction. The
> two questions I'm most interested in are
>
> 1) Do you have any priorities for features you'd like to see sooner
> rather than later?
>
> 2) What would be *your* preferred syntax for declaring a templated,
> operator-overloading class in C++?

thanks for doing it. I have couple ideas, that would make my life
easier, I would be interested in your feedback.

Currently when I want to wrap a C++ class, I first have to create the
definitions:

http://github.com/certik/hermes2d/blob/b4ddf0e825180f1360304d93cd3a081ba22b101e/python/hermes2d/hermes2d.pxd#L146

e.g.  in pxd:

    cdef struct c_WeakForm "WeakForm":
        void add_biform(int i, int j, ...)
        void add_biform_surf(int i, int j, ...)
        void add_liform(int i, ...)
        void add_liform_data(int i, void *data)
        void add_liform_surf(int i, ...)
    c_WeakForm *new_WeakForm "new WeakForm" (int neq)

cdef class WeakForm:
    cdef c_WeakForm *thisptr

Then one has to construct the actual class:

http://github.com/certik/hermes2d/blob/b4ddf0e825180f1360304d93cd3a081ba22b101e/python/hermes2d/hermes2d.pyx#L223

e.g. in pyx:

cdef class WeakForm:

    def __cinit__(self, int neq=1):
        self.thisptr = new_WeakForm(neq)

    def __dealloc__(self):
        delete(self.thisptr)




So when I am exposing a new class, i it's quite a lot of typing,
especially the name of the C++ class has to be copied over and over
again (e.g. in the definition of the new constructor, etc). Compared
to swig, it was much easier to do it in swig, where you basically just
copy the C++ header file and swig does the rest. That said, the Cython
way is of course much cleaner in the end, once I have it written
already.


Another area of improvement is that if the C++ contains hierarchy of
classes, I need to store a pointer to for example the ancestor and
then retype it everytime I want to use it in subclasses, like here:


http://github.com/certik/hermes2d/blob/b4ddf0e825180f1360304d93cd3a081ba22b101e/python/hermes2d/hermes2d.pyx#L125


it'd be nice to have some easier way to handle C++ subclasses in
Cython. I don't know how it should be done though.

Ondrej

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to