wrapping abstract classes question
Hi. What is the right way to wrap next abstract classes? struct base{ virtual int do_smth() = 0; }; struct derived : base{ virtual int do_smth_else() = 0; }; It is obvious to me that I should create wrapper classes for base and derived. My question is what is definition of derived wrapper? struct base_wrapper : base, boost::python::wrapper< base > { ... } The are 2 approaches to create wrapper for derived class 1. struct derived_wrapper : derived, boost::python::wrapper< derived >{ virtual int do_smth( ){ boost::python::override do_smth = this->get_override( "do_smth" ); return do_smth( ); } virtual int do_smth_else( ){ boost::python::override do_smth_else = this->get_override( "do_smth_else" ); return do_smth_else( ); } } 2. struct derived_wrapper : derived, base_wrapper, boost::python::wrapper< derived >{ virtual int do_smth_else( ){ boost::python::override do_smth_else = this->get_override( "do_smth_else" ); return do_smth_else( ); } } It seems to me that both approaches will work, but I do not know which one is better ( right ) and which one is not. Thanks for help. Roman Yakovenko
Roman Yakovenko <roman.yakovenko@gmail.com> writes:
The are 2 approaches to create wrapper for derived class 1.
struct derived_wrapper : derived, boost::python::wrapper< derived >{
virtual int do_smth( ){ boost::python::override do_smth = this->get_override( "do_smth" ); return do_smth( ); }
virtual int do_smth_else( ){ boost::python::override do_smth_else = this->get_override( "do_smth_else" ); return do_smth_else( ); }
}
2.
struct derived_wrapper : derived, base_wrapper, boost::python::wrapper< derived >{
virtual int do_smth_else( ){ boost::python::override do_smth_else = this->get_override( "do_smth_else" ); return do_smth_else( ); }
}
It seems to me that both approaches will work, but I do not know which one is better ( right ) and which one is not.
This one is tricky. I think this is probably the best you can do. template <class B> struct wrap_base : B { int do_smth() { return this->get_override("do_smth")(); }; }; struct base_wrapper : wrap_base<base>, boost::python::wrapper<base> { }; struct derived_wrapper : wrap_base<derived>, boost::python::wrapper<derived> { int do_smth_else() { return this->get_override("do_smth_else")(); }; }; HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams -
Roman Yakovenko