Re: [pygccxml-development] Cannot exclude inherited virtual methods
Brought to you by:
mbaas,
roman_yakovenko
From: Patrick H. <pat...@pr...> - 2009-02-19 14:16:44
|
Roman Yakovenko wrote: > 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. What I would like to see is the following generated by Py++: #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 ); } }; 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, bp::bases< Base > >( "Derived" ) .def( "f" , (void ( ::Base::* )( int ) )(&::Base::f) , ( bp::arg("v") ) ) .def( "f" , (void ( ::Base::* )( float ) )(&::Base::f) , ( bp::arg("v") ) ); } I have three goals: 1. Expose Base in a manner that allows its virtual methods to be overridden by a Python subclass. 2. Expose Derived in a manner that *does not* allow its virtual methods to be overridden by a Python subclass. 3. Prevent the exposure of an inherited, non-overridden virtual method with a signature that does not work well with Python. The third item was not expressed in my original message or in the code example because I wanted to focus on being able to exclude an inherited virtual method with no override. That seems to me to be the fundamental issue that I am seeing. I can exclude virtual methods for Base, but those that are inherited by Derived and not overridden seem beyond my reach for excluding. -Patrick -- Patrick L. Hartling Senior Software Engineer, Priority 5 http://www.priority5.com/ The information transmitted in this communication is intended only for the person or entity to which it is addressed and contains proprietary material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please destroy any copies, contact the sender and delete the material from any computer. |