Re: [Cython] [Pyrex] C++ issue

Robert Bradshaw <[email protected]>
Newsgroups gmane.comp.python.cython.devel,gmane.comp.python.pyrex
Message-ID <[email protected]>
In this case you might want to declare your variable to be *pointers*  
to the given classes, rather than the classes themselves. This will  
prevent c++ from trying to create them directly where the are  
declared (though you will then have to manually delete them when  
you're done with them).

- Robert

On Apr 28, 2008, at 9:26 AM, Ravi Lanka wrote:
> Pyrex gurus,
>
>   I am trying to wrap a C++ library and have been successful for the
> most part (thanks to you guys).  One of the classes that I need to  
> wrap
> does not contain a default constructor (see code below ).  The cpp  
> file
> that gets created complains that "foo" does not contain a default
> constructor [ cdef foo f  is invalid ].  At the same time, I cannot  
> say
> "cdef foo f = b.getFoo()". My solution was to build the cpp file from
> the pyrex code below and then create a line that says;
>
> cdef foo f = b.getFoo() instead of  "f = b.getFoo",
>
> and remove the initial declaration.  It works for what I am doing,  
> but I
> am afraid that there could be some reference count issues.
> Unfortunately, the argument required by the constructor of foo  
> class is
> neither required nor available in my wrapper code.
>
> Any Ideas ?
> thanks in advance.
>
> Ravi
>
> ------------------
> class foo {
>     public:
>         foo( templatedClassObject  unAvailable );
>         int (*getItems) { return 1; }
> };
>
> class bar {
>     public:
>         bar();
>         foo& getFoo() { return fooObj; }
> };
>
> pyrex:
>
> cdef extern from "foo.h":
>     ctypedef struct foo "foo":
>         int (*getItems)()
>
> cdef extern from "bar.h":
>     ctypedef struct bar "bar":
>         foo (*getFoo)()
>
>     bar *barFactory "new bar"()
>     void deleteBar "delete "(bar *barObj)
>
> def test():
>     cdef    bar   b
>     cdef    foo   f
>     ### b is populated through some calculations here
>     f = b.getFoo()
> -------------------------
>
>
> _______________________________________________
> Pyrex mailing list
> [email protected]
> http://lists.copyleft.no/mailman/listinfo/pyrex
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.