Re: [pygccxml-development] Cannot exclude inherited virtual methods
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2009-02-19 05:05:45
|
On Thu, Feb 19, 2009 at 1:57 AM, Patrick Hartling <pat...@pr...> wrote: > I have a case where a base class defines virtual methods that are inherited > by a derived class. I need to be able to exclude at least one of the virtual > methods from the generated Boost.Python code for the derived class, but I > cannot figure out how to do it. If I understand correctly, I am having > problems because the virtual methods are not overridden by the derived > class, and thus they are not part of the > pyplusplus.decl_wrappers.class_wrapper.class_t object for the derived class. > > I have attached a header file and Py++ script that demonstrate the issue. Is > there some way for me to apply a customization to the class wrapper's > inherited virtual methods for the derived object? I am using r1669 of the > pygccxml trunk and GCC 0.9 (1.127). I am not sure, I understand you correctly. The following is the code generated by Py++. Please change it so I could understand what you want. #include "boost/python.hpp" namespace bp = boost::python; struct Base_wrapper : Base, bp::wrapper< Base > { Base_wrapper(Base const & arg ) : Base( arg ) , bp::wrapper< Base >(){ // copy constructor } Base_wrapper() : Base() , bp::wrapper< Base >(){ // null constructor } virtual void f( int v ) { if( bp::override func_f = this->get_override( "f" ) ) func_f( v ); else this->Base::f( v ); } void default_f( int v ) { Base::f( v ); } virtual void f( float v ) { if( bp::override func_f = this->get_override( "f" ) ) func_f( v ); else this->Base::f( v ); } void default_f( float v ) { Base::f( v ); } }; struct Derived_wrapper : Derived, bp::wrapper< Derived > { Derived_wrapper(Derived const & arg ) : Derived( arg ) , bp::wrapper< Derived >(){ // copy constructor } Derived_wrapper() : Derived() , bp::wrapper< Derived >(){ // null constructor } virtual void f( int v ) { if( bp::override func_f = this->get_override( "f" ) ) func_f( v ); else this->Base::f( v ); } void default_f( int v ) { Base::f( v ); } virtual void f( float v ) { if( bp::override func_f = this->get_override( "f" ) ) func_f( v ); else this->Base::f( v ); } void default_f( float v ) { Base::f( v ); } }; BOOST_PYTHON_MODULE(pyplusplus){ bp::class_< Base_wrapper >( "Base" ) .def( "f" , (void ( ::Base::* )( int ) )(&::Base::f) , (void ( Base_wrapper::* )( int ) )(&Base_wrapper::default_f) , ( bp::arg("v") ) ) .def( "f" , (void ( ::Base::* )( float ) )(&::Base::f) , (void ( Base_wrapper::* )( float ) )(&Base_wrapper::default_f) , ( bp::arg("v") ) ); bp::class_< Derived_wrapper, bp::bases< Base > >( "Derived" ) .def( "f" , (void ( ::Base::* )( int ) )(&::Base::f) , (void ( Derived_wrapper::* )( int ) )(&Derived_wrapper::default_f) , ( bp::arg("v") ) ) .def( "f" , (void ( ::Base::* )( float ) )(&::Base::f) , (void ( Derived_wrapper::* )( float ) )(&Derived_wrapper::default_f) , ( bp::arg("v") ) ); } -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |