diff options
author | David Schulz <david.schulz@qt.io> | 2016-10-19 13:30:52 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2016-10-20 11:43:16 +0000 |
commit | 83da96189ee7226fde5410af5cb03e2e58912a76 (patch) | |
tree | 9f14737b7e5e2c7c15b2e9a61628ca78beb689e6 | |
parent | bc41012c7d4e552e37ae11785543b878042daab0 (diff) | |
download | qt-creator-83da96189ee7226fde5410af5cb03e2e58912a76.tar.gz |
Cdb: Add python function returning all template arguments
Change-Id: Ib0f2eefc63427c8b89288ec72c35c0596cd6c1d0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/libs/qtcreatorcdbext/pytype.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libs/qtcreatorcdbext/pytype.cpp b/src/libs/qtcreatorcdbext/pytype.cpp index 9b14b6fbd8..7e1010a9d9 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<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 *) { Type *self = reinterpret_cast<Type *>(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 */ }; |