Navigation Menu

Skip to content

Commit

Permalink
declare getAllDerivedFrom as static method
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 12, 2019
1 parent e1f85cd commit d61bf15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Base/TypePy.xml
Expand Up @@ -54,7 +54,7 @@ namespace Base {
<UserDocu>Returns true if given type is a father</UserDocu>
</Documentation>
</Methode>
<Methode Name="getAllDerivedFrom" Const="true">
<Methode Name="getAllDerivedFrom" Static="true">
<Documentation>
<UserDocu>Returns all descendants</UserDocu>
</Documentation>
Expand Down
18 changes: 10 additions & 8 deletions src/Base/TypePyImp.cpp
Expand Up @@ -95,22 +95,24 @@ PyObject* TypePy::isBad(PyObject *args)

PyObject* TypePy::isDerivedFrom(PyObject *args)
{
char *name;
if (!PyArg_ParseTuple(args, "s", &name)) // convert args: Python->C
return NULL; // NULL triggers exception
const char *name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;

Base::Type type = Base::Type::fromName(name);
bool v = (type != Base::Type::badType() && getBaseTypePtr()->isDerivedFrom(type));
return PyBool_FromLong(v ? 1 : 0);
}

PyObject* TypePy::getAllDerivedFrom(PyObject *args)
PyObject* TypePy::staticCallback_getAllDerivedFrom(PyObject* /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception

const char *name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;

Base::Type type = Base::Type::fromName(name);
std::vector<Base::Type> ary;
Base::Type::getAllDerivedFrom(*getBaseTypePtr(), ary);
Base::Type::getAllDerivedFrom(type, ary);
Py::List res;
for (std::vector<Base::Type>::iterator it = ary.begin(); it != ary.end(); ++it)
res.append(Py::String(it->getName()));
Expand Down

0 comments on commit d61bf15

Please sign in to comment.