22 return std::make_shared<MyVirtualData>(*this);
33 printf(
"Created MyVirtualData with address %p\n", (
void *)d.get());
40 printf(
"Created MyVirtualData with address %p\n", (
void *)d.get());
46 throw std::runtime_error(
"Called C++ virtual function.");
52 if (bp::override fo = this->get_override(
"doSomethingPtr")) {
67 if (bp::override fo = this->get_override(
"doSomethingRef")) {
75 if (bp::override fo = this->get_override(
"createData"))
return fo();
76 return default_createData();
109 auto *dter = std::get_deleter<bp::converter::shared_ptr_deleter>(d);
110 if (dter != 0) printf(
"> input shared_ptr has a deleter\n");
115 shared_ptr<MyVirtualData>
copy_shared(
const shared_ptr<MyVirtualData> &d) {
116 auto *dter = std::get_deleter<bp::converter::shared_ptr_deleter>(d);
117 if (dter != 0) printf(
"> input shared_ptr has a deleter\n");
123 "MyVirtualClass should be polymorphic!");
125 "MyVirtualData should be polymorphic!");
127 bp::class_<VirtualClassWrapper, boost::noncopyable>(
128 "MyVirtualClass", bp::init<>(bp::args(
"self")))
130 bp::args(
"self",
"data"))
132 bp::args(
"self",
"data"))
136 bp::register_ptr_to_python<shared_ptr<MyVirtualData> >();
140 bp::class_<DataWrapper, boost::noncopyable>(
"MyVirtualData", bp::no_init)
141 .def(bp::init<MyVirtualClass const &>(bp::args(
"self",
"model")));
146 bp::def(
"iden_ref",
iden_ref, bp::return_internal_reference<>());
147 bp::def(
"iden_shared",
iden_shared, bp::return_internal_reference<>());
const MyVirtualData & iden_ref(const MyVirtualData &d)
Take and return a const reference.
void throw_virtual_not_implemented_error()
virtual ~MyVirtualClass()
shared_ptr< MyVirtualData > default_createData() const
shared_ptr< MyVirtualData > callDoSomethingPtr(const MyVirtualClass &obj)
shared_ptr< MyVirtualData > callDoSomethingRef(const MyVirtualClass &obj)
const MyVirtualData & iden_shared(const shared_ptr< MyVirtualData > &d)
Eigen::TensorRef< Tensor > ref(Eigen::TensorRef< Tensor > tensor)
virtual void doSomethingRef(MyVirtualData &data) const =0
shared_ptr< MyVirtualData > createData() const override
shared_ptr< MyVirtualData > copy_shared(const shared_ptr< MyVirtualData > &d)
Take and return a shared_ptr.
void doSomethingPtr(shared_ptr< MyVirtualData > const &data) const override
void doSomethingRef(MyVirtualData &data) const override
MyVirtualData(MyVirtualClass const &)
virtual shared_ptr< MyVirtualData > createData() const
virtual void doSomethingPtr(shared_ptr< MyVirtualData > const &data) const =0
BOOST_PYTHON_MODULE(bind_virtual_factory)