Re: [pygccxml-development] Wrapping virtual functions only
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2009-03-09 20:12:44
|
On Mon, Mar 9, 2009 at 9:05 PM, Kevin Atkinson <kev...@gm...> wrote: > Hi there, Roman et al, Good evening. > First of all, thanks for the lovely tool. I've created many python > wrappers, with varying degrees of automation, and it looks like PY++ is what > I should have been using all along. Thank you! > I've been getting some behaviour I don't understand with the include and > exclude methods in PY++. I am trying to create a wrapper for Qt 4.5. Qt > has a nice reflection API with allows creating a very minimal generic > wrapper that will work for most things -- invoking methods, getting and > setting properties. The one thing you can't do is override virtual methods > in python and have them get called from C++. > > To remedy that, the wrappings will only wrap virtual methods on classes > derived from QObject. (Objects not derived from QObject don't support the > Qt reflection methods and so have to be conventionally wrapped). > > I'm testing with the following classes: > > class A > { > public: > void g() { printf("A::g()\n"); } > virtual void foo() = 0; > }; > > class B : public A > { > virtual void foo() { printf("B:foo()\n"); } > }; > > void free_func(A *a) > { > a->foo(); > } Let me to summarize what we have here: class A has two *public* functions: g - regular function ( virtuality == "not virtual" ) foo - pure virtual function ( virtuality == "pure virtual" ) class B has single *private* virtual function "foo" > When I do this: > > virtual_funcs = mb.member_functions(function=lambda > decl:decl.virtuality=='virtual').include() You can print the result of the statement. The only function you will see is: B::foo > Py++ adds the non-virtual function g as well: > ... By default, Py++ exports all "declarations" from the directory, where the source file is. It is explained here: http://www.language-binding.net/pyplusplus/documentation/tutorials/module_builder/module_builder.html#declarations-customization > If I do this: > > mb.member_functions(function=lambda decl:decl.virtuality == "virtual").include() So, you select private B::foo function and include it. Py++ will not expose it, because it is private and not pure virtual. > mb.member_functions(function=lambda decl:decl.virtuality != "virtual").exclude() Here, you select A::foo and A::g and exclude them > It doesn't add any member functions at all: I hope, now it is clear why. What you really want is to write: mb.member_functions(function=lambda decl:decl.virtuality == "not virtual").exclude() > Many apologies if I doing something really stupid. No need. You provided very detailed description and even me it took some time to understand what was going on. > Just in case, here's the whole py++ file: > ... I hope, it was clear. If not come back. I will be glad to see Qt exposed to Python using Boost Python and Py++. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |