summaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/typesystem_sample.xml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/samplebinding/typesystem_sample.xml')
-rw-r--r--tests/samplebinding/typesystem_sample.xml95
1 files changed, 87 insertions, 8 deletions
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index ec4ace7d..ba3a56eb 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -101,18 +101,93 @@
</primitive-type>
<container-type name="std::pair" type="pair">
- <conversion-rule file="pair_conversions.h"/>
<include file-name="utility" location="global"/>
+ <conversion-rule file="pair_conversions.h">
+ <native-to-target>
+ PyObject* %out = PyTuple_New(2);
+ PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first));
+ PyTuple_SET_ITEM(%out, 1, %CONVERTTOPYTHON[%INTYPE_1](%in.second));
+ return %out;
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PySequence">
+ %out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0));
+ %out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1));
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
</container-type>
+ <template name="cpplist_to_pylist_convertion">
+ PyObject* %out = PyList_New((int) %in.size());
+ %INTYPE::const_iterator it = %in.begin();
+ for (int idx = 0; it != %in.end(); ++it, ++idx) {
+ %INTYPE_0 cppItem(*it);
+ PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem));
+ }
+ return %out;
+ </template>
+ <template name="pyseq_to_cpplist_convertion">
+ for (int i = 0; i &lt; PySequence_Fast_GET_SIZE(%in); i++) {
+ PyObject* pyItem = PySequence_Fast_GET_ITEM(%in, i);
+ %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem);
+ %out.push_back(cppItem);
+ }
+ </template>
<container-type name="std::list" type="list">
- <conversion-rule file="list_conversions.h"/>
<include file-name="list" location="global"/>
+ <conversion-rule file="list_conversions.h">
+ <native-to-target>
+ <insert-template name="cpplist_to_pylist_convertion"/>
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PySequence">
+ <insert-template name="pyseq_to_cpplist_convertion"/>
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
+ </container-type>
+ <container-type name="List" type="list">
+ <include file-name="list" location="global"/>
+ <conversion-rule>
+ <native-to-target>
+ <insert-template name="cpplist_to_pylist_convertion"/>
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PySequence">
+ <insert-template name="pyseq_to_cpplist_convertion"/>
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
</container-type>
<container-type name="std::map" type="map">
- <conversion-rule file="map_conversions.h"/>
<include file-name="map" location="global"/>
+ <conversion-rule file="map_conversions.h">
+ <native-to-target>
+ PyObject* %out = PyDict_New();
+ %INTYPE::const_iterator it = %in.begin();
+ for (; it != %in.end(); ++it) {
+ %INTYPE_0 key = it->first;
+ %INTYPE_1 value = it->second;
+ PyDict_SetItem(%out,
+ %CONVERTTOPYTHON[%INTYPE_0](key),
+ %CONVERTTOPYTHON[%INTYPE_1](value));
+ }
+ return %out;
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PyDict">
+ PyObject* key;
+ PyObject* value;
+ Py_ssize_t pos = 0;
+ while (PyDict_Next(%in, &amp;pos, &amp;key, &amp;value)) {
+ %OUTTYPE_0 cppKey = %CONVERTTOCPP[%OUTTYPE_0](key);
+ %OUTTYPE_1 cppValue = %CONVERTTOCPP[%OUTTYPE_1](value);
+ %out.insert(%OUTTYPE::value_type(cppKey, cppValue));
+ }
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
</container-type>
- <container-type name="List" type="list" />
<add-function signature="cacheSize()" return-type="int">
<inject-code class="target">
@@ -181,6 +256,7 @@
<enum-type name="NiceEnum" />
</object-type>
</value-type>
+ <value-type name="SomeOtherInnerClass"/>
</value-type>
<modify-function signature="doSomethingWithArray(const unsigned char*, unsigned int, const char*)">
@@ -238,12 +314,14 @@
<namespace-type name="Photon">
<enum-type name="ClassType"/>
- <object-type name="TemplateBase" generate="no"/>
- <object-type name="ValueIdentity"/>
- <object-type name="ValueDuplicator"/>
+ <value-type name="TemplateBase" generate="no"/>
+ <value-type name="ValueIdentity"/>
+ <value-type name="ValueDuplicator"/>
</namespace-type>
- <value-type name="IntList" />
+ <value-type name="IntList">
+ <enum-type name="CtorEnum"/>
+ </value-type>
<object-type name="Abstract">
<enum-type name="Type"/>
@@ -1747,6 +1825,7 @@
</value-type>
<value-type name="StrList">
+ <enum-type name="CtorEnum"/>
<add-function signature="__len__" >
<inject-code class="target" position="end">
return %CPPSELF.size();