On Fri, 24 May 2013 02:59:24 +0600, Wichert Akkerman <
wic...@wiggy.net>
wrote:
> I have a fairly typical API where I have a public pure virtual class
> with a
> factory method that returns an implementation. It looks like this:
>
> class User {
> public:
> static boost::shared_ptr<User*> create() ;
> };
>
> I can't find any hints in the documentation how you would wrap this in
> Cython.
Is this
http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#static-member-method
the hint you are looking for?
Your code should look like:
cdef extern from "boost/shared_ptr.hpp" namespace "boost":
cppclass shared_ptr[T]:
T* get()
# Note: operator->, operator= are not supported
cdef extern from "YourHeader.h" namespace "yournamespace":
cppclass User:
... # non static User methods here
cdef extern from "YourHeader.h" namespace "yournamespace::User":
# static user methods here, note the renaming
shared_ptr[User*] User_create "create"()
cdef shared_ptr[User*] user = User_create()
BTW shouldn't your code be using shared_ptr<User> instead of
shared_ptr<User*> ?
Smart pointer to a pointer makes little sense.
Best regards,
Nikita Nemkin