diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-07-14 14:15:02 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-09-24 13:52:35 +0200 |
commit | bce1bfb3af99aeb24259df34d662e8fcf072d3fd (patch) | |
tree | ef36333a2b059f4278cc5aad4efa860f9e4cd30b /sources/shiboken6/ApiExtractor/abstractmetatype.cpp | |
parent | 79b32f4d4b5154ba8001bafc481fb6edacc10280 (diff) |
shiboken6: Add opaque containers for C++ sequence containers
Add a class that directly wraps a C++ sequence container,
allow for modifying them.
For all instantiated containers, generate a special (sequence) type
that wraps the C++ container directly. For example, it will be
accessible as a QList_int.
This is achieved via providing a template for a type private
that relies on a conversion traits template for conversion.
Only the conversion traits specialization code needs to be generated.
Use cases:
- Allowing for modifying Fields of such container types
(non-owning)
- Pass it into functions taking such containers instead of converting
back and forth from a PyList (constructed in Python, owning)
[ChangeLog][shiboken6] Support for opaque C++ sequence scontainers
has been added, allowing to pass a wrapped C++ container
directly instead of converting it back and forth from
Python sequences.
Task-number: PYSIDE-1605
Change-Id: I49d378eb1a0151730d817d5bdd4b71a7c3b5cdda
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetatype.cpp')
-rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetatype.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp index f099bba08..8e6238448 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp @@ -768,7 +768,8 @@ bool AbstractMetaType::shouldDereferenceArgument() const { return isWrapperPassedByReference() || valueTypeWithCopyConstructorOnlyPassed() - || isObjectTypeUsedAsValueType(); + || isObjectTypeUsedAsValueType() + || generateOpaqueContainer(); } bool AbstractMetaType::isCppIntegralPrimitive() const @@ -850,6 +851,36 @@ AbstractMetaType AbstractMetaType::fromAbstractMetaClass(const AbstractMetaClass return fromTypeEntry(metaClass->typeEntry()); } +bool AbstractMetaType::generateOpaqueContainer() const +{ + if (!isContainer()) + return false; + auto *containerTypeEntry = static_cast<const ContainerTypeEntry *>(typeEntry()); + auto kind = containerTypeEntry->containerKind(); + if (kind != ContainerTypeEntry::ListContainer) + return false; + const auto &instantation = d->m_instantiations.constFirst(); + if (instantation.referenceType() != NoReference) + return false; + const QString signature = instantation.cppSignature(); + + bool result = false; + auto *instTypEntry = instantation.typeEntry(); + switch (instTypEntry->type()) { + case TypeEntry::PrimitiveType: + case TypeEntry::FlagsType: + case TypeEntry::EnumType: + case TypeEntry::BasicValueType: + case TypeEntry::ObjectType: + case TypeEntry::CustomType: + result = containerTypeEntry->generateOpaqueContainer(signature); + break; + default: + break; + } + return result; +} + #ifndef QT_NO_DEBUG_STREAM void AbstractMetaType::formatDebug(QDebug &debug) const { |