diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-20 13:51:08 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-21 13:03:11 +0200 |
commit | e70fbd8d91af1fa9813bc1df7dfad44b1665957e (patch) | |
tree | 459fdff3bb60d2405bd5d0a02292a44b358689d7 /sources/shiboken6/generator/shiboken/cppgenerator.cpp | |
parent | c0beb9f29f36ea3bc8be26675a05253cc5584fe4 (diff) |
shiboken6: Implement opaque containers for getters returning a const reference
Add a bool m_const member to the container helper template that
indicates a const container. Error out of the modification functions
if that is set. Create an additional creation function for the const
case. A const opaque containers is then of same Python type as the
non-const version, requiring no further type checks.
Pick-to: 6.2
Task-number: PYSIDE-1605
Change-Id: I45faeb0d68e6144a9dfbe25497694b8acdd98c09
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken/cppgenerator.cpp')
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index a6abeb077..06299a2ab 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -197,8 +197,11 @@ static QString opaqueContainerCreationFunc(const AbstractMetaType &type) static_cast<const ContainerTypeEntry *>(type.typeEntry()); const auto *instantiationTypeEntry = type.instantiations().constFirst().typeEntry(); - return u"create"_qs - + containerTypeEntry->opaqueContainerName(instantiationTypeEntry->name()); + QString result = u"create"_qs; + if (type.isConstant()) + result += u"Const"_qs; + result += containerTypeEntry->opaqueContainerName(instantiationTypeEntry->name()); + return result; } // Write declaration of the function to create PyObject wrapping a container @@ -206,7 +209,7 @@ static void writeOpaqueContainerCreationFuncDecl(TextStream &s, const QString &n AbstractMetaType type) { type.setReferenceType(NoReference); - type.setConstant(false); + // Maintain const s << "PyObject *" << name << '(' << type.cppSignature() << "*);\n"; } |