Re: [pygccxml-development] Cannot exclude inherited virtual methods
Brought to you by:
mbaas,
roman_yakovenko
From: Patrick H. <pat...@pr...> - 2009-02-19 17:50:08
|
Roman Yakovenko wrote: > On Thu, Feb 19, 2009 at 4:17 PM, Patrick Hartling > <pat...@pr...> wrote: >> 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. > > This is what you already have . > >> 2. Expose Derived in a manner that *does not* allow its virtual methods to >> be overridden by a Python subclass. > > Py++ doesn't allow to do this and it is not simple to achieve in > general use case. For example, if Base class has pure virtual method, > the wrapper should be generated. > >> 3. Prevent the exposure of an inherited, non-overridden virtual method with >> a signature that does not work well with Python. > > For this case, Py++ introduces "Function Transformation" feature, > which works fine for all public member functions, even pure virtual > http://language-binding.net/pyplusplus/documentation/functions/transformation/transformation.html?highlight=function%20transformation We are using function transformations elsewhere, but this case would have required a custom transformer. Since it is very isolated (basically 1 class out of over 500), I just wanted to handle it in as simple a manner as possible. I thought that that would be excluding the method, but that turned out to be more involved than I had expected. >> 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. > > There is no "clean" way to achieve this, but try to take a look on > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/decl_wrappers/class_wrapper.py?revision=1664&view=markup > redefined_funcs function. > > It returns reference to list, which contains all function that should > be redefined in the class wrapper. Try to delete it content. Ah, I didn't think of that. I was trying to come up with ways to force the cached list to be rebuilt, but modifying it directly by removing the desired items is far more effective. Thanks for the tip. -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. |