diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-12-29 17:02:26 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:18:36 -0300 |
commit | 7ca708a09839e4a9a9bb2f1fb600bf683d42c1e9 (patch) | |
tree | 44ced148ddfaf0ab7a037961d64cb36101e1ff5d /tests/samplebinding/typesystem_sample.xml | |
parent | 3991d3b23bcce3f3ac5f468d35a1510a50ec8cba (diff) |
Updated documentation for type converters.
Expanded the Complex type conversion unit test.
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Paulo Alcantara <pcacjr@gmail.com>
Diffstat (limited to 'tests/samplebinding/typesystem_sample.xml')
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 6ab2d154e..0389d8520 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -37,6 +37,19 @@ </conversion-rule> </primitive-type> + <inject-code class="native" position="beginning"> + static bool Check2TupleOfNumbers(PyObject* pyIn) { + if (!PySequence_Check(pyIn) || !(PySequence_Size(pyIn) == 2)) + return false; + Shiboken::AutoDecRef pyReal(PySequence_GetItem(pyIn, 0)); + if (!SbkNumber_Check(pyReal)) + return false; + Shiboken::AutoDecRef pyImag(PySequence_GetItem(pyIn, 1)); + if (!SbkNumber_Check(pyImag)) + return false; + return true; + } + </inject-code> <primitive-type name="Complex" target-lang-api-name="PyComplex"> <include file-name="complex.h" location="global"/> <conversion-rule> @@ -51,6 +64,13 @@ double imag = PyComplex_ImagAsDouble(%in); %out = %OUTTYPE(real, imag); </add-conversion> + <add-conversion type="PySequence" check="Check2TupleOfNumbers(%in)"> + Shiboken::AutoDecRef pyReal(PySequence_GetItem(%in, 0)); + Shiboken::AutoDecRef pyImag(PySequence_GetItem(%in, 1)); + double real = %CONVERTTOCPP[double](pyReal); + double imag = %CONVERTTOCPP[double](pyImag); + %out = %OUTTYPE(real, imag); + </add-conversion> </target-to-native> </conversion-rule> </primitive-type> |