Cdb: Add python function returning all template arguments

Change-Id: Ib0f2eefc63427c8b89288ec72c35c0596cd6c1d0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2016-10-19 13:30:52 +02:00
parent bc41012c7d
commit 83da96189e

View File

@@ -272,6 +272,24 @@ PyObject *type_TemplateArgument(Type *self, PyObject *args)
return lookupType(innerType); return lookupType(innerType);
} }
PyObject *type_TemplateArguments(Type *self)
{
std::vector<std::string> innerTypes = innerTypesOf(getTypeName(self));
auto templateArguments = PyList_New(0);
for (const std::string &innerType : innerTypes) {
PyObject* childValue;
try {
int integer = std::stoi(innerType);
childValue = Py_BuildValue("i", integer);
}
catch (std::invalid_argument) {
childValue = lookupType(innerType);
}
PyList_Append(templateArguments, childValue);
}
return templateArguments;
}
PyObject *type_New(PyTypeObject *type, PyObject *, PyObject *) PyObject *type_New(PyTypeObject *type, PyObject *, PyObject *)
{ {
Type *self = reinterpret_cast<Type *>(type->tp_alloc(type, 0)); Type *self = reinterpret_cast<Type *>(type->tp_alloc(type, 0));
@@ -315,6 +333,8 @@ static PyMethodDef typeMethods[] = {
{"templateArgument", PyCFunction(type_TemplateArgument), METH_VARARGS, {"templateArgument", PyCFunction(type_TemplateArgument), METH_VARARGS,
"Returns template argument at position"}, "Returns template argument at position"},
{"templateArguments", PyCFunction(type_TemplateArguments), METH_NOARGS,
"Returns all template arguments."},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };