Re: [pygccxml-development] virtual functions without wrappers
Brought to you by:
mbaas,
roman_yakovenko
From: Neal B. <ndb...@gm...> - 2006-08-25 11:42:33
|
On Friday 25 August 2006 4:41 am, Matthias Baas wrote: > Neal Becker wrote: > > I am playing with pyplusplus, trying out pypp_api. I noticed that a > > class with virtual functions and inheritance used wrappers, as shown in > > the boost::python tutorial. > > > > I would like to have to option to bypass these wrappers. IIUC, wrappers > > are only needed if the function will be overidden in python and then > > called from c++. My intention is a class hierarchy implemented in c++ > > only that is called from python. > > > > Here is a typical example: > > > > struct base { virtual void F() = 0; }; > > > > struct impl_1 : base { virtual void F() { do something; } }; > > > > struct X { > > X (boost::shared_ptr<base> _p) : p (_p) {} > > boost::shared_ptr<base> p; > > void use_F () { (*p)->F(); } > > }; > > > > In python then: > > > > i = impl_1() > > x = X (i) > > x.use_F() > > I think what you're looking for is the "finalize" functionality which > would tell Py++ that wrappers are not required. I'm not entirely sure, > but I believe this functionality is currently not properly supported by > Py++ (Roman has to give a definite answer here). > > If you don't have to call F() from Python then a simple workaround would > be to ignore that method (but again, I'm not sure if this will prevent > Py++ from generating the wrapper class). > > - Matthias - > > Actually, it appears that I don't really need to do anything. I don't care so much about generating wrappers, I just didn't want the overhead of using them. Looking at the generated code, it seems that I needn't be concerned. It appears that a call from c++ to the virtual function does not use the wrapper but goes direct: struct A { virtual int F () const = 0; }; struct B : public A { virtual int F () const { return 1; } }; struct Z { Z (boost::shared_ptr<A> _a ) : a (_a) {} int use_F() { return a->F(); } boost::shared_ptr<A> a; }; bp::class_< Z >( "Z", bp::init< boost::shared_ptr<A> >(( bp::arg("_a") )) [bp::default_call_policies()] ) .def( "use_F" , &::Z::use_F , bp::default_call_policies() ) .def_readwrite( "a", &Z::a ); |