Skip to content
Snippets Groups Projects
Commit 9be4fa3d authored by Wilson Jallet's avatar Wilson Jallet :clapper:
Browse files

tests/python: use old-style call to parent ctor

parent 43022a1e
No related branches found
No related tags found
No related merge requests found
Pipeline #27435 passed with warnings
...@@ -24,7 +24,7 @@ struct MyVirtualClass { ...@@ -24,7 +24,7 @@ struct MyVirtualClass {
}; };
struct MyVirtualData { struct MyVirtualData {
MyVirtualData(MyVirtualClass const&) {} MyVirtualData(MyVirtualClass const &) {}
virtual ~MyVirtualData() {} // virtual dtor to mark class as polymorphic virtual ~MyVirtualData() {} // virtual dtor to mark class as polymorphic
}; };
...@@ -84,8 +84,9 @@ struct VirtualClassWrapper : MyVirtualClass, bp::wrapper<MyVirtualClass> { ...@@ -84,8 +84,9 @@ struct VirtualClassWrapper : MyVirtualClass, bp::wrapper<MyVirtualClass> {
/// This "trampoline class" does nothing but is ABSOLUTELY required to ensure /// This "trampoline class" does nothing but is ABSOLUTELY required to ensure
/// downcasting works properly with non-smart ptr signatures. Otherwise, /// downcasting works properly with non-smart ptr signatures. Otherwise,
/// there is no handle to the original Python object ( @c PyObject *). /// there is no handle to the original Python object ( @c PyObject *).
/// Every single polymorphic type exposed to Python should be exposed through such a trampoline. /// Every single polymorphic type exposed to Python should be exposed through
/// Users can also create their own wrapper classes by taking inspiration from boost::python::wrapper<T>. /// such a trampoline. Users can also create their own wrapper classes by taking
/// inspiration from boost::python::wrapper<T>.
struct DataWrapper : MyVirtualData, bp::wrapper<MyVirtualData> { struct DataWrapper : MyVirtualData, bp::wrapper<MyVirtualData> {
/// we have to use-declare non-defaulted constructors /// we have to use-declare non-defaulted constructors
/// (see https://en.cppreference.com/w/cpp/language/default_constructor) /// (see https://en.cppreference.com/w/cpp/language/default_constructor)
...@@ -99,7 +100,8 @@ const MyVirtualData &iden_ref(const MyVirtualData &d) { ...@@ -99,7 +100,8 @@ const MyVirtualData &iden_ref(const MyVirtualData &d) {
return d; return d;
} }
/// Take a shared_ptr (by const reference or value, doesn't matter), return by const reference /// Take a shared_ptr (by const reference or value, doesn't matter), return by
/// const reference
const MyVirtualData &iden_shared(const shared_ptr<MyVirtualData> &d) { const MyVirtualData &iden_shared(const shared_ptr<MyVirtualData> &d) {
// get boost.python's custom deleter // get boost.python's custom deleter
// boost.python hides the handle to the original object in there // boost.python hides the handle to the original object in there
...@@ -136,7 +138,7 @@ BOOST_PYTHON_MODULE(bind_virtual_factory) { ...@@ -136,7 +138,7 @@ BOOST_PYTHON_MODULE(bind_virtual_factory) {
/// otherwise if passed as "HeldType", we need to define /// otherwise if passed as "HeldType", we need to define
/// the constructor and call initializer manually. /// the constructor and call initializer manually.
bp::class_<DataWrapper, boost::noncopyable>("MyVirtualData", bp::no_init) bp::class_<DataWrapper, boost::noncopyable>("MyVirtualData", bp::no_init)
.def(bp::init<MyVirtualClass const&>(bp::args("self", "model"))); .def(bp::init<MyVirtualClass const &>(bp::args("self", "model")));
bp::def("callDoSomethingPtr", callDoSomethingPtr, bp::args("obj")); bp::def("callDoSomethingPtr", callDoSomethingPtr, bp::args("obj"));
bp::def("callDoSomethingRef", callDoSomethingRef, bp::args("obj")); bp::def("callDoSomethingRef", callDoSomethingRef, bp::args("obj"));
......
...@@ -4,7 +4,7 @@ import bind_virtual_factory as bvf ...@@ -4,7 +4,7 @@ import bind_virtual_factory as bvf
class ImplClass(bvf.MyVirtualClass): class ImplClass(bvf.MyVirtualClass):
def __init__(self): def __init__(self):
self.val = 42 self.val = 42
super().__init__() bvf.MyVirtualClass.__init__(self)
def createData(self): def createData(self):
return ImplData(self) return ImplData(self)
...@@ -27,7 +27,8 @@ class ImplClass(bvf.MyVirtualClass): ...@@ -27,7 +27,8 @@ class ImplClass(bvf.MyVirtualClass):
class ImplData(bvf.MyVirtualData): class ImplData(bvf.MyVirtualData):
def __init__(self, c): def __init__(self, c):
super().__init__(c) # parent virtual class requires arg # parent virtual class requires arg
bvf.MyVirtualData.__init__(self, c)
self.value = c.val self.value = c.val
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment