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/tests/minimalbinding | |
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/tests/minimalbinding')
-rw-r--r-- | sources/shiboken6/tests/minimalbinding/listuser_test.py | 26 | ||||
-rw-r--r-- | sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml | 7 |
2 files changed, 30 insertions, 3 deletions
diff --git a/sources/shiboken6/tests/minimalbinding/listuser_test.py b/sources/shiboken6/tests/minimalbinding/listuser_test.py index b5048aa44..1a11ccfbf 100644 --- a/sources/shiboken6/tests/minimalbinding/listuser_test.py +++ b/sources/shiboken6/tests/minimalbinding/listuser_test.py @@ -39,7 +39,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from minimal import ListUser, Val, Obj +from minimal import ListUser, Val, Obj, StdIntList class ExtListUser(ListUser): @@ -321,6 +321,30 @@ class ListOfIntListConversionTest(unittest.TestCase): self.assertEqual(lu.sumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]) * 2) self.assertEqual(lu.callSumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]) * 2) + def testOpaqueContainer(self): + lu = ListUser() + + # Set via Python + python_list = [1,2] + lu.setStdIntList(python_list) + self.assertEqual(len(lu.m_stdIntList), 2) + self.assertEqual(lu.m_stdIntList[0], 1) + self.assertEqual(lu.m_stdIntList[1], 2) + + # Set via C++ + cpp_list = StdIntList() + cpp_list.append(3) + cpp_list.append(4) + lu.setStdIntList(cpp_list) + self.assertEqual(len(lu.m_stdIntList), 2) + self.assertEqual(lu.m_stdIntList[0], 3) + self.assertEqual(lu.m_stdIntList[1], 4) + + # Access field directly via reference + lu.m_stdIntList.append(5) + self.assertEqual(len(lu.m_stdIntList), 3) + self.assertEqual(lu.m_stdIntList[2], 5) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml index 625615fa1..2b9cbc89f 100644 --- a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml +++ b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml @@ -17,7 +17,8 @@ </conversion-rule> </primitive-type> - <container-type name="std::list" type="list"> + <container-type name="std::list" type="list" + opaque-containers="int:StdIntList"> <include file-name="list" location="global"/> <conversion-rule> <native-to-target> @@ -47,7 +48,9 @@ <value-type name="Val"> <enum-type name="ValEnum"/> </value-type> - <value-type name="ListUser"/> + <value-type name="ListUser"> + <modify-field name="m_stdIntList" opaque-container="yes"/> + </value-type> <value-type name="MinBoolUser"/> <container-type name="std::vector" type="vector"> |