From 83da96189ee7226fde5410af5cb03e2e58912a76 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 19 Oct 2016 13:30:52 +0200 Subject: [PATCH] Cdb: Add python function returning all template arguments Change-Id: Ib0f2eefc63427c8b89288ec72c35c0596cd6c1d0 Reviewed-by: Christian Stenger --- src/libs/qtcreatorcdbext/pytype.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libs/qtcreatorcdbext/pytype.cpp b/src/libs/qtcreatorcdbext/pytype.cpp index 9b14b6fbd8e..7e1010a9d93 100644 --- a/src/libs/qtcreatorcdbext/pytype.cpp +++ b/src/libs/qtcreatorcdbext/pytype.cpp @@ -272,6 +272,24 @@ PyObject *type_TemplateArgument(Type *self, PyObject *args) return lookupType(innerType); } +PyObject *type_TemplateArguments(Type *self) +{ + std::vector 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 *) { Type *self = reinterpret_cast(type->tp_alloc(type, 0)); @@ -315,6 +333,8 @@ static PyMethodDef typeMethods[] = { {"templateArgument", PyCFunction(type_TemplateArgument), METH_VARARGS, "Returns template argument at position"}, + {"templateArguments", PyCFunction(type_TemplateArguments), METH_NOARGS, + "Returns all template arguments."}, {NULL} /* Sentinel */ };