Base: [skip ci] expose Type::createInstance and Type::createInstanceByName to Python

This commit is contained in:
wmayer
2020-10-29 17:18:10 +01:00
parent 4aca75d396
commit e22286f5b4
2 changed files with 41 additions and 0 deletions

View File

@@ -167,6 +167,37 @@ PyObject* TypePy::getAllDerived(PyObject *args)
return Py::new_reference_to(res);
}
PyObject* TypePy::createInstance (PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
Base::BaseClass* base = static_cast<Base::BaseClass*>(getBaseTypePtr()->createInstance());
if (!base) {
Py_Return;
}
//TODO: At the moment "base" will never be destroyed and causes a memory leak
return base->getPyObject();
}
PyObject* TypePy::createInstanceByName (PyObject *args)
{
const char* type;
PyObject* load = Py_False;
if (!PyArg_ParseTuple(args, "s|O!", &type, &PyBool_Type, &load))
return nullptr;
Base::BaseClass* base = static_cast<Base::BaseClass*>
(Base::Type::createInstanceByName(type, PyObject_IsTrue(load) ? true : false));
if (!base) {
Py_Return;
}
//TODO: At the moment "base" will never be destroyed and causes a memory leak
return base->getPyObject();
}
Py::String TypePy::getName(void) const
{
return Py::String(std::string(getBaseTypePtr()->getName()));