Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/boundary-dressup-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert committed Nov 13, 2019
2 parents e32f023 + d2032da commit a288533
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/Base/TypePy.xml
Expand Up @@ -39,6 +39,11 @@ namespace Base {
<UserDocu>Returns an invalid type id</UserDocu>
</Documentation>
</Methode>
<Methode Name="getAllDerivedFrom" Static="true">
<Documentation>
<UserDocu>Returns all descendants</UserDocu>
</Documentation>
</Methode>
<Methode Name="getParent" Const="true">
<Documentation>
<UserDocu>Returns the parent type id</UserDocu>
Expand All @@ -54,7 +59,7 @@ namespace Base {
<UserDocu>Returns true if given type is a father</UserDocu>
</Documentation>
</Methode>
<Methode Name="getAllDerivedFrom" Static="true">
<Methode Name="getAllDerived" Const="true">
<Documentation>
<UserDocu>Returns all descendants</UserDocu>
</Documentation>
Expand Down
80 changes: 64 additions & 16 deletions src/Base/TypePyImp.cpp
Expand Up @@ -41,7 +41,7 @@ PyObject* TypePy::staticCallback_fromName (PyObject * /*self*/, PyObject *args)
{
const char *name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
return nullptr;

Base::Type type = Base::Type::fromName(name);
return new TypePy(new Base::Type(type));
Expand All @@ -51,7 +51,7 @@ PyObject* TypePy::staticCallback_fromKey (PyObject * /*self*/, PyObject *args)
{
unsigned int index;
if (!PyArg_ParseTuple(args, "I", &index))
return NULL;
return nullptr;

Base::Type type = Base::Type::fromKey(index);
return new TypePy(new Base::Type(type));
Expand All @@ -60,7 +60,7 @@ PyObject* TypePy::staticCallback_fromKey (PyObject * /*self*/, PyObject *args)
PyObject* TypePy::staticCallback_getNumTypes (PyObject * /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
return nullptr;

int num = Base::Type::getNumTypes();
return PyLong_FromLong(num);
Expand All @@ -69,7 +69,7 @@ PyObject* TypePy::staticCallback_getNumTypes (PyObject * /*self*/, PyObject *arg
PyObject* TypePy::staticCallback_getBadType (PyObject * /*self*/, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
return nullptr;

Base::Type type = Base::Type::badType();
return new TypePy(new Base::Type(type));
Expand All @@ -78,7 +78,7 @@ PyObject* TypePy::staticCallback_getBadType (PyObject * /*self*/, PyObject *args
PyObject* TypePy::getParent(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
return nullptr;

Base::Type type = getBaseTypePtr()->getParent();
return new TypePy(new Base::Type(type));
Expand All @@ -87,35 +87,83 @@ PyObject* TypePy::getParent(PyObject *args)
PyObject* TypePy::isBad(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
return nullptr;

bool v = getBaseTypePtr()->isBad();
return PyBool_FromLong(v ? 1 : 0);
}

PyObject* TypePy::isDerivedFrom(PyObject *args)
{
const char *name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
Base::Type type;

do {
const char *name;
if (PyArg_ParseTuple(args, "s", &name)) {
type = Base::Type::fromName(name);
break;
}

PyErr_Clear();
PyObject* t;
if (PyArg_ParseTuple(args, "O!", &TypePy::Type, &t)) {
type = *static_cast<TypePy*>(t)->getBaseTypePtr();
break;
}

PyErr_SetString(PyExc_TypeError, "TypeId or str expected");
return nullptr;
}
while (false);

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

PyObject* TypePy::staticCallback_getAllDerivedFrom(PyObject* /*self*/, PyObject *args)
{
const char *name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
Base::Type type;

do {
const char *name;
if (PyArg_ParseTuple(args, "s", &name)) {
type = Base::Type::fromName(name);
break;
}

PyErr_Clear();
PyObject* t;
if (PyArg_ParseTuple(args, "O!", &TypePy::Type, &t)) {
type = *static_cast<TypePy*>(t)->getBaseTypePtr();
break;
}

PyErr_SetString(PyExc_TypeError, "TypeId or str expected");
return nullptr;
}
while (false);

Base::Type type = Base::Type::fromName(name);
std::vector<Base::Type> 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()));
for (std::vector<Base::Type>::iterator it = ary.begin(); it != ary.end(); ++it) {
res.append(Py::asObject(new TypePy(new Base::Type(*it))));
}
return Py::new_reference_to(res);
}

PyObject* TypePy::getAllDerived(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;

Base::Type type = Base::Type::fromName(getBaseTypePtr()->getName());
std::vector<Base::Type> 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::asObject(new TypePy(new Base::Type(*it))));
}
return Py::new_reference_to(res);
}

Expand Down

0 comments on commit a288533

Please sign in to comment.