Base: [skip ci] expose Type::createInstance and Type::createInstanceByName to Python
This commit is contained in:
@@ -64,6 +64,16 @@ namespace Base {
|
||||
<UserDocu>Returns all descendants</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="createInstance">
|
||||
<Documentation>
|
||||
<UserDocu>Creates an instance of this type</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="createInstanceByName" Static="true">
|
||||
<Documentation>
|
||||
<UserDocu>Creates an instance of the named type</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="Name" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>The name of the type id</UserDocu>
|
||||
|
||||
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user